if len(sortedMoves) == 0: return worst (playerOneTorque1, playerOneTorque2) = thisBoard.getTorque(thisBoard.playerOneMoves) if self.currentPlayer == 1: # We want to balance the weights that player one placed as much as possible. if abs(playerOneTorque1) > abs(playerOneTorque2): bestMove = sortedMoves[-1] else: bestMove = sortedMoves[0] else: # Otherwise we want to unbalance the weights that player one placed as much as possible. bestMove = sortedMoves[0] return bestMove def runAlphaBeta(thisBoard, playerNumber): inf = float('Inf') infSet1 = (inf, inf, inf, inf) infSet2 = (inf, inf, inf, inf) testStrategies = Strategies(playerNumber) score = testStrategies.alphaBeta(thisBoard, infSet1, infSet2) output = (score[0], score[1]) return output if __name__ == '__main__': thisBoard = board.readBoard('board.txt') output = runAlphaBeta(thisBoard, 1) print(output)
def __init__(self, playerNumber, remainingTime): self.__board = board.readBoard(self.BOARD_NAME) self.playerNumber = playerNumber