0

Hey I am trying to implement negamax with alpha-beta and quiesce search with 4 players but it is a little different. For example, lets say 0 = Red, 1 = Blue, 2 = Yellow, and 3 = Green, and Red and Green are on the same team meaning 2 turns will be the maximizer and 2 turns will be the minimizer. Here is my implementation based on the 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

This seems to not be working properly, I figured if the next player to move is on my team we should not switch alpha and beta and just not reverse the value. Any suggestion on anything I am doing wrong.

  • I assume this is for chess? A bit more context would be nice--why are we dealing with teams? – ggorlen Nov 18 '20 at 21:06
  • Because chess.com has 4 player chess, and it would be a challenge for me since i can make a regular chess engine in Python. – Nicholas English Nov 18 '20 at 21:11
  • OK, so how does the 4 player chess work exactly? Please describe the problem you're solving here. What exactly isn't working? I see [no problem context or expected result] [code dump taken out of context] [isn't working] so I'm pretty sure you'll need to provide more of a handle to folks who want to help. – ggorlen Nov 18 '20 at 21:13
  • I do not understand the difference for the ki. Its like play with two players but the move generator gives the ki only moves of the player who is on turn. There is nothing to change in the ki itself. – TheSlater Nov 18 '20 at 21:29
  • Sorry for the late response I am at work. I’ll add more details on the error and fix the question when I get home. – Nicholas English Nov 19 '20 at 06:56

0 Answers0