HELP: Possibly infinite recursion in quiescence search
Posted: Mon Apr 04, 2022 8:21 am
I've implemented negamax search in my chess engine and everything was working fine until I tried implementing quiescence search. When I don't add a depth limit to it I get a stack overflow error. And I'm unable to find the source of the issue, so I would appreciate if anyone good give some feedback. Not necessarily a concrete solution but maybe ways to debug this. All the source code can be found here. And this is the qsearch implementation:
Code: Select all
func (search *Search) quiescence(pos Position, alpha, beta int) int {
// evaluation
evaluation := evaluate(pos)
// fail-hard beta cutoff
if evaluation >= beta {
// node (move) fails high
return beta
}
// found better move
if evaluation > alpha {
// PV node (move)
alpha = evaluation
}
// move list
moves := pos.generate_moves()
for i := 0; i < moves.count; i++ {
// preserve board state
pos.copy_board()
// increment half move counter
search.ply++
// skip if move is ilegal
if !pos.make_move(moves.list[i], only_captures) {
search.ply--
continue
}
// recursively call quiescence
score := -search.quiescence(pos, -beta, -alpha)
// take back move
pos.take_back()
// decrement ply
search.ply--
// fail-hard beta cutoff
if score >= beta {
// node (move) fails high
return beta
}
// found better move
if score > alpha {
// PV node (move)
alpha = score
}
}
// node fails low
return alpha
}