goto in PHP 5.3

It appears that the goto statement is being added to PHP 5.3. Considering its bad reputation the move seems like a strange feature to be adding. Especially since one of the main benefit of a goto, exception handling, appears to have been introduced in PHP 5.

Hopefully all the web programmers out there will tread cautiously with their new power.

Taking Stuff Apart: Nikko NA-550

From time to time I come across an old piece of electronics that I want to harvest some parts from. Stepping motors from floppy disk drives, Solenoids from zip drives, small DC motors from CD drives to name a few of my favorites. Audio Amplifiers in particular are my very favorit. They have lots of interesting and hard to find pieces.





Without further adieu, here's a before shot of this vintage 80's "Nikko NA-550 Integrated Amplifier" that I picked up at a landfill a few weeks ago. For anyone curious, the power button was jammed in the off position, which is probably what earned it a spot at the dump.



Got a bunch of nice metal knobs, some dB meters, some very nice Alps selector switches, some Alps potentiometers, a 2.5A breaker and some other misc parts.

Ant AI

I've been toiling away trying to come up with an algorithm which will make ants move in a believable manner while only using a very limited view (the 4 adjacent tiles which they can move to). This was much more difficult than I was expecting, it sounds too easy to say "the ants wander around randomly, then once they found food they could head home following the chemicals they left behind". Implementing it like that not only doesn't work, but the ants end up congregating around the ant hill and don't accomplish much of anything.

The final algorithm is a set of rules that look like this:
1. If carrying food, call go home AI.
2. If carrying food and in base, drop food (or wander until there is a spot to drop the food), set chemical output to low.
3. If not on surface, wander until on surface.
4. If on surface, check for food, pickup, change chemical output to high.
5. If on surface and no food, try to follow a chemical trail.
6. If no trail to follow search for food by looking for a spot with low (or no) chemicals.

The most successful part of this algorithm is step #6, the ants really spread out and find food spawned in a random location quickly.

The other interesting part, which isn't in the steps above, has to do with how the ants apply their pheromone to the tiles. I'm not sure how it is done in nature, but I have it set so if the trail is cold and the ant doesn't want other ants to follow it (i.e. not carrying food) it deposits only a small chemical trail, essentially marking that someone has been there. On the other hand if it does want other ants to follow it (i.e. carrying food), it will deposit a high amount.

To glue everything together in a natural manner, the chemical levels "decay" over time.

The biggest surprise of all this how complex the chemical trail following algorithm became. In an ideal world the chemical trail would be a high resolution heat-map style implementation which would allow the direction they are moving in to be clear. With my low resolution chemical trail, if there is a block of several high-chemical tiles all clumped up the ants start getting put into cycles, so I have to add special cases to resolve that. I'm not sure how interesting those special cases are so I'll leave them out for now.

I now have lots of variables to tweak (chemical output low, chemical output high, chemical decay rate, decay amount, max chemical per tile) several algorithms and functions which could use tweaking (chemicalOutput, trail following). All in all I'm very happy with the result given the constraints, and will hopefully have a demo out soon.