function minimax(board, depth, alpha, beta) { if(depth === 0 …) { … return … } else { … for (index = 0; index < possible_moves.length; ++index) { … minimax(new_board, --depth, alpha, beta) // ^^ … } } }
Here you're decrementing the depth
in a loop. Use depth <= 0
for the base case, and/or pass depth - 1
as an argument or put the decrement statement before the loop.