AI Project #1: All The King's Horses

Due: January 17 19, 2011, 11:59 PM

In this project, you will write a program to play a game called "All The King's Horses". A number of versions of this game are described in Conway's "On Numbers and Games", but we will play one specific version not described exactly there.

In this two-player game, each player has control of two chess knights on a chessboard (which can be of any size). On your turn, you must move one of your knights toward the upper-left corner of the board. In general, this means that four moves are available:

Of course, if a knight is near the top or left of the board, fewer moves will be possible, and a knight in the upper left 2x2 area cannot move at all. For this reason, the board can be considered to extend infinitely far down and to the right without the state space becoming infinitely large. In addition, a knight is not allowed to move to a square occupied by another knight (of either color). You lose the game if you are unable to make a move. As such, this game has no draws.

For this project, you will write code in Python that determines optimal moves for this game (in the minimax sense). Specifically, you must produce a file that reads in a game state from the command line (described below) including which player is to move, and returns the best possible next position after that player's move who will win if both players play optimally.

You should print out either "WHITE WILL WIN" or "BLACK WILL WIN" depending on which player can win the game if each play optimally. An example of running your function is:

username$ BLACK 2 2 3 3 1 2 3 1

The format for the command line arguments is:

Make sure not to print anything other than "BLACK/WHITE WILL WIN" in the final version you submit. (Presumably other print statements will be useful for you during debugging, but turn these off.)

You must also include a writeup (no more than one page) that describes your representation and how your code works. It must be clear enough for me to appropriately grade your code on efficiency and correctness.

You will submit your project using mycourses. You need to submit two files,, and writeup.txt, which is a plain text file documenting your code.

Your code will be tested using Python 2.6.

Your project grade will be assigned as follows:

Please contact Justin Domke with any clarifying questions. Answers will be posted here for all, so check for updates periodically.


Q) Will the program be tested with bad data?
A) No, the program will only be tested with valid inputs.

Q) Will you please give me a set of test cases?
A) No. :)