X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;ds=sidebyside;f=src%2Fposition.cpp;h=1e416ef6bf776fa67d61480e1e227491926bd05f;hb=5f5d056c8fb9996748b742c9d5102c9202b0bd2c;hp=95195d3af47240dfed607c8a0bc6ddc127add1b8;hpb=b9bc6e823f061753419e563c4f923e60bd8c6193;p=stockfish diff --git a/src/position.cpp b/src/position.cpp index 95195d3a..1e416ef6 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -63,7 +63,7 @@ const Value PieceValueEndgame[17] = { }; // To convert a Piece to and from a FEN char -static const string PieceToChar(" PNBRQK pnbrqk ."); +static const string PieceToChar(" PNBRQK pnbrqk"); /// CheckInfo c'tor @@ -154,7 +154,7 @@ void Position::from_fen(const string& fenStr, bool isChess960, Thread* th) { sq += Square(token - '0'); // Advance the given number of files else if (token == '/') - sq = make_square(FILE_A, rank_of(sq) - Rank(2)); + sq -= Square(16); else if ((p = PieceToChar.find(token)) != string::npos) { @@ -187,7 +187,7 @@ void Position::from_fen(const string& fenStr, bool isChess960, Thread* th) { for (rsq = relative_square(c, SQ_A1); type_of(piece_on(rsq)) != ROOK; rsq++) {} else if (token >= 'A' && token <= 'H') - rsq = make_square(File(token - 'A'), relative_rank(c, RANK_1)); + rsq = File(token - 'A') | relative_rank(c, RANK_1); else continue; @@ -199,7 +199,7 @@ void Position::from_fen(const string& fenStr, bool isChess960, Thread* th) { if ( ((fen >> col) && (col >= 'a' && col <= 'h')) && ((fen >> row) && (row == '3' || row == '6'))) { - st->epSquare = make_square(File(col - 'a'), Rank(row - '1')); + st->epSquare = File(col - 'a') | Rank(row - '1'); if (!(attackers_to(st->epSquare) & pieces(sideToMove, PAWN))) st->epSquare = SQ_NONE; @@ -268,7 +268,7 @@ const string Position::to_fen() const { for (File file = FILE_A; file <= FILE_H; file++) { - sq = make_square(file, rank); + sq = file | rank; if (is_empty(sq)) emptyCnt++; @@ -319,7 +319,11 @@ const string Position::to_fen() const { void Position::print(Move move) const { - const char* dottedLine = "\n+---+---+---+---+---+---+---+---+\n"; + const string dottedLine = "\n+---+---+---+---+---+---+---+---+"; + const string twoRows = dottedLine + "\n| | . | | . | | . | | . |" + + dottedLine + "\n| . | | . | | . | | . | |"; + + string brd = twoRows + twoRows + twoRows + twoRows + dottedLine; if (move) { @@ -327,22 +331,11 @@ void Position::print(Move move) const { cout << "\nMove is: " << (sideToMove == BLACK ? ".." : "") << move_to_san(p, move); } - for (Rank rank = RANK_8; rank >= RANK_1; rank--) - { - cout << dottedLine << '|'; - for (File file = FILE_A; file <= FILE_H; file++) - { - Square sq = make_square(file, rank); - Piece piece = piece_on(sq); - char c = (color_of(piece) == BLACK ? '=' : ' '); - - if (piece == NO_PIECE && !opposite_colors(sq, SQ_A1)) - piece++; // Index the dot + for (Square sq = SQ_A1; sq <= SQ_H8; sq++) + if (piece_on(sq) != NO_PIECE) + brd[513 - 68*rank_of(sq) + 4*file_of(sq)] = PieceToChar[piece_on(sq)]; - cout << c << PieceToChar[piece] << c << '|'; - } - } - cout << dottedLine << "Fen is: " << to_fen() << "\nKey is: " << st->key << endl; + cout << brd << "\nFen is: " << to_fen() << "\nKey is: " << st->key << endl; } @@ -663,7 +656,7 @@ bool Position::move_gives_check(Move m, const CheckInfo& ci) const { // the captured pawn. if (is_enpassant(m)) { - Square capsq = make_square(file_of(to), rank_of(from)); + Square capsq = file_of(to) | rank_of(from); Bitboard b = (pieces() ^ from ^ capsq) | to; return (attacks_bb< ROOK>(ksq, b) & pieces(us, QUEEN, ROOK)) @@ -707,14 +700,6 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI // Copy some fields of old state to our new StateInfo object except the ones // which are recalculated from scratch anyway, then switch our state pointer // to point to the new, ready to be updated, state. - struct ReducedStateInfo { - Key pawnKey, materialKey; - Value npMaterial[2]; - int castleRights, rule50, pliesFromNull; - Score psq_score; - Square epSquare; - }; - memcpy(&newSt, st, sizeof(ReducedStateInfo)); newSt.previous = st;