Archive for the ‘Random’ Category.

Memcached and You

Tweemotional.com was not doing so well. It had too much information in the database which was also missing an index on the date causing the SELECT to do a file sort on millions of rows.

So I took the opportunity to flush the database since raw tweet data that is more than 24 hours old is ignored anyway and added in the index.

However, I also plugged in Memcached support. With Memcached you can do the query on the database once, take the result and stuff it in memcached. The next time you need the data you simply query memcached which returns the result instantly.

So now when the backend scripts for Tweemotional.com are gather information from Twitter they also update the Memcached versions of what the site needs to display the data. So now the site itself runs very quickly since it’s not hitting the database nearly as much.

If you want to make use of Memcached for your site you’ll need pretty much any computer you can get. I have it running on a PIII 533Mhz system with 512MB of memory. Obviously if you have a site that could make use of more space to store cached objects then you’ll need a system with more RAM or diskspace. For best performance you want enough memory that memcached doesn’t have to pull information from the disk before sending it over.

There are Windows binaries available but they are for an older version. If you want to run the latest version you’ll probably want to just use some version of Linux. I prefer Ubuntu. The 8.04 version installed and ran just fine on my system. I turned off the graphical flair for the GUI and it runs rather smoothly.

There are existing libraries for Memcached for PHP and C# as well as other languages. Enyim.Caching is what I use with C#. I then wrote a simple static class wrapper around that so I can just use memcached.get, memcached.set and memcached.remove and not have to deal with any initialization.

Another reason for using a wrapper is that memcached doesn’t like keys with certain characters. To avoid this problem the wrapper automatically MD5’s the key I pass in before it passed it along to memcached. In my code I can then use whatever key I want.

The other thing you have to remember with C# is that you must explicity make your classes Serializable or they cannot be cached through memcached. I don’t believe PHP has this issue. I’m not sure if there’s anything in PHP that isn’t serializable by default.

If you’re running any sort of website that is doing some heavy lifting with queries it would be to your benefit to take a look at memcached to see what it can do for you.

Winning at Superheroes Alliance on Facebook

There are two key things you need to do in Superheroes Alliance on Facebook: win fights and complete missions. Completing missions in a reasonable amount of time requires having plenty of energy. Winning battles requires attack strength with a supporting alliance and quality items for each person in your team including yourself.

Defense is used mainly when defending yourself against other people’s attacks. In the event you lose a battle you lose HP and money. If you don’t keep cash on hand there’s no financial incentive for others to attack you and so they don’t. They hit you once and if they win they see they get nothing for it so they move on to the next target. The first step to avoid being attacked is to keep your money in the vault. It costs you 10% but that’s better than losing it all from being attacked constantly. Don’t worry about defense points and instead focus on increasing attack points.

HP are your “hit points.” You lose them every time you get hit. The only thing you need to worry about is losing more than you have in a single hit. Once you go below 25 you can no longer be attacked. This is why, at least for awhile, you don’t need to waste points increasing your HP.

You need one stamina point for each attack. You don’t really need to increase this since you can always go back and attack someone again after recovering your stamina and HP.

Completing missions gets you money, better items and experience which moves you through the levels. You also get extra points for the lab. Use them to get hired heros. The more people you have on your team the better chance you have of winning battles.

The second and most important thing to do to avoid being attacked is to win more battles than you lose. Generally people are going to attack the weaker players so if you win more than you lose other players will for the most part avoid you.

So above all else, increase your attack points the most, then energy. As you progress through the levels you can start to increase other stats as well. But you need to win battles and complete missions before you can really start rounding out your character.

Superheroes Alliance on Facebook

I used to play Heroes vs Villians on Facebook until I discovered Superheroes Alliance. Superheroes Alliance is a very well polished game that plays much like HvV but looks significantly better and has better features. For example you can see how many wins and loses another player has which makes it easier to figure out who you’d like to attack. You can also battle rivals which means you can keep track of how many wins and loses you have against specific players and keep battling them if you beat them most of the time.

I’ve been looking for tips and tricks for this game and havn’t found any so I’m going to offer a few.

Prior to the complete reworking of missions they were pretty much useless. Now you need them to get better sidekicks. However, your focus, especially early on, should be only on attack and defense. The real money and experience comes not from missions, but from attacking and winning battles against other players.

Money is important in this game. If you want better sidekicks you needs income to support them. If an abilitity is available to get more money from winning battles, take advantage of it. Use most of your skill points to magnify attack and defense where possible but don’t neglect the money train.

