Пример #1
0
def mc_trial(board, player):
    """ Play game until finished by switching players and performing random moves """
    while board.check_win() is None:
        empty_cells = board.get_empty_squares()
        next_move = random.choice(empty_cells)
        board.move(next_move[0], next_move[1], player)
        player = provided.switch_player(player)
Пример #2
0
def mc_update_scores(scores, board, player):
    """Update scores for a finished game"""
    winner = board.check_win()
    if winner == provided.DRAW:
        return
    
    for row in range(board.get_dim()):
        for col in range(board.get_dim()):
            square = board.square(row, col)
            if square == player:
                scores[row][col] = scores[row][col] + (SCORE_CURRENT if winner == player else -SCORE_CURRENT)
            elif square == provided.switch_player(player):
                scores[row][col] = scores[row][col] + (SCORE_OTHER if winner != player else -SCORE_OTHER)