Archive for May, 2008

Code Monkey (Jonathan Coulton cover)

Wednesday, May 21st, 2008

This is a bare-bones acoustic cover of Jonathan Coulton’s song, “Code Monkey.” The cover’s nothing special, just something I did in between packing stuff. I recorded it live with my Mac’s mic, with very little processing: a little noise reduction here, a little bass reduction there. The hardest part was keeping quiet, since it is technically quiet hours in my dorm. Enjoy!

Download MP3 here.

Behold the Glory that is Object-Oriented programming!

Wednesday, May 7th, 2008

So, for my final project in CS 365 (Databases), I’m designing a Wikipedia-style encyclopedia. Not very original, but it gets the job done. And it’s kind of fun to code.

Until today, however. Since this is finals week, I’ve been concentrating on other things until today. The project is due tomorrow. I already had a lot of it done (strange for me, I know, but I’m trying to get out of here), and had seen a lot of e-mails over the weekend about how the DB server we were using was going down and back up as it was fixed. I didn’t worry too much, because as of last night it was supposed to be up and strong.

Imagine my horror, then, as I logged on to the site to see what needed to be done, and got all sorts of errors, most of them involving the MySQL server’s refusal to connect. Some pages, mostly display pages, were still working. So I could browse to articles, list them, and so on, but I couldn’t create or edit them. I was understandably upset, because I also couldn’t implement the access controls or categorization features that my proposal said I would.

After some investigation, I determined that the problem arose when I requested more than one SQL connection at a time. In theory, I only needed one at a time, but my architecture was designed around a Database class, which you could have more than one of. One class for one connection. I also had some static classes for doing things like manipulating articles, categorizing them, linkifying them, and so on. All the edit pages would usually verify that the article in question exists, then call these static classes to do what they needed to do. So the calling page was creating a DB connection, then the static classes would, in order to do what they had to.

My options were looking pretty grim. Do I switch DB servers, and troubleshoot that nightmare? Do I change my whole engineering scheme with T-minus 20 hours and counting?

After some general freaking out, I realized that my pages revolved around a static call in the Database class called getConnection(), which returns a connection to the default database. The wheels in my head started turning, and I realized that since every one of my requests for a database connection go through this method, I could somehow use it to save the day.

The trick was to create a static class member called $working, which held the connection to one, and only one, database. So I changed my code. From this:

public static function getConnection ()  
{
   return new Database();  
}

To this:

public static function getConnection ()  
{
   if (self::$working == NULL)
    self::$working = new Database();
   return self::$working;  
}

Since I essentially had a factory method to get the database connections to begin with, I merely needed to change this method so that it created the first connection, but didn’t do so on subsequent connection requests. Instead, it returns the already-existing connection. Since all my pages use this method, it means that they all use one and only one server connection. I changed the code, uploaded, and… voila! It worked perfectly.

Imagine the trouble I’d be in if I hadn’t done this to begin with. This is why I love OO programming. Because if you start with well-engineered code, then a major change like this can fix everything, and break nothing. Long live Object-Oriented Programming!

Update:I would be remiss not to mention that this is the Singleton design pattern, which my buddy and classmate Dylan pointed out I had omitted from the original post.

Smash Bros Brawl Has a Broken AI

Tuesday, May 6th, 2008

Try this experiment:

  1. Start a game of Smash Bros Brawl on Free For All. Use stock mode.
  2. Just play with one player, set the rest to CPUs on level 9.
  3. Start the game, and time how long it takes for the game to end.
  4. Now, replace yourself with another computer on level 9, and time that match.

Which game took longer? Nine times out of ten, it will probably be the all-computer match. Does the first game end quickly because the AI on Smash Bros Brawl is just that good, that three of them can usually beat a human player? Does the second game take longer because the computers are excelent players?

No, it’s because the AI is biased against humans. In FFA matches, the computers actually target the human players, leaving each other alone relatively. If you need proof of this, play FFA with two humans and two CPUs. If you and your friend are halfway decent and unbiased, you will probably be the last two standing. You can also try a 1v1 in FFA, you against a computer. It’s a lot easier. Even 1v1v1 is better. But when you get three computer players all ganging up on the one human, the game becomes a lot harder.

Need some examples of this bias? Read on. From what I’ve seen, Free-for-All with 3 CPUs is really a team match, human vs. 3 computers. The game has been kind enough to activate team damage, so every once in a while they’ll hurt each other. Here are some examples:

Final Smashes

This is where it gets ridiculous. They computer will, without fail, target the human players. If you happen to die right before a CPU gets the Smash Ball, that player will wait until you have come back to use it. If you wait up on your platform while you’re invincible, so will the CPU. He will not even consider using his Final Smash on his teammates. The other CPUs will not even consider trying to take it from him. The most ridiculous cases are Lucas or Ness. It looks like the programmers gave each character a final smash AI, so they know how to use it. A lot of characters (Captain Falcon, Meta Knight) need to be close to use their smash. Ness and Lucas don’t, however. Their final smash is screen-wide. But they usually try to get near the human player before they deploy it.

Even worse are the Final Smashes that involve controlling direction. For example, the Star Fox characters use their big, stupid tanks. Sonic flies around the stage, as does Pikachu. It’s especially fun to get into a corner where Fox’s tank can’t reach, or to lead him somewhere he’ll get stuck. If you stand still, he’ll try to get at you but not go anywhere, even if the other CPUs are easily accessible. Similarly, Super Sonic or Pikachu will try and hammer you. They might hit another CPU in passing, but they’re not fooling anybody.

Dragoon

This is the most infuriating. True, you can dodge it, but you need split-second timing. If one CPU gets this, he will target you mercilessly. Even if the other two CPUs are standing in a tempting cluster, the CPU will prefer hitting the human player for one kill over getting the other two computers for two. Like with the Final Smash, if you die just before they get it and wait to come out, the CPU will wait until your invincibility wears off before attacking you.

The Chase

Try playing a large stage, like the Zelda Castle or the custom ‘Maze’ stage. Right at the start of the match, run from the CPUs (all three will immediately begin chasing you when the match begins). You can lead the other three CPUs on a chase, round and round the stage. They will occasionally take swipes at each other, but they’re only love taps.

No unbiased person can argue that the CPU itself is unbiased. They hate human players. They even taunt the humans after they’ve killed them — but not other computers. Way to rub it in, guys.

So what can you do? Well, you can always play with at least one other human. People may develop grudges from time to time, but they usually mix it up after they’re told to piss off and stop targeting one person. You can’t do that for the AI. Unfortunately, if you just want a quick game by yourself, you’re SOL.

I’ve tried playing 1v1v1 in team mode, with me on one team and the other two players on different team. It seems to end up the same way.

For now, I guess we’ll just have to treat FFA like a team match, humans vs. robots. The Smash Bros Brawl AI is not the hardest alone, but with three ganging up on you, the sheer force of the numbers is enough to trip you up. The only upside to this situation is that if you keep practicing, you’ll probably get really good against other humans.