コード例 #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
ファイル: test_tictac.py プロジェクト: CMLL/tdd_tic_tac
 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
ファイル: test_tictac.py プロジェクト: CMLL/tdd_tic_tac
 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
ファイル: test_tictac.py プロジェクト: CMLL/tdd_tic_tac
 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
ファイル: test_tictac.py プロジェクト: CMLL/tdd_tic_tac
 def test_a_newly_started_game_cannot_be_over(self):
     """
     A new game cannot be considered over.
     """
     game = TicTac()
     assert not game.is_over()