X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fposition.cpp;h=d2aeb8221209ad391e54480e6442444d91d19749;hb=e6c9ce635819957bce641a432b0675c5c033631b;hp=6a5a577738393fafaf65dc47e7af54d2f8ff8a78;hpb=13a73f67c018e58b2fd46f886c45ef2b75188c8e;p=stockfish diff --git a/src/position.cpp b/src/position.cpp index 6a5a5777..d2aeb822 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -56,7 +56,7 @@ Key Position::exclusion_key() const { return st->key ^ Zobrist::exclusion;} namespace { -// min_attacker() is an helper function used by see() to locate the least +// min_attacker() is a helper function used by see() 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. @@ -211,7 +211,7 @@ void Position::set(const string& fenStr, bool isChess960, Thread* th) { */ char col, row, token; - size_t p; + size_t idx; Square sq = SQ_A8; std::istringstream ss(fenStr); @@ -227,9 +227,9 @@ void Position::set(const string& fenStr, bool isChess960, Thread* th) { else if (token == '/') sq -= Square(16); - else if ((p = PieceToChar.find(token)) != string::npos) + else if ((idx = PieceToChar.find(token)) != string::npos) { - put_piece(sq, color_of(Piece(p)), type_of(Piece(p))); + put_piece(sq, color_of(Piece(idx)), type_of(Piece(idx))); ++sq; } } @@ -297,7 +297,7 @@ void Position::set(const string& fenStr, bool isChess960, Thread* th) { } -/// Position::set_castling_flag() is an helper function used to set castling +/// Position::set_castling_flag() is a helper function used to set castling /// flags given the corresponding color and the rook starting square. void Position::set_castling_flag(Color c, Square rfrom) { @@ -329,25 +329,21 @@ void Position::set_castling_flag(Color c, Square rfrom) { const string Position::fen() const { + int emptyCnt; std::ostringstream ss; for (Rank rank = RANK_8; rank >= RANK_1; --rank) { for (File file = FILE_A; file <= FILE_H; ++file) { - Square sq = file | rank; - - if (empty(sq)) - { - int emptyCnt = 1; - - for ( ; file < FILE_H && empty(++sq); ++file) - ++emptyCnt; + for (emptyCnt = 0; file <= FILE_H && empty(file | rank); ++file) + ++emptyCnt; + if (emptyCnt) ss << emptyCnt; - } - else - ss << PieceToChar[piece_on(sq)]; + + if (file <= FILE_H) + ss << PieceToChar[piece_on(file | rank)]; } if (rank > RANK_1) @@ -368,11 +364,11 @@ const string Position::fen() const { if (can_castle(BLACK_OOO)) ss << (chess960 ? file_to_char(file_of(castling_rook_square(BLACK, QUEEN_SIDE)), true) : 'q'); - if (st->castlingFlags == NO_CASTLING) + if (!can_castle(WHITE) && !can_castle(BLACK)) ss << '-'; ss << (ep_square() == SQ_NONE ? " - " : " " + square_to_string(ep_square()) + " ") - << st->rule50 << " " << 1 + (gamePly - int(sideToMove == BLACK)) / 2; + << st->rule50 << " " << 1 + (gamePly - int(sideToMove == BLACK)) / 2; return ss.str(); } @@ -415,9 +411,9 @@ const string Position::pretty(Move move) const { } -/// Position:hidden_checkers() returns a bitboard of all pinned / discovery check +/// Position:hidden_checkers() returns a bitboard of all pinned / discovered check /// pieces, according to the call parameters. Pinned pieces protect our king and -/// discovery check pieces attack the enemy king. +/// discovered check pieces attack the enemy king. Bitboard Position::hidden_checkers(Square ksq, Color c, Color toMove) const { @@ -536,7 +532,7 @@ bool Position::pseudo_legal(const Move m) const { return false; // We have already handled promotion moves, so destination - // cannot be on the 8/1th rank. + // cannot be on the 8th/1st rank. if (rank_of(to) == RANK_8 || rank_of(to) == RANK_1) return false; @@ -873,7 +869,7 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI if (ci.checkSq[pt] & to) st->checkersBB |= to; - // Discovery checks + // Discovered checks if (ci.dcCandidates && (ci.dcCandidates & from)) { if (pt != ROOK)