I'm trying to build a chess AI, and I'm running into a strange error. As a foreword, I did go through stackoverflow and try to find similar issues, but it didn't help me as I thought I was implementing tuple unpacking correctly and I can't seem to find the bug in my code.
Below is the code for my negamax function. It takes in the chess board, the current player and the current depth.
It uses the board.evalFunction() function which returns a number representing the value at the board position to the current player. That function is working properly. I have marked the line where I am getting the error: ValueError: need more than 0 values to unpack
.
Can someone help me out?
def negamax(board, player, depth):
if player == 'human':
opposite = 'computer'
else:
opposite = 'human'
if depth == 0:
return (board.evalFunction(player), None)
moveset = board.generateMoves(player)
maximum = -99999999999
optMove = ""
for move in moveset:
newBoard = copy.deepcopy(board)
newBoard.makeMove(move)
newBoard.rotate()
#The following line throws the error
score, move = -1 * negamax(board, opposite, depth - 1)
if score > maximum:
maximum = score
optMove = move
elif score == maximum:
if(random.choice([True, False])):
maximum = score
optMove = move
return (maximum, optMove)