from TicTacToe import *

def DoPlays(plays):
	tictactoe.Reset()
	for p in plays:
		try:
			tictactoe.Play(p)
		except TicTacToeException, e:
			print "Exception:", e
		for row in tictactoe.GetBoard():
			print "\t", row
		print tictactoe.GetMoves()
		print

def GotResult(value):
	if value == -1:
		print "Game drawn"
	else:
		print "Player", value, "won."

tictactoe = TicTacToe()
tictactoe.AddNotifier(GotResult)

plays = [
	(2, [0, 0]),
	(1, [1, 1]),
	(1, [2, 1]), # illegal - same player tried to play twice
	(2, [2, 0]),
	(1, [0, 0]), # illegal move (already played there)
	(2, [1, 0]), # same player tried to play twice
	(1, [1, 0]),
	(2, [0, 2]),
	(1, [0, 2]), # illegal move (tried to play on a space already played)
	(1, [3, 2]), # illegal move (outside board area)
	(2, [2, 2]), # sample player tried to play twice
	(1, [2, 2]),
	(2, [1, 2]),
	(1, [0, 1]),
	(2, [2, 1]),
	]

print "Testing exception cases and drawn game."
print "---------------------------------------"
DoPlays(plays)
print

plays = [
	(2, [0, 0]),
	(1, [1, 1]),
	(2, [2, 0]),
	(1, [1, 0]),
	(2, [0, 2]),
	(1, [1, 2]),
	(2, [1, 2]), # game finished already
	]

print "Testing player 2 win."
print "---------------------------------------"
DoPlays(plays)
print

plays = [
	(1, [0, 0]),
	(2, [0, 1]),
	(1, [2, 2]),
	(2, [1, 0]),
	(1, [1, 2]),
	(2, [0, 2]),
	(1, [2, 1]),
	(2, [2, 0]),
	(1, [1, 1]),
	]

print "Testing player 2 win on the last move."
print "---------------------------------------"
DoPlays(plays)
print


