Skip to content

Commit

Permalink
fix: set LASTMOVE on null move pruning to prevent illegal moves
Browse files Browse the repository at this point in the history
  • Loading branch information
xjcl committed Dec 29, 2022
1 parent e8a4d6e commit a373322
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions jangine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -921,16 +921,21 @@ ValuePlusMove negamax(num COLOR, num alpha, num beta, num adaptive, bool is_quie
alpha = best.value;
}

Move LASTMOVE_BAK = LASTMOVE;

// TODO: when switching to bitboards, also check if a piece other than a pawn is still on the board
// TODO: Only one null move in entire search or just disallow 2 in a row?
// TODO: set LASTMOVE?
// Null Move Pruning
// maybe okay to do without as no duplicate moves possible and king will be captured instead
if (can_null_move && depth >= 1 && adaptive >= 3 && !king_in_check(COLOR))
{
PiecePlusCatling ppc = make_null_move();
LASTMOVE = {0};

ValuePlusMove rec = negamax(COLOR == WHITE ? BLACK : WHITE, -beta, -beta + 1, adaptive - 3, is_quies, false, depth + 1, lines, lines_accurate);

unmake_null_move(ppc.c_rights_w, ppc.c_rights_b);
LASTMOVE = LASTMOVE_BAK;

if (-rec.value >= beta)
return {beta, {0}};
Expand All @@ -944,7 +949,6 @@ ValuePlusMove negamax(num COLOR, num alpha, num beta, num adaptive, bool is_quie

num adaptive_new = 0;
num legal_moves_found = 0;
Move LASTMOVE_BAK = LASTMOVE;

num try_killer_move = -1;
num alpha_raised_n_times = 0;
Expand Down Expand Up @@ -1530,6 +1534,7 @@ int main(int argc, char const *argv[])
if (startswith("setboard", line)) {
std::string fen = line_cpp.substr(9);
board_from_fen(fen.c_str());
pprint();
}
/*** XBOARD END ***/

Expand Down

0 comments on commit a373322

Please sign in to comment.