Artificial Intelligence Pathfinding ----------------------------------- Moving monsters ain't easy. The first version of kamikaze let them wander along the walls, so they could never get into the middle of the playfield. The second version added some randomization, yet the movements were pretty predictable. In kamikaze 0.0.4pre, pathfinding was introduced. It was triggered whenever an item was uncovered (such as additional life or power), and using a depth-first flood-fill algorithm calculated in advance the way of each monster to the item. Features: - path was recalculated whenever a 'dirty flag' was recognized (such as a tile in the path marked as walkable wasn't walkable anymore) Drawbacks: - any monster which couldn't reach the item was recalculated in ever round. - paths were not the shortest ones, and emerging path shortcuts were not considered To solve the problems, the new algorithm comes into the game. It uses multiple breadth-first iterations, and thus guarantees that whenever the first path is found, it is the shortest one. The drawback, that in each iteration many previously examined tiles must be examined again, is a small one, given that no useless recalculations occur. (This can be ensured by introducing a list of unreachable tiles for each monster, linked with a timestamp.) Possible improvements: - dynamic updates (possible, but consumes a lot of time) - lower bounds (punishments) to exclude paths that are short but go nearby bombs or enemies Note that all those optimization only affect CPU usage, not network or I/O usage, and barely differ in memory requirements.