Shell Scripting

December 13th, 2006

This is the first shell scripting guide I’ve seen that doesn’t suck. It’s worth it to every programmer to learn shell scripting, bash files, unix/linux command line, blah blah blah whatever. It’s all the same. After overcoming your initial disgust and/or horror you’ll come to realize something, it’s actually pretty useful. The Linux programmer types are evil, to be sure, but they really know how to get the job done when you want to be hardcore about it. Just in case you don’t know, Windows users can use Cygwin to bring the Unix command line experience to them.

The most important thing to know is that the language used in the command line is the exact same thing as a shell script. That’s all a shell script really is, line after line of commands as if somebody typed them one after the other. I enjoy it so much now that I run my website entirely through a command line (frontends are for suckers) and it’s actually much easier in the long run once you get over the learning curve.

Twilight Princess (Review)

December 12th, 2006

Okay, first off there are no spoilers here, so unless you’re hardcore about keeping yourself hidden from any information, read with impunity. Also, I’m gonna complain about it some in this review, but that’s just what I do. There should be no doubt in the minds of any Wii or Gamecube owner that they should buy this game, and people without either system should consider getting it to play this game. It’s a near-perfect Zelda game, the likes of which we’ll probably never see again for a long time. Simply put, if you ever enjoyed a Zelda game, you’ll enjoy this.

It’s long, it took me around 50 hours (keeping in mind I went after every side-quest I could get my hands on). There’s lots of interesting weapons, most of them rehashes of older ones but they tried to enhance nearly every one of these in some way. There’s some new stuff in there too, but these aren’t very usable except in specific situations, which is annoying, but they’re fun while they last. Lots of dungeons, lots of side-quests, lots of minigames, lots of things to collect and enemies to kill. It looks fantastic (despite being a Gamecube game), and it’s one of the best games I’ve played in a long time.

The dungeons are fascinating, each is so unique that it never seems to get old despite how many you’ll go through. It’ll probably get hard for you at some points, otherwise it’d be boring, but mostly follows the usual Zelda concepts. They’ve improved the swordplay, and while it’s mostly standard at first, you can pick up nifty tricks that make fighting very interesting (Tip: sheathe your sword right after killing a more powerful enemy, Link does a cool little animation when you do). You get a new sidekick, much like Navi and Tatl, only instead of a fairy it’s a demonic looking imp named Midna. Midna turns out to be darker and more interesting than both fairy sidekicks and does more useful things than yell “Hey!” and “Listen!” whenever you do something.

You spend a lot of your time as a Wolf in the game (while Midna rides on your back). Which is interesting, but gets old - right around the time they stop forcing you to be one though. Hyrule is huge, but there’s lots of warping so you don’t have to spend all your time walking everywhere. Epona (the horse) is back again, and she’s pretty fast too. There’s no musical instrument this time, instead you mostly rely on plants that Link can play special tunes with. They only grow in certain places, but it ends up being more interesting anyway since there’s nothing to play.

I played the Wii version, and in my opinion it probably doesn’t have any real advantage over the Gamecube version. The Wii controls are tacked on, and although they’re interesting sometimes (fishing!) the advantages are slim. Unless the Gamecube version has been neglected in some way, don’t concern yourself with what’s better and buy what you can get.

As for complaints? Why are there so many rupees?! I can’t kill an enemy without triggering a treasure chest loaded with so many rupees Link refuses to take it. I’m not joking, he’ll seriously put it back. There’s nothing to spend all your money on so I simply donate most of it to a man who won’t actually give you anything if you give him enough. The minigames in the game are dirt cheap, sometimes free, and most of the things you can buy are refills (bombs for example). The kind of things you pick up plenty of while playing the game normally. So why am I complaining? It gets really tired checking dozens of treasure chests full of money because you don’t want to miss a key or a heart piece only to find yet another 100 rupees that you can’t have. It’s like Hyrule’s going through a recession.

