X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fmovegen.cpp;h=3a69f8ab998885e18277b25960bf90e31cd5ed0b;hp=3622f18e84217b14b56a506bf4bdf2d91fc0754e;hb=805afcbf3d5db39c85b759232cfb99ab0a250311;hpb=4c5cbb1b14b283679e3e0096b7973c97b75088f3 diff --git a/src/movegen.cpp b/src/movegen.cpp index 3622f18e..3a69f8ab 100644 --- a/src/movegen.cpp +++ b/src/movegen.cpp @@ -26,7 +26,7 @@ namespace { template - ExtMove* generate_castling(const Position& pos, ExtMove* moveList, Color us, const CheckInfo* ci) { + ExtMove* generate_castling(const Position& pos, ExtMove* moveList, Color us) { static const bool KingSide = (Cr == WHITE_OO || Cr == BLACK_OO); @@ -57,10 +57,8 @@ namespace { Move m = make(kfrom, rfrom); - if (Checks && !pos.gives_check(m, *ci)) + if (Checks && !pos.gives_check(m)) return moveList; - else - (void)ci; // Silence a warning under MSVC *moveList++ = m; return moveList; @@ -68,7 +66,7 @@ namespace { template - ExtMove* make_promotions(ExtMove* moveList, Square to, const CheckInfo* ci) { + ExtMove* make_promotions(ExtMove* moveList, Square to, Square ksq) { if (Type == CAPTURES || Type == EVASIONS || Type == NON_EVASIONS) *moveList++ = make(to - Delta, to, QUEEN); @@ -82,18 +80,15 @@ namespace { // Knight promotion is the only promotion that can give a direct check // that's not already included in the queen promotion. - if (Type == QUIET_CHECKS && (StepAttacksBB[W_KNIGHT][to] & ci->ksq)) + if (Type == QUIET_CHECKS && (StepAttacksBB[W_KNIGHT][to] & ksq)) *moveList++ = make(to - Delta, to, KNIGHT); - else - (void)ci; // Silence a warning under MSVC return moveList; } template - ExtMove* generate_pawn_moves(const Position& pos, ExtMove* moveList, - Bitboard target, const CheckInfo* ci) { + ExtMove* generate_pawn_moves(const Position& pos, ExtMove* moveList, Bitboard target) { // Compute our parametrized parameters at compile time, named according to // the point of view of white side. @@ -129,16 +124,19 @@ namespace { if (Type == QUIET_CHECKS) { - b1 &= pos.attacks_from(ci->ksq, Them); - b2 &= pos.attacks_from(ci->ksq, Them); + Square ksq = pos.square(Them); + + b1 &= pos.attacks_from(ksq, Them); + b2 &= pos.attacks_from(ksq, Them); // Add pawn pushes which give discovered check. This is possible only // if the pawn is not on the same file as the enemy king, because we // don't generate captures. Note that a possible discovery check // promotion has been already generated amongst the captures. - if (pawnsNotOn7 & ci->dcCandidates) + Bitboard dcCandidates = pos.discovered_check_candidates(); + if (pawnsNotOn7 & dcCandidates) { - Bitboard dc1 = shift_bb(pawnsNotOn7 & ci->dcCandidates) & emptySquares & ~file_bb(ci->ksq); + Bitboard dc1 = shift_bb(pawnsNotOn7 & dcCandidates) & emptySquares & ~file_bb(ksq); Bitboard dc2 = shift_bb(dc1 & TRank3BB) & emptySquares; b1 |= dc1; @@ -172,14 +170,16 @@ namespace { Bitboard b2 = shift_bb(pawnsOn7) & enemies; Bitboard b3 = shift_bb(pawnsOn7) & emptySquares; + Square ksq = pos.square(Them); + while (b1) - moveList = make_promotions(moveList, pop_lsb(&b1), ci); + moveList = make_promotions(moveList, pop_lsb(&b1), ksq); while (b2) - moveList = make_promotions(moveList, pop_lsb(&b2), ci); + moveList = make_promotions(moveList, pop_lsb(&b2), ksq); while (b3) - moveList = make_promotions(moveList, pop_lsb(&b3), ci); + moveList = make_promotions(moveList, pop_lsb(&b3), ksq); } // Standard and en-passant captures @@ -225,7 +225,7 @@ namespace { template ExtMove* generate_moves(const Position& pos, ExtMove* moveList, Color us, - Bitboard target, const CheckInfo* ci) { + Bitboard target) { assert(Pt != KING && Pt != PAWN); @@ -236,17 +236,17 @@ namespace { if (Checks) { if ( (Pt == BISHOP || Pt == ROOK || Pt == QUEEN) - && !(PseudoAttacks[Pt][from] & target & ci->checkSquares[Pt])) + && !(PseudoAttacks[Pt][from] & target & pos.check_info().checkSquares[Pt])) continue; - if (ci->dcCandidates & from) + if (pos.discovered_check_candidates() & from) continue; } Bitboard b = pos.attacks_from(from) & target; if (Checks) - b &= ci->checkSquares[Pt]; + b &= pos.check_info().checkSquares[Pt]; while (b) *moveList++ = make_move(from, pop_lsb(&b)); @@ -257,16 +257,15 @@ namespace { template - ExtMove* generate_all(const Position& pos, ExtMove* moveList, Bitboard target, - const CheckInfo* ci = nullptr) { + ExtMove* generate_all(const Position& pos, ExtMove* moveList, Bitboard target) { const bool Checks = Type == QUIET_CHECKS; - moveList = generate_pawn_moves(pos, moveList, target, ci); - moveList = generate_moves(pos, moveList, Us, target, ci); - moveList = generate_moves(pos, moveList, Us, target, ci); - moveList = generate_moves< ROOK, Checks>(pos, moveList, Us, target, ci); - moveList = generate_moves< QUEEN, Checks>(pos, moveList, Us, target, ci); + moveList = generate_pawn_moves(pos, moveList, target); + moveList = generate_moves(pos, moveList, Us, target); + moveList = generate_moves(pos, moveList, Us, target); + moveList = generate_moves< ROOK, Checks>(pos, moveList, Us, target); + moveList = generate_moves< QUEEN, Checks>(pos, moveList, Us, target); if (Type != QUIET_CHECKS && Type != EVASIONS) { @@ -280,13 +279,13 @@ namespace { { if (pos.is_chess960()) { - moveList = generate_castling::right, Checks, true>(pos, moveList, Us, ci); - moveList = generate_castling::right, Checks, true>(pos, moveList, Us, ci); + moveList = generate_castling::right, Checks, true>(pos, moveList, Us); + moveList = generate_castling::right, Checks, true>(pos, moveList, Us); } else { - moveList = generate_castling::right, Checks, false>(pos, moveList, Us, ci); - moveList = generate_castling::right, Checks, false>(pos, moveList, Us, ci); + moveList = generate_castling::right, Checks, false>(pos, moveList, Us); + moveList = generate_castling::right, Checks, false>(pos, moveList, Us); } } @@ -335,8 +334,7 @@ ExtMove* generate(const Position& pos, ExtMove* moveList) { assert(!pos.checkers()); Color us = pos.side_to_move(); - CheckInfo ci(pos); - Bitboard dc = ci.dcCandidates; + Bitboard dc = pos.discovered_check_candidates(); while (dc) { @@ -349,14 +347,14 @@ ExtMove* generate(const Position& pos, ExtMove* moveList) { Bitboard b = pos.attacks_from(Piece(pt), from) & ~pos.pieces(); if (pt == KING) - b &= ~PseudoAttacks[QUEEN][ci.ksq]; + b &= ~PseudoAttacks[QUEEN][pos.square(~us)]; while (b) *moveList++ = make_move(from, pop_lsb(&b)); } - return us == WHITE ? generate_all(pos, moveList, ~pos.pieces(), &ci) - : generate_all(pos, moveList, ~pos.pieces(), &ci); + return us == WHITE ? generate_all(pos, moveList, ~pos.pieces()) + : generate_all(pos, moveList, ~pos.pieces()); } @@ -411,7 +409,7 @@ ExtMove* generate(const Position& pos, ExtMove* moveList) { : generate(pos, moveList); while (cur != moveList) if ( (pinned || from_sq(*cur) == ksq || type_of(*cur) == ENPASSANT) - && !pos.legal(*cur, pinned)) + && !pos.legal(*cur)) *cur = (--moveList)->move; else ++cur;