Computer games: Simplified 'Snapper'
I don't know the name of this computer game, not being much of a gameplayer, but it looks remotely like snapper. You can try this one manually, as well, but it is definitely not up for the game of the year award, and I am mainly interested in automatic mode.
You are supposed to collect the basket ball 5 times, watching out for passing cars- you have 3 lives.
The hunted party naturally moves away from the player, while the hunters try to approach the player. Everybody and everything are assumed to favour horizontal movement to vertical, which slightly simplifies the program.
The first point to note is that a little dither in the motion actually improves performance, especially when there are obstacles on the board. Why not add the full snapper maze then? Well, unless the hunters mostly move periodically, the game then becomes impossible to win.
The technique for the player in demo mode is quite simple: If the player is closer to the hunted party than the hunters, it attacks. Otherwise, it turns away from the target in order to gain some space by exploiting its superior speed, and will try again later. (The game cannot be won unless there is a speed advantage).
It seems rational to escape when in the midst of hunters, but this actually brings the success rate down to 60%: There are 3 lives and subsequent play is easier if the hunters are all drawn together. The routine is included in the code, but left inactive.
It is fair to say that the hit rate varies as the number of hunters, board size and player-hunter speed ratio does. Statistics mode essentially involves switching off the sound, display and interframe delay. Reading from and writing to an array replaces screen oriented calls like boxFill and getPointColour. On a 1.8 GHz processor, the program played 10,000 games in about 160 seconds. When the speed advantage is 50%, then:
Hit rate | 90% |
Average lives, games won | 1.8 |
Average collections, games lost | 0.8 |
I certainly don't consider computers to be glorified games machines, but the occasional game might attract some people who only have a marginal interest in more important topics. Here is the game code.
My
breakout demo mode is outperforming me! I will tidy up the code and present it in a few months time.
For my own code, up to this point: Valid XHTML 1.0!