Example #1
0
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)
Example #2
0
 def test_a_game_without_a_clear_victor_is_a_draw(self):
     """
     A game without victor is a draw.
     """
     game = TicTac()
     game.board.body = [
         ['y', 'x', 'y'],
         ['y', 'x', 'y'],
         ['x', 'y', 'x'],
     ]
     assert game.is_a_draw()