X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fmovegen.cpp;h=3a69f8ab998885e18277b25960bf90e31cd5ed0b;hp=51adc5b4c0296d60914c3d97f371ada9a657439b;hb=805afcbf3d5db39c85b759232cfb99ab0a250311;hpb=ee0371f86e319aa24bc1d32f02d9495eea79aa72 diff --git a/src/movegen.cpp b/src/movegen.cpp index 51adc5b4..3a69f8ab 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); @@ -34,7 +35,7 @@ namespace { // After castling, the rook and king final positions are the same in Chess960 // as they would be in standard chess. - Square kfrom = pos.king_square(us); + Square kfrom = pos.square(us); Square rfrom = pos.castling_rook_square(Cr); Square kto = relative_square(us, KingSide ? SQ_G1 : SQ_C1); Bitboard enemies = pos.pieces(~us); @@ -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,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); - 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 +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; @@ -168,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 @@ -221,28 +225,28 @@ namespace { template ExtMove* generate_moves(const Position& pos, ExtMove* moveList, Color us, - Bitboard target, const CheckInfo* ci) { + Bitboard target) { assert(Pt != KING && Pt != PAWN); - const Square* pl = pos.list(us); + const Square* pl = pos.squares(us); for (Square from = *pl; from != SQ_NONE; from = *++pl) { 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 && (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)); @@ -253,20 +257,19 @@ 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) { - Square ksq = pos.king_square(Us); + Square ksq = pos.square(Us); Bitboard b = pos.attacks_from(ksq) & target; while (b) *moveList++ = make_move(ksq, pop_lsb(&b)); @@ -276,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); } } @@ -331,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) { @@ -345,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()); } @@ -364,7 +366,7 @@ ExtMove* generate(const Position& pos, ExtMove* moveList) { assert(pos.checkers()); Color us = pos.side_to_move(); - Square ksq = pos.king_square(us); + Square ksq = pos.square(us); Bitboard sliderAttacks = 0; Bitboard sliders = pos.checkers() & ~pos.pieces(KNIGHT, PAWN); @@ -400,14 +402,14 @@ template<> ExtMove* generate(const Position& pos, ExtMove* moveList) { Bitboard pinned = pos.pinned_pieces(pos.side_to_move()); - Square ksq = pos.king_square(pos.side_to_move()); + Square ksq = pos.square(pos.side_to_move()); ExtMove* cur = moveList; moveList = pos.checkers() ? generate(pos, 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;