HELP: Possibly infinite recursion in quiescence search

Code, algorithms, languages, construction...
Post Reply
OliveriQ
Posts: 2
Joined: Mon Apr 04, 2022 8:02 am

HELP: Possibly infinite recursion in quiescence search

Post by OliveriQ » 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
}

delphi_coder
Posts: 9
Joined: Sun Mar 03, 2019 4:11 pm

Re: HELP: Possibly infinite recursion in quiescence search

Post by delphi_coder » Tue Jul 12, 2022 12:18 am

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

AspectOfTheNoob
Posts: 1
Joined: Wed Feb 08, 2023 4:17 pm

Re: HELP: Possibly infinite recursion in quiescence search

Post by AspectOfTheNoob » Wed Feb 08, 2023 4:28 pm

Quiescence search only generates captures, not all legal moves

Post Reply