예제 #1
0
파일: main.py 프로젝트: CMLL/tdd_tic_tac
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_player_can_win_by_filling_a_second_diagonal(self):
     """
     A player can win by filling the second diagonal.
     """
     game = TicTac()
     game.board.body = [
         ['x', 'x', 'y'],
         ['x', 'y', 'x'],
         ['y', 'x', 'y'],
     ]
     assert game.who_won() == game.player_two
예제 #3
0
 def test_a_player_can_win_by_filling_a_diagonal(self):
     """
     A player can win by filling one of the two possible
     diagonals available.
     """
     game = TicTac()
     game.board.body = [
         ['x', 'x', 'y'],
         ['y', 'x', 'y'],
         ['y', 'y', 'x'],
     ]
     assert game.who_won() == game.player_one
예제 #4
0
 def test_a_player_can_win_by_having_a_column_filled(self):
     """
     The player can win by having a complete column with
     its mark.
     """
     game = TicTac()
     game.board.body = [
         ['x', 'x', 'y'],
         ['y', 'x', 'y'],
         ['x', 'y', 'y'],
     ]
     assert game.who_won() == game.player_two
예제 #5
0
 def test_a_player_wons_by_having_any_row_with_its_mark(self):
     """
     The first player can win by having any row complete
     with its mark.
     """
     game = TicTac()
     game.board.body = [
         ['x', 'x', 'x'],
         ['x', 'y', 'y'],
         ['y', 'y', 'x'],
     ]
     assert game.who_won() == game.player_one