def play(): """ Simple interaction with a game of tic tac toe. """ print "Welcome to the game of Tic Tac Toe." game = TicTac() while not game.is_over(): for row in game.show_game_board(): pprint(row) print "Make a move: " try: input_x = int(raw_input('Position X: ')) input_y = int(raw_input('Position Y: ')) try: game.player_one.make_move(input_x, input_y) except NotInTurnError: game.player_two.make_move(input_x, input_y) except InvalidMoveError as error: print error.message if game.is_a_draw(): print "Ended in a draw." else: for row in game.show_game_board(): pprint(row) print 'Player {} won.'.format(game.who_won().player_mark)
def test_board_reflects_the_movement_made_by_player_one(self): """ The board must reflect the movements made by each player after is done. """ game = TicTac() game.player_one.make_move(1, 1) expected = [[0,0,0], [0, 'x', 0], [0, 0, 0]] assert game.show_game_board() == expected
def test_board_can_be_visualized_as_a_list_at_game_start(self): """ The game board can be visualized as a list of coordinates at game start. """ game = TicTac() row = [0,0,0] expected = [row, row, row] assert game.show_game_board() == expected