Пример #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)
Пример #2
0
 def test_a_game_can_be_over_once_one_player_has_won(self):
     game = TicTac()
     game.board.body = [
         ['y', 0, 0],
         ['y', 0, 0],
         ['y', 'x', 0],
     ]
     assert game.is_over()
Пример #3
0
 def test_a_game_with_empty_tiles_cannot_be_over(self):
     """
     A game in which there are still empty tiles cannot be considered
     over.
     """
     game = TicTac()
     game.player_one.make_move(1, 1)
     assert not game.is_over()
Пример #4
0
 def test_a_without_empty_tiles_can_be_considered_over(self):
     """
     A game in which therer are no more empty tiles can
     be considered over.
     """
     game = TicTac()
     game.board.body = [
         ['x', 'x', 'y'],
         ['y', 'x', 'x'],
         ['x', 'y', 'x'],
     ]
     assert game.is_over()
Пример #5
0
 def test_a_newly_started_game_cannot_be_over(self):
     """
     A new game cannot be considered over.
     """
     game = TicTac()
     assert not game.is_over()