X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fmovegen.cpp;h=efa47bd5b4f3df2142f94bf5da4a552567a00b64;hp=111895876459d0b9b67921ae305a57bc13b70748;hb=b96dd754ede60b8463606cf38eac3eab400a123d;hpb=e6310b3469b07b6bbecf8d8f75367a655090f22b diff --git a/src/movegen.cpp b/src/movegen.cpp index 11189587..efa47bd5 100644 --- a/src/movegen.cpp +++ b/src/movegen.cpp @@ -2,6 +2,7 @@ Stockfish, a UCI chess playing engine derived from Glaurung 2.1 Copyright (C) 2004-2008 Tord Romstad (Glaurung author) Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad + Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad Stockfish is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -25,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); @@ -56,17 +57,16 @@ namespace { Move m = make(kfrom, rfrom); - if (Checks && !pos.gives_check(m, *ci)) + if (Checks && !pos.gives_check(m)) return moveList; *moveList++ = m; - - return (void)ci, moveList; // Silence a warning under MSVC + return moveList; } 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); @@ -80,16 +80,17 @@ 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)ksq; // Silence a warning under MSVC - return (void)ci, moveList; // 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. @@ -125,16 +126,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; @@ -168,14 +172,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 @@ -221,7 +227,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); @@ -232,17 +238,17 @@ namespace { if (Checks) { if ( (Pt == BISHOP || Pt == ROOK || Pt == QUEEN) - && !(PseudoAttacks[Pt][from] & target & ci->checkSquares[Pt])) + && !(PseudoAttacks[Pt][from] & target & pos.check_squares(Pt))) continue; - if (ci->dcCandidates && (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_squares(Pt); while (b) *moveList++ = make_move(from, pop_lsb(&b)); @@ -253,16 +259,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) { @@ -276,13 +281,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); } } @@ -331,8 +336,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) { @@ -345,14 +349,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()); } @@ -407,7 +411,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;