From 352b3f8b05a2445cb52fb66daa25e4a7bf0b3f43 Mon Sep 17 00:00:00 2001 From: Zachary Wahrman Date: Thu, 12 Dec 2019 18:36:09 -0500 Subject: [PATCH] Update state.py --- state.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/state.py b/state.py index 3169c83..bcd0095 100644 --- a/state.py +++ b/state.py @@ -9,11 +9,14 @@ def Minimax(state, depth, maximizingPlayer, alpha, beta): if depth == max_depth: - return state.eval(), None + return state.eval(state.board, playerColor, opponentColor), None if maximizingPlayer == playerColor: best_move = None for successor_state in state.generate_successors(state.board, maximizingPlayer): - val, move = Minimax(successor_state, depth + 1, False, alpha, beta) + if players[0] == maximizingPlayer: + val, move = Minimax(successor_state, depth + 1, players[1], alpha, beta) + else: + val, move = Minimax(successor_state, depth + 1, players[0], alpha, beta) if val == max(val, alpha): alpha = val best_move = successor_state.last_move @@ -27,7 +30,10 @@ def Minimax(state, depth, maximizingPlayer, alpha, beta): else: best_move = None for successor_state in state.generate_successors(state.board, maximizingPlayer): - val, move = Minimax(successor_state, depth + 1, True, alpha, beta) + if players[0] == maximizingPlayer: + val, move = Minimax(successor_state, depth + 1, players[1], alpha, beta) + else: + val, move = Minimax(successor_state, depth + 1, players[0], alpha, beta) if val == min(val, beta): beta = val best_move = successor_state.last_move @@ -247,8 +253,8 @@ def generate_successors(self, board, color): #Evaluation function def eval(self, board, playerColor, opponentColor): - player_moves = self.generate_moves(playerColor) - opponent_moves = self.generate_moves(opponentColor) + player_moves = self.generate_moves(board, playerColor) + opponent_moves = self.generate_moves(board, opponentColor) if player_moves == 0: return -1 * math.inf if opponent_moves == 0: @@ -258,6 +264,7 @@ def eval(self, board, playerColor, opponentColor): def makeMove(self, color): if len(self.generate_moves(self.board, color)) > 0: move = Minimax(self, 0, color, math.inf * -1, math.inf) + print(move) self.movePiece(move[1][0], move[1][1]) else: self.gameOver = 1