The bosses in the game are very epic and cool looking, but are usually pretty lame. They’re so easy to beat it’s ridiculous, I beat nearly all on the first try without any potions or fairies to help me out. Their weak spots are usually obvious and they have a hard time hurting anybody who can see them winding up for an attack. One boss (not the first one either) didn’t hit me once. He didn’t seem to even try, I actually threw myself in his way because I thought he’d do something interesting. Instead he ignored me. There’s a couple of exceptions (particularly sword-battle minibosses), but you’re mostly there to enjoy how nifty the boss looks. I’m mostly surprised that the same guy who directed some of the best bosses in a Zelda game (Majora’s Mask had some amazing fights) has managed to create some of the lamest. Keep in mind boss battles are a fraction of the game, you spend most of your time in pure dungeon-wandering bliss.

I can’t shake the feeling this is the last great Zelda game in some way. A Link to the Past defined the series, Ocarina of Time made it amazing, and now Twilight Princess is quite possibly as good as it gets. There were flaws, sure, but how can you improve that much upon something so perfected? The only hope for the series now is probably some drastic changes, because the formula probably won’t work any better than this. Hopefully they’ll think up some new ideas using the Wii, since a new Wii Zelda game is already in the works.

Got a Wii (Review)

December 7th, 2006

EDIT: I’m updating my review. It was a little premature. I’m allowed to do that right? Here’s the better version, although in the end I say the same thing.

My Wii Friend Code is: 0098 9538 1192 6591. Add me and leave your friend code in the comments if you like.

I finally got ahold of a Wii, barely. I was #32 in line and they only had 32 consoles. Twilight Princess is beyond amazing. It’s purified classic Zelda in a fancy package. It’s perfect so far, and without overselling it, it’s already on of the better games I’ve ever played. I can’t really say if it’s any better on the Wii than on the Gamecube though, the pointer (for aiming) mostly annoys me so I turned it off. There’s a minigame in Zelda that convinced me the Wiimote is the real deal, you rotate the Wiimote to rotate a board in the game and it catches every subtle movement. That, along with fishing, probably makes it more worth it than the Gamecube version. Other things though, like swinging the sword, are basically like pushing buttons by swinging the Wiimote instead. Link doesn’t, for example, swing in the direction you did. The speaker on the Wiimote is only annoying so far, and doesn’t really add to the game.

Wii Sports is mostly interesting because the Wiimote’s interesting right now. It’s ultimately a few experimental minigames put together. Still, I’m becoming addicted to it anyway. One feature that I find interesting are the Miis. You can create a caricature of a person and play as them in Wii Sports (and other games). I found myself trying to make Miis of everyone I knew. When you connect your Wii to other Wiis you can see and share Miis.

There’s lots of missing features waiting to be updated. The News and Weather channels don’t work yet, and while the Weather channel should start working soon the News channel won’t for a while. I can’t download the Opera browser and it seems I’ll have to buy something to get it (although the browser itself is “free”). You can’t backup your Gamecube saves, although you can manage them on their memory cards. The Wii doesn’t come with S-Video cables (I thought it would), only composite cables. The “friend code” system is really annoying, it seems when you add a person to your address book they won’t even know - they have to add you too. Buying classic games online is mostly a scam, as you don’t own them like you own a cartridge, you merely license them and they’re locked to your Wii. Not to mention that you will probably be buying games you already own. It doesn’t play DVDs, or mp3s (except when in the photo viewer), or play videos (unless they’re Motion JPEG - which nobody uses).

As for the nifty things, you can send and receive emails using regular email or the Wiis. Since your Wii can stay partially active all the time your Wii will automatically download emails and alert you by pulsing the drive light. Gamecube games work perfectly with the Wii and offers a good replacement for it. The Wiimote can store Miis (and probably other data in the future) which can be brought to other Wiis.

I think, in the end, the Wii is worth it. There’s a lot of potential in this machine. Keep in mind though, you should consider not buying it unless you’re after a Wii game or two, I think it still needs more time to mature as a console. Most of my complaints are easily fixable and will be probably be fixed. In the end it’s a solid machine that will probably become what it should be - in the future.

Fast Array-Searching Algorithm

December 4th, 2006

