Board Games Automated

This post on Boing Boing got me thinking about the time I wrote a program that played with itself. I think it was written on the mutated basic supplied with the ICL/BT Merlin Tonto that my Dad brought home one day. Or it could have been on the ZX Spectrum, can’t remember.

Anyway, I taught the computer to play Snakes and Ladders (aka Chutes and Ladders). The board was held in a one-dimensional array – no need for two dimensions, for reasons that will become clear. Certain cells in the array held markers that would cause the program to send the player forward or backward to another cell if they landed there – this represented the Snakes (sending you backward) or Ladders (sending you forward).

I the first complete version of the game, a human could play against the computer. You pressed the space bar, and the program would roll a virtual die, that is, randomly generate a number from 1 to 6. Then it would tell you what space you landed on, whether there was a snake or ladder there, and where you ended up. Then the computer would roll the die for itself, and display it’s final position. Repeat until one or both of you were at position 100. The human always went first, and it was possible to have a draw. This prevented me from having to decide who got to play first. You had to land exactly on 100. I had implemented the rule whereby if you were at space 98 for example, and you rolled a six, you would move two forward, then back four to 96.

The next stage was to get the computer to play itself (“number of players: zero“). This was easy, just do the computer turn twice. I built in a delay to the turn and position display so you could watch them play. You ran the program, the display would flicker it’s digits for a few seconds until one of the computer players would reach 100, and it would be lauded as the winner.

The final step into insanity came when I removed the display portion altogether. You ran the program, and about a second later, a winner would be announced. Of course, it looked like I was just randomly selecting a winner and displaying it, but I knew that in the guts of the computer, the subroutines were running and pieces were being moved up and down the board. I even got it to play “best of 3”, “best of 5”, and later, “best of 99” which took a couple of minutes – but every game was played through properly.

I like to think of two Little Computer People, Red and Blue, shaking a tiny die (at least 7 pixels square on a side of course – you work it out) and moving their little pieces, hoping to land on that long ladder that went all the way from 5 to 95.