Weird Behavior in Quiescence Search

Discussion of chess software programming and technical issues.

Moderators: hgm, Dann Corbit, Harvey Williamson

Forum rules
This textbox is used to restore diagrams posted with the [d] tag before the upgrade.
Post Reply
oriyonay
Posts: 24
Joined: Tue Jun 01, 2021 3:46 am
Full name: ori yonay

Weird Behavior in Quiescence Search

Post by oriyonay » Tue Jul 27, 2021 11:10 pm

Howdy everyone - I hope you're having a fantastic day so far!
I'm working on my engine right now and have been facing some weird bugs that all have to do with qsearch (whenever I don't use it, everything works perfectly): if I run 'go depth 6', followed by 'go depth 8' and 'go depth 9' (on the same position), everything works fine. But when I then try 'go depth 8' again, it gives me values close to -INF and INF.
Here is my code - I also do move ordering but I removed it to make this simpler.

Code: Select all

int quiescence(int alpha, int beta) {
  nodes_evaluated++;

  // static evaluation:
  int eval = evaluate();

  // alpha/beta escape conditions:
  if (eval >= beta) return beta;
  if (eval > alpha) alpha = eval;

  // generate all possible moves from this position:
  int moves[MAX_POSITION_MOVES];
  int num_moves = b.get_nonquiet_moves(moves);

  // if there are no more nonquiet moves to make, return the current static eval:
  if (num_moves == 0) return eval;

  // recursively qsearch the horizon:
  for (int i = 0; i < num_moves; i++) {
    // make move & recursively call negamax helper function:
    b.make_move(moves[i]);
    int score = -quiescence(-beta, -alpha);
    b.undo_move();

    if (score > alpha) {
      alpha = score;
      if (score >= beta) return beta;
    }
  }

  return alpha;
}
Any help, tips, or a nudge in the right direction would be greatly appreciated!
Thank you and enjoy the rest of your day!

federico
Posts: 10
Joined: Sun Oct 22, 2017 2:36 am
Location: Canada
Full name: Federico Rojo
Contact:

Re: Weird Behavior in Quiescence Search

Post by federico » Wed Jul 28, 2021 12:21 am

If you run the command go depth 9 and works fine, but if you run again you don't get the same results then my guess is that it has to do with the transposition tables.

If you have them i would look there. Try disabling them and see if the issue persists.


Fede

oriyonay
Posts: 24
Joined: Tue Jun 01, 2021 3:46 am
Full name: ori yonay

Re: Weird Behavior in Quiescence Search

Post by oriyonay » Wed Jul 28, 2021 1:13 am

federico wrote:
Wed Jul 28, 2021 12:21 am
If you run the command go depth 9 and works fine, but if you run again you don't get the same results then my guess is that it has to do with the transposition tables.

If you have them i would look there. Try disabling them and see if the issue persists.


Fede
Thank you for the reply! That's the thing - I haven't implemented transposition tables yet...

amanjpro
Posts: 563
Joined: Sat Mar 13, 2021 12:47 am
Full name: Amanj Sherwany
Contact:

Re: Weird Behavior in Quiescence Search

Post by amanjpro » Wed Jul 28, 2021 4:28 am

You probably recycle pv table incorrectly, or something along this line

Karlo Bala
Posts: 348
Joined: Wed Mar 22, 2006 9:17 am
Location: Novi Sad, Serbia

Re: Weird Behavior in Quiescence Search

Post by Karlo Bala » Wed Jul 28, 2021 1:29 pm

oriyonay wrote:
Tue Jul 27, 2021 11:10 pm
Howdy everyone - I hope you're having a fantastic day so far!
I'm working on my engine right now and have been facing some weird bugs that all have to do with qsearch (whenever I don't use it, everything works perfectly): if I run 'go depth 6', followed by 'go depth 8' and 'go depth 9' (on the same position), everything works fine. But when I then try 'go depth 8' again, it gives me values close to -INF and INF.
Here is my code - I also do move ordering but I removed it to make this simpler.

Code: Select all

