fredag 10 december 2010

Tic-tac-toe in python

Represent a board with a nine character string with spaces, "X", and "O". The rows of the board are concatenated to make the string, so the board


 X |   |   
---+---+---
   | O |   
---+---+---
   | X | O 


is the string "X   O  XO".

Given a board string, the function tic() returns the next board.  However, if the opponent can win (provided he makes the right moves), then tic() doesn't try to fight back, and may return bad moves.  A smarter program might continue to fight back as long as the game is not actually over.

Inga kommentarer:

Skicka en kommentar