Friday, September 04, 2015

Clare vs. 'the Cat'

This afternoon I programmed my very first simulation of the family pet, Shadow. In this simplistic iteration, the cat plays a game with the user. The idea is to stack 20 cans of cat food. The user and the cat take turns to stack 1, 2 or three cans at a time: the first to 20 wins.

Here is a transcript of the start of play. The cat's moves are between asterisks ***; the user's moves are signposted with -->.

Miaow, my name is Shadow. The game is to stack 20 cans of cat food. You can choose 1 or 2 or 3 cans at each turn. Me too! First to 20 wins.

Do you want to play first? type y for yes, n for no followed by return.

So, do you want to play first (y/n and press return)? n

*** My move is 2 cans. Total number of cans = 2 ***

enter your number 1, 2 or 3 |: 2

--> You entered 2 cans. Total number of cans = 4

*** My move is 1 cans. Total number of cans = 5 ***

enter your number - 1, 2 or 3: |:  ...

And here is a video of my guinea pig, Clare, playing the cat. What was it that Kipling said about winning and losing? (You may have to double-click on video to get full screen).

The game was an exercise from 'The Art of Prolog' and it took me a while to develop the game-play to program. Here is the folder containing the Prolog program by the way: you may use it to infer the winning strategy.

No comments:

Post a Comment

Comments are moderated. Keep it polite and no gratuitous links to your business website - we're not a billboard here.