Page 1 of 1

HELP: Possibly infinite recursion in quiescence search

Posted: Mon Apr 04, 2022 8:21 am
by OliveriQ
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
}

Re: HELP: Possibly infinite recursion in quiescence search

Posted: Tue Jul 12, 2022 12:18 am
by delphi_coder
I experienced this problem when i include check moves on quiescence search.as a simple debug technique you may want to try putting depth limit for including checks in quiescence. or exclude them to see if the problem persist

Code: Select all

	// move list
	moves := pos.generate_moves()
just as a doubt: does this line of code generate all moves or just captures

ps: what language is this. looks like both pascal and C

Re: HELP: Possibly infinite recursion in quiescence search

Posted: Wed Feb 08, 2023 4:28 pm
by AspectOfTheNoob
Quiescence search only generates captures, not all legal moves