X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fposition.cpp;h=cc320b4b3e45d55aba64cbc2194f71795ba5d35f;hp=5f5bb5a6a0e1111a255b872c71c4d0409157f84a;hb=8b0fee9998e2ae530fa57e55f6cf145779aef3d0;hpb=5943600a890cef1e83235d08b248e686c95c77d1 diff --git a/src/position.cpp b/src/position.cpp index 5f5bb5a6..cc320b4b 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -1,7 +1,7 @@ /* Stockfish, a UCI chess playing engine derived from Glaurung 2.1 Copyright (C) 2004-2008 Tord Romstad (Glaurung author) - Copyright (C) 2008-2014 Marco Costalba, Joona Kiiski, Tord Romstad + Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, 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 @@ -19,7 +19,7 @@ #include #include -#include +#include // For std::memset #include #include @@ -47,7 +47,7 @@ namespace Zobrist { Key exclusion; } -Key Position::exclusion_key() const { return st->key ^ Zobrist::exclusion;} +Key Position::exclusion_key() const { return st->key ^ Zobrist::exclusion; } namespace { @@ -123,7 +123,7 @@ std::ostream& operator<<(std::ostream& os, const Position& pos) { << std::setfill('0') << std::setw(16) << pos.st->key << std::dec << "\nCheckers: "; for (Bitboard b = pos.checkers(); b; ) - os << UCI::format_square(pop_lsb(&b)) << " "; + os << UCI::square(pop_lsb(&b)) << " "; return os; } @@ -176,9 +176,8 @@ void Position::init() { } -/// Position::operator=() creates a copy of 'pos'. We want the new born Position -/// object to not depend on any external data so we detach state pointer from -/// the source one. +/// Position::operator=() creates a copy of 'pos' but detaching the state pointer +/// from the source to be self-consistent and not depending on any external data. Position& Position::operator=(const Position& pos) { @@ -444,7 +443,7 @@ const string Position::fen() const { if (!can_castle(WHITE) && !can_castle(BLACK)) ss << '-'; - ss << (ep_square() == SQ_NONE ? " - " : " " + UCI::format_square(ep_square()) + " ") + ss << (ep_square() == SQ_NONE ? " - " : " " + UCI::square(ep_square()) + " ") << st->rule50 << " " << 1 + (gamePly - (sideToMove == BLACK)) / 2; return ss.str(); @@ -642,7 +641,7 @@ bool Position::gives_check(Move m, const CheckInfo& ci) const { return true; // Is there a discovered check? - if ( unlikely(ci.dcCandidates) + if ( ci.dcCandidates && (ci.dcCandidates & from) && !aligned(from, to, ci.ksq)) return true; @@ -871,7 +870,7 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI st->checkersBB |= to; // Discovered checks - if (unlikely(ci.dcCandidates) && (ci.dcCandidates & from)) + if (ci.dcCandidates && (ci.dcCandidates & from)) { if (pt != ROOK) st->checkersBB |= attacks_from(king_square(them)) & pieces(us, QUEEN, ROOK); @@ -1061,8 +1060,8 @@ Value Position::see(Move m) const { stm = color_of(piece_on(from)); occupied = pieces() ^ from; - // Castling moves are implemented as king capturing the rook so cannot be - // handled correctly. Simply return 0 that is always the correct value + // Castling moves are implemented as king capturing the rook so cannot + // be handled correctly. Simply return VALUE_ZERO that is always correct // unless in the rare case the rook ends up under attack. if (type_of(m) == CASTLING) return VALUE_ZERO; @@ -1148,10 +1147,6 @@ bool Position::is_draw() const { /// Position::flip() flips position with the white and black sides reversed. This /// is only useful for debugging e.g. for finding evaluation symmetry bugs. -static char toggle_case(char c) { - return char(islower(c) ? toupper(c) : tolower(c)); -} - void Position::flip() { string f, token; @@ -1169,7 +1164,8 @@ void Position::flip() { ss >> token; // Castling availability f += token + " "; - std::transform(f.begin(), f.end(), f.begin(), toggle_case); + std::transform(f.begin(), f.end(), f.begin(), + [](char c) { return char(islower(c) ? toupper(c) : tolower(c)); }); ss >> token; // En passant square f += (token == "-" ? token : token.replace(1, 1, token[1] == '3' ? "6" : "3"));