Only buy land and property in blocks of 10. The price goes up significantly with each purchase so the more you buy all at once the more money you save. To save the most money buy 10 blocks of land when you can. Buy no more than 10. You will start earning money on the land. Then buy 10 blocks of property to go on the land when you can. The price of the land will drop back down to the lowest price and you can repeat the process.

Keep track of the amount of money you earn vs the cost of the land + property. You want to maximize your return so buy the land+property combo that results in the greatest earnings for the cost no matter how little the earnings are. It all adds up quickly when you consider the amount you will earn over several days.

By the time you own 30 of a property it takes about a week to recoup the cost. When you’re at that point it’s time to start saving up for the big ticket items.

Again high defense and attack stats and top of the line sidekicks, you can quickly bring in millions by battling.

Use the vault often. Yes it costs you 10% but that’s significantly less than it costs when someone beats you in a battle. I typically vault the money until I’m within 5-10 million of my goal. Once I have the last 5-10mil on hand I withdraw just enough to cover my purchase. Make sure you’ve regenerated all your health before sinking all the money you have into your purchase.

Once you have millions of dollars coming in every hour it’s time to stop focusing so much on making money and focus more on completing missions. That means using some of your skill points to up your maximum energy.

As you progress in the game the goal is to depend less on your character and more on your alliance and sidekicks. You don’t need maxed out attack and defense because your multipliers, sidekicks and alliance take care of that.

The Emotional State of the Internet

The Emotional State of the Internet is a website which analyzes Twitter messages and calculates how the internet is feeling. It’s updated every 10 minutes. You can also see a historical chart of the current top emotion.

It’s interesting to see the difference between what emotion people twitter about the most in various languages. French speakers talk about how lonely they are. Germans by a wide margin talk about “angst” the most. While Google Translate tells me it means “frightened” in English, according to Wikipedia it more accurately translates to “anxiety.” This is why I keep the original word listed and put the English translation in parantheses.

Italians tend to talk most about being “triste” which means sad while Spanish speakers talk by a slightly wider margin about being happy.

Maybe Spanish speakers are happier than everyone else or maybe they use Twitter mostly to express happiness and tend to keep other emotions to themselves.

If you want to what people are getting emotional about you can click on “keywords” at the top of the page. That will list all the current keywords for all the various emotions the site is tracking.

A-Star Path Finding

A-Star (A*) Implementation in C# is an excellent implementation of A* in C#. It plugged neatly into Bunnies 3.0 which will soon have a sequal “Zombies.” The AI in Bunnies consists of stupid bunnies that just bounce around and multiply and slightly more intelligent enemies that will come at you and shoot at you if they see you. In “Zombies” you can run but you can’t hide. The game will be slow moving but difficult to kill hordes of enemies with limited ammo and various weapons. The A* algorithm is being used by the zombies to always keep them moving towards you no matter where you go.

This isn’t my first use of the A* algorithm and the flaws with it are still there. My first use of A* was for a simulator that had tanks and flying vehicals moving around complex 3D terrain that was created using DEM data (geological survey data of real life locations). One of the test paths took a helicopter over Mount Saint Helens. The helicopter would fly up the side of the mountain at the maximum pitch, fly down into the mountain, fly up out of the mountain and then fly down the side of the mountain to the destination.

The reason it did this is because A* always wants to be close to the final destination which was at the base of the other side of the mountain. So if it got a chance to lower the altitude to be close to the base it did. But that’s obviously not the optimum path. The fix for flying vehicals is to find the farthest point in the list of destinations which can be seen with a simple line of sight check. So from the base of the mountain the helicopter can see the top of the mountain so it heads straight there. From there it can see the other side of the rim so it flies straight there. And from there it can see it’s destination so it flies straight there. A path that was dozens of points is reduced to less than 10.

The technique is basically just doing intelligent post processing on the A* path to cut out unnecessary steps. Land vehicals had limits on the angle of the terrain they were going over. Sometimes A* would come up with tangled paths that didn’t go anywhere. So to fix that I found the farthest point along the A* path that the vehical could see and travel to without violating the steepness rule. That easily cut out knots that A* had created and simplified paths significantly.

Because the Bunnies Engine deals with flat terrain the line of sight algorithm can be used on the zombies to simplify their movement. Once I start putting together an actual tutorial on A* I’ll give visual examples of how post processing helps clean up A*.

Real Time Software Rendering is Moving