int quiescence(int alpha, int beta) {
  nodes_evaluated++;

  // static evaluation:
  int eval = evaluate();

  // alpha/beta escape conditions:
  if (eval >= beta) return beta;
  if (eval > alpha) alpha = eval;

  // generate all possible moves from this position:
  int moves[MAX_POSITION_MOVES];
  int num_moves = b.get_nonquiet_moves(moves);

  // if there are no more nonquiet moves to make, return the current static eval:
  if (num_moves == 0) return eval;

  // recursively qsearch the horizon:
  for (int i = 0; i < num_moves; i++) {
    // make move & recursively call negamax helper function:
    b.make_move(moves[i]);
    int score = -quiescence(-beta, -alpha);
    b.undo_move();

    if (score > alpha) {
      alpha = score;
      if (score >= beta) return beta;
    }
  }

  return alpha;
}
Any help, tips, or a nudge in the right direction would be greatly appreciated!
Thank you and enjoy the rest of your day!
What do you do when the king is in check?
Best Regards,
Karlo Balla Jr.

oriyonay
Posts: 24
Joined: Tue Jun 01, 2021 3:46 am
Full name: ori yonay

Re: Weird Behavior in Quiescence Search

Post by oriyonay » Wed Jul 28, 2021 3:33 pm

Karlo Bala wrote:
Wed Jul 28, 2021 1:29 pm
What do you do when the king is in check?
Oh my god I didn't even think of that! Right now I'm not doing anything special in qsearch when the king is in check. What should I do?

aryan1508
Posts: 31
Joined: Sat Mar 20, 2021 2:44 pm
Full name: Aryan Parekh

Re: Weird Behavior in Quiescence Search

Post by aryan1508 » Wed Jul 28, 2021 3:40 pm

oriyonay wrote:
Wed Jul 28, 2021 3:33 pm
Karlo Bala wrote:
Wed Jul 28, 2021 1:29 pm
What do you do when the king is in check?
Oh my god I didn't even think of that! Right now I'm not doing anything special in qsearch when the king is in check. What should I do?
In Bit-Genie I avoid going into Qsearch if the king is in check, a kind of check extension

oriyonay
Posts: 24
Joined: Tue Jun 01, 2021 3:46 am
Full name: ori yonay

Re: Weird Behavior in Quiescence Search

Post by oriyonay » Wed Jul 28, 2021 4:05 pm

aryan1508 wrote:
Wed Jul 28, 2021 3:40 pm
In Bit-Genie I avoid going into Qsearch if the king is in check, a kind of check extension
I replaced the (somewhat dumb) line

Code: Select all

if (num_moves == 0) return eval;
with

Code: Select all

if (b.is_check()) return eval;
and it seems to work. Should I be returning the static evaluation in this case, or alpha?

amanjpro
Posts: 563
Joined: Sat Mar 13, 2021 12:47 am
Full name: Amanj Sherwany
Contact:

Re: Weird Behavior in Quiescence Search

Post by amanjpro » Wed Jul 28, 2021 6:06 pm

oriyonay wrote:
Wed Jul 28, 2021 4:05 pm
aryan1508 wrote:
Wed Jul 28, 2021 3:40 pm
In Bit-Genie I avoid going into Qsearch if the king is in check, a kind of check extension
I replaced the (somewhat dumb) line

Code: Select all

if (num_moves == 0) return eval;
with

Code: Select all

if (b.is_check()) return eval;
and it seems to work. Should I be returning the static evaluation in this case, or alpha?
You probably want to return alpha when there is no move to play... And when in check you should search all moves not only captures... To make sure you don't put the king into a mating net

Karlo Bala
Posts: 348
Joined: Wed Mar 22, 2006 9:17 am
Location: Novi Sad, Serbia

Re: Weird Behavior in Quiescence Search

Post by Karlo Bala » Wed Jul 28, 2021 7:34 pm

oriyonay wrote:
Wed Jul 28, 2021 4:05 pm
aryan1508 wrote:
Wed Jul 28, 2021 3:40 pm
In Bit-Genie I avoid going into Qsearch if the king is in check, a kind of check extension
I replaced the (somewhat dumb) line

Code: Select all

if (num_moves == 0) return eval;
with

Code: Select all

if (b.is_check()) return eval;
and it seems to work. Should I be returning the static evaluation in this case, or alpha?
Quick and dirty solution:

Search:
If (!inCheck && depth <= 0) return QSearch(...)

QSearch:
if (inCheck) return Search(...)
Best Regards,
Karlo Balla Jr.

Post Reply