Skip to content

Commit c272207

Browse files
Enhance doNullMove for en passant and add related tests (#45)
* Update doNullMove to handle en passant state * Add tests for move, null move, and undo move Reason for the bug: uninitialized diffs in entry --------- Co-authored-by: GitHub Actions <actions@github.com>
1 parent 68a650e commit c272207

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

position.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,13 @@ template <typename PieceC = EnginePiece, typename = std::enable_if_t<is_piece_en
182182

183183
inline void doNullMove() {
184184
history.push_back(current_state);
185+
current_state.incr_sqs[0] = current_state.incr_sqs[1] = current_state.incr_sqs[2] = current_state.incr_sqs[3] = SQ_NONE;
186+
current_state.incr_pc[0] = current_state.incr_pc[1] = current_state.incr_pc[2] = current_state.incr_pc[3] =
187+
PieceC::NO_PIECE;
188+
if (current_state.epIncluded)
189+
current_state.hash ^= zobrist::RandomEP[file_of(ep_square())];
190+
current_state.epIncluded = false;
191+
current_state.enPassant = SQ_NONE;
185192
current_state.turn = ~current_state.turn;
186193
current_state.hash ^= zobrist::RandomTurn;
187194
current_state.fullMoveNumber += (current_state.turn == WHITE);

tests.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,29 @@ TEST_CASE("Experienced bugs in this repo") {
402402
REQUIRE(p.zobrist() == p.hash());
403403
REQUIRE(p.hash() == 4177524090105507023);
404404
}
405+
{
406+
Position p;
407+
p.doMove<false>(Move(SQ_A2, SQ_A3));
408+
REQUIRE(p.zobrist() == p.hash());
409+
p.doMove<false>(Move(SQ_B8, SQ_A6));
410+
REQUIRE(p.zobrist() == p.hash());
411+
p.doMove<false>(Move(SQ_F2, SQ_F3));
412+
REQUIRE(p.zobrist() == p.hash());
413+
p.doMove<false>(Move(SQ_F7, SQ_F5));
414+
REQUIRE(p.zobrist() == p.hash());
415+
p.doNullMove();
416+
REQUIRE(p.zobrist() == p.hash());
417+
p.undoMove();
418+
REQUIRE(p.zobrist() == p.hash());
419+
p.undoMove();
420+
REQUIRE(p.zobrist() == p.hash());
421+
p.undoMove();
422+
REQUIRE(p.zobrist() == p.hash());
423+
p.undoMove();
424+
REQUIRE(p.zobrist() == p.hash());
425+
p.undoMove();
426+
REQUIRE(p.zobrist() == p.hash());
427+
}
405428
{
406429
Position p;
407430
REQUIRE(p.getCastlingPath(WHITE, true) == 0x60);

0 commit comments

Comments
 (0)