The original software rendering location will remain up for now while I slowly transition each of the lessons to the new Real Time Software Rendering Blog.

I found that it was quite the pain to update the old site since it was all static HTML and any syntax highlighted code was highlighted by hand. WordPress has a handy dandy plugin that automatically does the syntax highlighting. So this move will hopefully motivate me to continue adding new lessons on more topics.

There is certainly no shortage of lesson ideas that I’d like to cover.

Elmo and the Wii Part 2

The next game I decided to go with from the original Elmo game is the Feed Dorothy game. The object of this game is to move Dorothy so she catches the food. In my version you feed her cookies. In the original version the object is to feed Dorothy fish food. Bleck.

From a technical standpoint this demonstrates some additional game programming concepts. The cookie comes from the fish food container. The fish food container moves around and shakes. Dorothy is actually animated to look like her tail is waving. A 2D image of a goldfish was progressively modified with the “bulge” filter in Paint.Net (a free and excellent image editing tool for Windows). The fish object then progressively rotates through the frames of animation. “States” are used extensively to keep everything in sync. Also, both the fish food and Dorothy face the direction they are moving.

We’re no longer simply moving around static images like the Soccer Game.

The next game to be implemented is the Alphabet Game where Elmo must dodge obstacles and collect one letter at a time. I found a couple examples of Elmo saying the alphabet on YouTube. One is a rap song. The other is a skit with Grover where Elmo says every letter except one. I’ll see how I can best use those in the Alphabet Game.

Looney Tunes ACME Arsenal

One of questions many gamers have is “why do you even have lives?” It made sense back in the arcade days because lives cost real money. There was a financial incentive to make the game difficult so you’d die often and have to pop in more quarters. Many modern console games just annoy you if you run out of lives. For example making you go through the whole process of loading up your saved game again.

ACME Arsenal doesn’t have “lives.” You can still die but there are numerous checkpoints throughout the levels so that if you die you don’t lose much time and there’s no real punishment. That I like. Although it can be annoying in some parts where it’s possible to hit a checkpoint and then fall making you choose between killing yourself or working your way back up to the checkpoint. In some cases it’s faster to just kill yourself and get started back at the checkpoint.

The biggest annoyance is found at the tutorial level when you learn how to do double and triple jumps. The double jump is easy. The triple jump requires you figure out what the heck the manual is talking about. You press A twice and then twist the nunchuck a quarter turn left or right. What they don’t make clear is how the nunchuck must be held when doing the twist. You may assume from the illustration and the intended action that you rotate the controller while holding it vertically. That is not the case. You have to hold the controller level and twist your wrist to the side.

One complaint reviewers had was inconsistant behavior when trying to get the character to perform various actions. I’m guessing that was caused by not holding the controller properly. In many games an animation is used to tell you how exactly to move the controller. ACME Arsenal doesn’t do much to help you out.

Until you figure out how to hold the nunchuck and rotate it to perform the triple jump consistantly you’re not going to get very far in the game.

Once you’ve figured out how to work the controls the game is actually pretty fun. One of “cheats” that you may discover on your own quickly is that weapons that are provided by the game to perform a certain task reappear within seconds after picking it up. So you can pick up a gun and stay in the same spot and your ammo count will continue to go up rather quickly. This doesn’t apply to weapons dropped by enemies. In some levels you can find a weapon, wait for a minute or two in the same spot and have hundreds of rounds of ammo and go on a rampage. If you die you lose the weapon and all the ammo and you may not be able to go back and get it again after you make it past some checkpoints.

I picked the game up for about $15 and I’d say it’s worth the money. It’s frustrating to begin with but once you get the hang of it it becomes more entertaining.

Ninja Cat

Bunnies Web Site Update

The Bunnies site has been updated. One of the features of the game that the site didn’t support was bump mapped and depth mapped walls. There is now a tool available that will allow you to use any tile piece as a bump and/or depth map for any other tile piece.

The client has supported this feature for awhile. I had previously just manually set up a couple test tiles directly in the database.

It would probably be a good idea to put together some sort of manual for this product now. The Bunnies web-site is now fully capable of editing maps for the Bunnies game. The rest of the game development process is going to revolve around making Bunnies fully internet enabled. Currently the server serves only to access map information and download resources. What I’m looking to do next is to allow multiple players to interact when they’re in the same map. The first part of that is implementing a chat interface.

ss_blog_claim=70b9168863fc97c91e6d88b40542a327 ss_blog_claim=70b9168863fc97c91e6d88b40542a327