1

(井字游戏:15x15 棋盘上的 2 人游戏(玩家 x 和玩家 o),其中一个玩家首先形成 5 个棋子链,然后获胜)

更多描述


所以我实现了一个井字游戏算法,它使用简单的 alpha beta 修剪..

这是我到目前为止所拥有的:

def ab_minimax(state):
    max_position, max_value, alpha, beta = None, None, float('-inf'), float('inf')
    positions = getAvailablePositions()

    for position in positions:
        temp = next_state(state, position)
        value = self.ab_min_move(temp, 3, alpha, beta)

        if max_value < value:
            max_position = position
            max_value = value

    return max_position

def ab_max_move(state, depth, alpha, beta):
    if game_ended(state) or depth == 0:
        return get_score(state)

    value = float('-inf')

    positions = getAvailablePositions()

    for position in positions:
        temp = next_state(state, position)
        value = max(value, self.ab_min_move(temp, depth-1, alpha, beta))

        if value >= beta:
            return value

        alpha = max(alpha, value)

        if alpha >= beta:
            break

    return value

def ab_min_move(state, depth, alpha, beta):
    if game_ended(state) or depth == 0:
        return get_score(state)

    value = float('inf')

    positions = getAvailablePositions()

    for position in positions:
        temp = next_state(state, position)
        value = min(value, ab_max_move(temp, depth-1, alpha, beta))

        if value <= alpha:
            return value

        beta = min(beta, value)

        if alpha >= beta:
            break           

    return value

这很好用,但很明显,代理返回动作需要太多时间。

然后我遇到了威胁空间搜索的想法,它的主要目的是放置“威胁”。

在这个井字游戏中,威胁正在攻击诸如“.ooo”之类的序列。“呜呜。” (如果我是玩家 o)

问题是,我不知道我应该把这个威胁空间搜索放在哪里

阿尔法贝塔函数....

我很确定这个想法是将威胁空间搜索与原始的 alpha beta minimax 结合起来

算法,,,但我不确定应该在哪里以及如何完成......

有人可以给我一些解释或真正简短的伪代码..吗?

谢谢!

4

1 回答 1

2

Another idea here is that localize your minimax search , that is if your grid is sparsely occupied then no need to evaluate mini-max search on whole of the grid only evaluate mini-max on next positions which are in vicinity of already occupied region. Like at the beginning of the game you can consider only 5*5 grid as your state spaces rather than a 15*15 grid, this small optimization can save you lots of time. And as the grid gets filled you can see that the no of valid states itself get reduced hence your algorithm will remain as fast.

于 2013-11-19T04:34:46.563 回答