A while back I tried to solve a simple problem, first pick a completely random integer, then what’s the fastest way to guess it? That is to say, using the fewest amount of chances. You only have one advantage, when you guess, you are told if the number you guessed is <= or > the number you a searching for.

The answer is pretty simple. Let’s say the number is 481, all you need to start with is a really big number that is greater than what you’re looking for, let’s say 1000. Cut it in half, is it still greater than the number? Yes, so now you know that the number is >= 0 and < 500. Cut it in half again, and you’ll find it’s <= the number you’re searching for. Now you know that the number is >= 250 and < 500. Continue with this like so…

250 >= x < 500
Guess: 325 (it's <=)
325 >= x < 500
Guess: 412 (it's <=)
412 >= x < 500
Guess: 456 (it's <=)
456 >= x < 500
Guess: 489 (it's >)
478 >= x < 489
Guess: 483 (it's >)
478 >= x < 483
Guess: 480 (it's <=)
480 >= x < 483
Guess: 481 (it's <=)
481 >= x < 483
Guess: 482 (it's >)
481 >= x < 482

At the end, you’ll notice there’s only one number that’s >= 481 and < 482, the number you’re looking for.

In case you didn’t notice several numbers above were rounded. This always bothered me as it seemed untrustworthy, inheriting possible problems from floating point number math. Then I realized this issue could be overstepped and made much faster through the use of binary math. With a binary math technique you’d only work with multiples of two, so there are never rounding issues. First you need to find the highest multiple of two that is above the number you are searching for, in this case, we’re trying to find 1683.

Guess: 00000000 00000001 (1) (true)
Guess: 00000000 00000010 (2) (true)
Guess: 00000000 00000100 (4) (true)
Guess: 00000000 00001000 (8) (true)
Guess: 00000000 00010000 (16) (true)
Guess: 00000000 00100000 (32) (true)
Guess: 00000000 01000000 (64) (true)
Guess: 00000000 10000000 (128) (true)
Guess: 00000001 00000000 (256) (true)
Guess: 00000010 00000000 (512) (true)
Guess: 00000100 00000000 (1024) (true)
Guess: 00001000 00000000 (2048) (false)
Answer: 2048

Now we know the first multiple of two that is higher than the number is 2048. Now finding the number between the current minimum/maximum is much simpler through the use of binary math.

00000100 00000000 => 1024 (start)
00000110 00000000 => (1024 | 512) == 1536 (true)
00000111 00000000 => (1536 | 256) == 1792 (false)
00000110 10000000 => (1536 | 128) == 1664 (true)
00000110 11000000 => (1664 | 64) == 1728 (false)
00000110 10100000 => (1664 | 32) == 1696 (false)
00000110 10010000 => (1664 | 16) == 1680 (true)
00000110 10011000 => (1680 | 8) == 1688 (false)
00000110 10010100 => (1680 | 4) == 1684 (false)
00000110 10010010 => (1680 | 2) == 1682 (true)
00000110 10010011 => (1682 | 1) == 1683 (true)
Answer: 1683

You’ll notice every time the result is true, the bit that is currently being tested stays in the result, otherwise it returns to zero.

Next is a simple example of how to use this technique. The goal of this code is to insert a number into an Array in numerical order. That is to say, each number in the Array should be greater than (or equal to) the numbers that precede it. Also keep in mind even if there is only one entry (length == 1) there are two possible places to put the new number, before and after the lone entry.

function addEntry(entry:Number):void {
var cBit:uint = 1;
while (cBit < arr.length) {
cBit <<= 1;
}
var pos:uint = 0;

do {
if ((pos | cBit) <= arr.length) {
if (entry >= arr[(pos | cBit)-1]) {
pos
|= cBit;
}
}

} while ((cBit >>>= 1) !== 0);
arr.splice(pos,0,entry);
}

That’s the simplified version, get a more optimized and complete example here. The great thing about this method is that it can be used to keep (or find) just about anything sorted. I’d also like to note that while I did actually think this up on my own, I’m definitely not the first. Not by a long shot. The real name for it appears to be Binary Search Algorithim.