Python Negamax算法,带Alpha Beta和静止搜索,团队(4名玩家)

Python Negamax算法,带Alpha Beta和静止搜索,团队(4名玩家),python,alpha-beta-pruning,negamax,Python,Alpha Beta Pruning,Negamax,嘿,我正在尝试用alpha-beta实现negamax,用4名玩家实现静止搜索,但有点不同。例如,假设0=Red,1=Blue,2=Yellow,和3=Green,红色和绿色在同一组,这意味着2圈是最大值,2圈是最小值。下面是我基于wiki的实现 def search(self, position, alpha, beta, depth, root=True): self.nodes += 1 best_move = [] if position in self.hist

嘿,我正在尝试用alpha-beta实现negamax,用4名玩家实现静止搜索,但有点不同。例如,假设
0=Red
1=Blue
2=Yellow
,和
3=Green
,红色和绿色在同一组,这意味着2圈是最大值,2圈是最小值。下面是我基于wiki的实现

def search(self, position, alpha, beta, depth, root=True):
    self.nodes += 1
    best_move = []
    if position in self.history and not root: return 0 # prevent a three-fold repetition moves when the engine is winning.
    bestscore = -999999
    if depth == 0 or position.is_final: return self.quiesce(position, alpha, beta)
    for move in position.moves():
        if position.turn in (0, 2): score = -self.search(position.move(move), -beta, -alpha, depth - 1, False)
        else: score = self.search(position.move(move), alpha, beta, depth - 1, False)
        if score >= beta: return score # fail-soft beta-cutoff
        if score > bestscore:
            bestscore = score
            if root: best_move = move
            if score > alpha: alpha = score
    if not root: return bestscore
    else: return best_move

def quiesce(self, position, alpha, beta):
    if position.is_final: return position.score + position.value() # this position is final so just return the evaluation.
    stand_pat = position.score + position.value()
    if stand_pat >= beta: return beta
    if alpha < stand_pat: alpha = stand_pat
    for move in position.moves():
        if move[2] != 1: continue # continue through the moves until we encounter another capture.
        if position.turn in (0, 2): score = -self.quiesce(position.move(move), -beta, -alpha)
        else: score = self.quiesce(position.move(move), alpha, beta)
        if score >= beta: return beta
        if score > alpha: alpha = score
    return alpha
def搜索(self、position、alpha、beta、depth、root=True):
self.nodes+=1
最佳移动=[]
if position in self.history and not root:返回0#当引擎获胜时,防止三次重复移动。
最佳得分=-999999
如果深度==0或位置为最终:返回自我静止(位置、α、β)
对于移入位置。移动():
如果position.turn(0,2):score=-self.search(position.move(move),-beta,-alpha,depth-1,False)
否则:分数=自我搜索(位置、移动、阿尔法、贝塔、深度-1、假)
如果得分>=beta:返回得分#失败软beta截止
如果得分>最佳得分:
最佳分数
如果根:最佳移动=移动
如果分数>α:α=分数
如果不是根:返回最佳分数
其他:返回最佳移动
def静止(自身、位置、α、β):
如果position.is_final:return position.score+position.value()#此位置为final,因此只需返回评估。
站姿=位置分数+位置值()
如果站姿>=beta:返回beta
如果阿尔法<站姿:阿尔法=站姿
对于移入位置。移动():
如果移动[2]!=1:继续#继续移动直到我们遇到另一个俘虏。
如果position.turn(0,2):分数=-self.quiesce(position.move(move),-beta,-alpha)
其他:分数=自我静止(位置、移动、阿尔法、贝塔)
如果得分>=beta:返回beta
如果分数>α:α=分数
返回阿尔法

这似乎不能正常工作,我想如果下一个球员是在我的球队,我们不应该切换阿尔法和贝塔,只是不扭转的价值。对我做错的事情有什么建议吗。

我想这是下棋用的吧?再多了解一点环境就好了——我们为什么要与团队打交道?因为chess.com有4人国际象棋,这对我来说是一个挑战,因为我可以用Python制作一个常规的国际象棋引擎。好的,那么4人国际象棋到底是如何工作的呢?请描述一下你正在解决的问题。到底是什么不起作用?我看到[没有问题的上下文或预期结果][断章取义的代码转储][不起作用],所以我很确定您需要为想要帮助的人提供更多的处理。我不理解ki的区别。这就像两个玩家的游戏,但移动生成器只提供轮到的玩家的ki移动。ki本身没有什么可以改变的。很抱歉我在工作中反应太晚了。我将添加有关错误的更多详细信息,并在回家后修复问题。