コード例 #1
0
ファイル: views.py プロジェクト: mtgorski/tic_tac_toe
def advance_helper(player_first, board_string):
    '''
    Given a game state represented by a string, updates that state
    with the perfect strategy's next move, if any and the result
    of the game, if any.

    :param player_first: string representing whether the player went first
        ('true' or false')
    :param board: string representing the state of the board. Length 9 each
        character being 'x', 'o' or '-'
    :returns: dictionary of the form {'board' : '-x--o----', 'wins' : ''},
        where 'wins' can be either '', 'x', 'o' or 'tie'.
    '''
    board = construct_board(board_string)
    result = board.result()
    if result == "None":
        move = perfect(board)
        board.place(*move)
        board_string = construct_board_str(board)
        result = board.result()
        if result == "None":
            result = ''
    result = result.lower()
    return {'board' : board_string, 'wins': result}
コード例 #2
0
def advance_helper(player_first, board_string):
    '''
    Given a game state represented by a string, updates that state
    with the perfect strategy's next move, if any and the result
    of the game, if any.

    :param player_first: string representing whether the player went first
        ('true' or false')
    :param board: string representing the state of the board. Length 9 each
        character being 'x', 'o' or '-'
    :returns: dictionary of the form {'board' : '-x--o----', 'wins' : ''},
        where 'wins' can be either '', 'x', 'o' or 'tie'.
    '''
    board = construct_board(board_string)
    result = board.result()
    if result == "None":
        move = perfect(board)
        board.place(*move)
        board_string = construct_board_str(board)
        result = board.result()
        if result == "None":
            result = ''
    result = result.lower()
    return {'board': board_string, 'wins': result}
コード例 #3
0
 def test_OnBoardWithOneAcceptableOptionReturnsIt3(self):
     self.assertEqual(perfect(self.board6), (8, 'x'))
コード例 #4
0
 def test_OnBoardWithOneAcceptableOptionReturnsIt2(self):
     self.assertEqual(perfect(self.board5), (1, 'o'))
コード例 #5
0
 def test_OnBoardWithMultipleAccetableOptionsReturnsOneOfThem2(self):
     self.assertIn(perfect(self.board3), [(0, 'o'), (2, 'o'), (6, 'o'), (7, 'o')])
コード例 #6
0
 def test_OnBoardWithMultipleAccetableOptionsReturnsOneOfThem1(self):
     self.assertIn(perfect(self.board1), [(6, 'x'), (2, 'x')])