Thursday, October 02, 2008

Gay Marriage

According to both Biden and Palin in the VP debates, neither McCain nor Obama support allowing homosexual couples the right to marry. Someday, one or both candidates (or more candidates, God forbid there be third parties) will support this idea, which isn't quaint, isn't harmful to anyone, and essentially verifies our dedication to universal human rights, regardless of race, religion, or sexual preference. Hopefully, that time will come within our lifetime... but I'm not hedging my bets. Which sadly says a lot about the hatred that still bubbles below the surface of our society.

Wednesday, May 21, 2008

Code Monkey (Jonathan Coulton cover)

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.

Wednesday, May 07, 2008

Behold the Glory that is Object-Oriented programming!

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!

Labels: , , , ,

Tuesday, May 06, 2008

Smash Bros Brawl Has a Broken AI

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.

Labels: , , ,

Saturday, April 05, 2008

I shook hands with the next President of the United States

Went to the Missoula Obama rally at the University today. Lots of people getting signatures in the line, which stretched at least as far back as the Music Building, and probably much farther than that.

What can I say? The rally was bitchin'. There was a bit too much buildup, but it was worth it. Obama is just as eloquent a speaker as he's made out to be. He couldn't have picked a better town, since we tend to lean so far to the left here. He managed to tailor his speech to Montana without it feeling forced. Probably the biggest reaction he got was when he mentioned that no matter what, George W. Bush would not be on the ballot here. We Missoulians really, really don't like the guy.

Now, I'd prefer someone like Gravel as president, but he obviously won't be (he's kind of behind in the delegate count). I consider myself a libertarian, but I lean to the left, so that's where I tend to vote. And I'd rather not see McCain in office, because I've become rather fond of my civil liberties (those I have left, that is), and it's pretty clear he's just a Business as Usual type of guy.

As far as the Democrats go, Hillary's just dragging her heels along the slow path to irrelevance. Every day she finds a new way to prove that she'll do or say anything to become president. When you get down to it, it all comes down to attitude. They have fairly similar politics. Obama's is one of support, of doing something for the American people. Hillary's, on the other hand, is one of ambition, of doing anything to become the first woman president.

Plus, I really don't want to see our line of political succession go Bush, Clinton, Bush, Clinton. Then, Jeb Bush could run, and after him, Chelsea! Blahh :-P

Saturday, March 15, 2008

Democrats grow temporary spine...

Kudos to the House for blocking retroactive immunity to the telecoms for being complicit in the wiretapping of Americans. I considered this issue important enough to write Denny Rehberg about, and I got a response -- straight along party lines. I don't have the original letter I wrote, but I essentially took the standpoint that Montanans have been steamrolled by large corporations enough as it is, so as a Montanan Rehberg should realize that giving any sort of immunity to a corporation for any reason is a bad idea. His response?
The Protect America Act brings the outdated Foreign Intelligence Surveillance Act (FISA) of 1978 into line with current technological capabilities while adding appropriate liability protections for patriotic third parties who have helped defend our country.

The House of Representatives must pass this critical legislation without delay to ensure that Americans are protected from those who want to do us harm. I will do everything I can to ensure that these important protections are reinstated.

Sorry, Dave, the national agenda of the Republican Party trumps any obligation you may think I have to my constituents.

He lost in the end, as the house passed a bill refusing such retroactive immunity. This is actually a good, good thing. Bush and his cronies are trying to play the fear card. In the NY Times article, Bush is quoted as saying, "Companies that may have helped us save lives should be thanked for their patriotic service, not subjected to billion-dollar lawsuits that will make them less willing to help in the future. The House bill may be good for class action trial lawyers, but it would be terrible for the United States."

This is bad logic, and it's not very difficult to see why. I'm not surprised that you have no grasp of how our government works, Mr. President, but the scenario you described is not sufficient to change it. We have these things called checks and balances to prevent any one branch of the government (there are three, by the way) from overstepping its bounds. It's also why you can't declare war any time you want... oh, wait, scratch that one.

Anyway, the decision to take away Americans' right to file suit against the telecoms for breaching their civil liberties is not Congress's to make. All companies should be subject to "billion-dollar lawsuits" all the time because, let's be frank, corporations don't really care about the people they may hurt. The decision about whether the telecoms were complicit in violating Americans' rights belongs to the judicial branch alone, and should be decided on a case-by-case basis. The legislative branch should never, ever preempt the courts' ability to provide a path to justice for American citizens.

Taking away our ability to defend our rights and seek justice is a bad, bad idea. It essentially sends the telecoms the message that it's okay to allow this kind of paranoid eavesdropping, and to go ahead and continue doing so, without fear of reprisal. Retroactive immunity is never a good idea. When you grant it, you acknowledge that those given immunity did in fact do something wrong, while at the same time declaring that nothing should be done about it.

Of course, Bush will veto any bill that attempts to seek justice the moment it arrives at his desk. But he's on his way out. And there may be someone else in the White House soon enough to undo a lot of damage done by the president. That's a good thing to think of (actually, there is more than one person who would probably do that, but I'm talking about the guy who will actually make it to the White House).

Labels: , , ,

Monday, February 11, 2008

Bad Vista UI! Bad!

We all get to a point where our open window account in Explorer skyrockets. I use the 'Run' dialog to get to a lot of places, which opens each directory in a new window. So I often find myself with all my Explorer windows grouped together on the taskbar, and something like 16 or more directories in the listing. It's natural to just want to 'reset' things and close them all.

But beware! The Explorer group includes not only your directory windows, but also any copy jobs going on. If you right-click and choose 'Close Group' when you are copying, your job in unceremoniously canceled (which itself could take a while, depending on how cranky the Vista copy routines are that day). God help you if you happen to be copying many gigabytes of files.

This is bad user interface design. Directory windows and copy windows should not be grouped together. A directory window displays information, while a copy windows displays a process. Yes, they run in the same program (Explorer), but they are two absolutely different things, and should be grouped together into two separate groups on the taskbar. A less-correct alternative, but probably easier to implement in software, would be to close all the directory windows, then ask the user -- for each copy job -- whether or not the copy should be canceled.

Labels: , , , ,