The book Python Programming for the Absolute Beginner uses this algorithm: Number the board 012 345 678 best_moves = [4,0,2,6,8,1,3,5,7] choose first available out of best_movesIt turns out that you can modify this scheme pretty easily with one-turn-lookahead to guarantee a draw for either player.