X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fposition.cpp;h=01f51ed0c358b0de39264c54373b107183885b71;hp=7d0cde2146dc29e50a905f0090cf9378b1269943;hb=2c237da54647bb7526f3512bea183eb44919cdda;hpb=06eba14dc984dc793e959ff7a5de19e1a190112b diff --git a/src/position.cpp b/src/position.cpp index 7d0cde21..01f51ed0 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -52,6 +52,9 @@ namespace { const string PieceToChar(" PNBRQK pnbrqk"); +const Piece Pieces[] = { W_PAWN, W_KNIGHT, W_BISHOP, W_ROOK, W_QUEEN, W_KING, + B_PAWN, B_KNIGHT, B_BISHOP, B_ROOK, B_QUEEN, B_KING }; + // min_attacker() is a helper function used by see_ge() to locate the least // valuable attacker for the side to move, remove the attacker we just found // from the bitboards and scan for new X-ray attacks behind it. @@ -62,7 +65,7 @@ PieceType min_attacker(const Bitboard* bb, Square to, Bitboard stmAttackers, Bitboard b = stmAttackers & bb[Pt]; if (!b) - return min_attacker(bb, to, stmAttackers, occupied, attackers); + return min_attacker(bb, to, stmAttackers, occupied, attackers); occupied ^= b & ~(b - 1); @@ -474,7 +477,7 @@ Bitboard Position::slider_blockers(Bitboard sliders, Square s, Bitboard& pinners pinners = 0; // Snipers are sliders that attack 's' when a piece is removed - Bitboard snipers = ( (PseudoAttacks[ROOK ][s] & pieces(QUEEN, ROOK)) + Bitboard snipers = ( (PseudoAttacks[ ROOK][s] & pieces(QUEEN, ROOK)) | (PseudoAttacks[BISHOP][s] & pieces(QUEEN, BISHOP))) & sliders; while (snipers) @@ -501,7 +504,7 @@ Bitboard Position::attackers_to(Square s, Bitboard occupied) const { return (attacks_from(s, BLACK) & pieces(WHITE, PAWN)) | (attacks_from(s, WHITE) & pieces(BLACK, PAWN)) | (attacks_from(s) & pieces(KNIGHT)) - | (attacks_bb(s, occupied) & pieces(ROOK, QUEEN)) + | (attacks_bb< ROOK>(s, occupied) & pieces( ROOK, QUEEN)) | (attacks_bb(s, occupied) & pieces(BISHOP, QUEEN)) | (attacks_from(s) & pieces(KING)); } @@ -595,7 +598,7 @@ bool Position::pseudo_legal(const Move m) const { && empty(to - pawn_push(us)))) return false; } - else if (!(attacks_from(pc, from) & to)) + else if (!(attacks_from(type_of(pc), from) & to)) return false; // Evasions generator already takes care to avoid some kind of illegal moves @@ -648,7 +651,7 @@ bool Position::gives_check(Move m) const { return false; case PROMOTION: - return attacks_bb(Piece(promotion_type(m)), to, pieces() ^ from) & square(~sideToMove); + return attacks_bb(promotion_type(m), to, pieces() ^ from) & square(~sideToMove); // En passant capture with check? We have already handled the case // of direct checks and ordinary discovered check, so the only case we @@ -1097,10 +1100,10 @@ bool Position::is_draw(int ply) const { stp = stp->previous->previous; // At root position ply is 1, so return a draw score if a position - // repeats once earlier but after or at the root, or repeats twice - // strictly before the root. + // repeats once earlier but strictly after the root, or repeats twice + // before or at the root. if ( stp->key == st->key - && ++cnt + (ply - i > 0) == 2) + && ++cnt + (ply - 1 > i) == 2) return true; } @@ -1192,7 +1195,6 @@ bool Position::pos_is_ok(int* failedStep) const { } if (step == Lists) - { for (Piece pc : Pieces) { if (pieceCount[pc] != popcount(pieces(color_of(pc), type_of(pc)))) @@ -1202,9 +1204,6 @@ bool Position::pos_is_ok(int* failedStep) const { if (board[pieceList[pc][i]] != pc || index[pieceList[pc][i]] != i) return false; } - if (pieceCount[PAWN] > FILE_NB) - return false; - } if (step == Castling) for (Color c = WHITE; c <= BLACK; ++c)