From: Marco Costalba Date: Sat, 23 Jun 2012 07:49:33 +0000 (+0100) Subject: Replace make_square() with operator|(File, Rank) X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=5f5d056c8fb9996748b742c9d5102c9202b0bd2c Replace make_square() with operator|(File, Rank) Be fancy :-) No functional change. Signed-off-by: Marco Costalba --- diff --git a/src/bitbase.cpp b/src/bitbase.cpp index ceb94a0f..9322e537 100644 --- a/src/bitbase.cpp +++ b/src/bitbase.cpp @@ -117,7 +117,7 @@ namespace { stm = Color(idx & 1); bksq = Square((idx >> 1) & 63); wksq = Square((idx >> 7) & 63); - psq = make_square(File((idx >> 13) & 3), Rank((idx >> 15) + 1)); + psq = File((idx >> 13) & 3) | Rank((idx >> 15) + 1); } Result KPKPosition::classify_leaf(int idx) { diff --git a/src/bitboard.cpp b/src/bitboard.cpp index 03080d15..08b43ad8 100644 --- a/src/bitboard.cpp +++ b/src/bitboard.cpp @@ -143,7 +143,7 @@ void Bitboards::print(Bitboard b) { std::cout << "+---+---+---+---+---+---+---+---+" << '\n'; for (File file = FILE_A; file <= FILE_H; file++) - std::cout << "| " << (b & make_square(file, rank) ? "X " : " "); + std::cout << "| " << (b & (file | rank) ? "X " : " "); std::cout << "|\n"; } diff --git a/src/endgame.cpp b/src/endgame.cpp index feaf59aa..f5f2074c 100644 --- a/src/endgame.cpp +++ b/src/endgame.cpp @@ -262,7 +262,7 @@ Value Endgame::operator()(const Position& pos) const { bpsq = ~bpsq; } - Square queeningSq = make_square(file_of(bpsq), RANK_1); + Square queeningSq = file_of(bpsq) | RANK_1; Value result; // If the stronger side's king is in front of the pawn, it's a win @@ -414,7 +414,7 @@ ScaleFactor Endgame::operator()(const Position& pos) const { && !(pawns & ~file_bb(pawnFile))) { Square bishopSq = pos.piece_list(strongerSide, BISHOP)[0]; - Square queeningSq = relative_square(strongerSide, make_square(pawnFile, RANK_8)); + Square queeningSq = relative_square(strongerSide, pawnFile | RANK_8); Square kingSq = pos.king_square(weakerSide); if ( opposite_colors(queeningSq, bishopSq) @@ -513,7 +513,7 @@ ScaleFactor Endgame::operator()(const Position& pos) const { File f = file_of(wpsq); Rank r = rank_of(wpsq); - Square queeningSq = make_square(f, RANK_8); + Square queeningSq = f | RANK_8; int tempo = (pos.side_to_move() == strongerSide); // If the pawn is not too far advanced and the defending king defends the @@ -752,12 +752,12 @@ ScaleFactor Endgame::operator()(const Position& pos) const { if (relative_rank(strongerSide, psq1) > relative_rank(strongerSide, psq2)) { blockSq1 = psq1 + pawn_push(strongerSide); - blockSq2 = make_square(file_of(psq2), rank_of(psq1)); + blockSq2 = file_of(psq2) | rank_of(psq1); } else { blockSq1 = psq2 + pawn_push(strongerSide); - blockSq2 = make_square(file_of(psq1), rank_of(psq2)); + blockSq2 = file_of(psq1) | rank_of(psq2); } switch (file_distance(psq1, psq2)) diff --git a/src/evaluate.cpp b/src/evaluate.cpp index 8a5b6618..02ca6d35 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -977,7 +977,7 @@ Value do_evaluate(const Position& pos, Value& margin) { while (b) { s = pop_1st_bit(&b); - queeningSquare = relative_square(c, make_square(file_of(s), RANK_8)); + queeningSquare = relative_square(c, file_of(s) | RANK_8); queeningPath = forward_bb(c, s); // Compute plies to queening and check direct advancement @@ -1020,7 +1020,7 @@ Value do_evaluate(const Position& pos, Value& margin) { s = pop_1st_bit(&b); // Compute plies from queening - queeningSquare = relative_square(loserSide, make_square(file_of(s), RANK_8)); + queeningSquare = relative_square(loserSide, file_of(s) | RANK_8); movesToGo = rank_distance(s, queeningSquare) - int(relative_rank(loserSide, s) == RANK_2); pliesToGo = 2 * movesToGo - int(loserSide == pos.side_to_move()); @@ -1044,7 +1044,7 @@ Value do_evaluate(const Position& pos, Value& margin) { minKingDist = kingptg = 256; // Compute plies from queening - queeningSquare = relative_square(loserSide, make_square(file_of(s), RANK_8)); + queeningSquare = relative_square(loserSide, file_of(s) | RANK_8); movesToGo = rank_distance(s, queeningSquare) - int(relative_rank(loserSide, s) == RANK_2); pliesToGo = 2 * movesToGo - int(loserSide == pos.side_to_move()); diff --git a/src/move.cpp b/src/move.cpp index 41d16037..8ea6ad52 100644 --- a/src/move.cpp +++ b/src/move.cpp @@ -43,7 +43,7 @@ const string move_to_uci(Move m, bool chess960) { return "0000"; if (is_castle(m) && !chess960) - to = make_square(to > from ? FILE_G : FILE_C, rank_of(from)); + to = (to > from ? FILE_G : FILE_C) | rank_of(from); if (is_promotion(m)) promotion = char(tolower(piece_type_to_char(promotion_type(m)))); @@ -89,7 +89,7 @@ const string move_to_san(Position& pos, Move m) { PieceType pt = type_of(pos.piece_on(from)); if (is_castle(m)) - san = to_sq(m) < from_sq(m) ? "O-O-O" : "O-O"; + san = to > from ? "O-O" : "O-O-O"; else { if (pt != PAWN) diff --git a/src/position.cpp b/src/position.cpp index c26ab1b6..1e416ef6 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -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++; @@ -656,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)) diff --git a/src/types.h b/src/types.h index 40a2baa0..4a78cc81 100644 --- a/src/types.h +++ b/src/types.h @@ -335,6 +335,10 @@ inline Square operator~(Square s) { return Square(s ^ 56); // Vertical flip SQ_A1 -> SQ_A8 } +inline Square operator|(File f, Rank r) { + return Square((r << 3) | f); +} + inline Value mate_in(int ply) { return VALUE_MATE - ply; } @@ -359,10 +363,6 @@ inline Color color_of(Piece p) { return Color(p >> 3); } -inline Square make_square(File f, Rank r) { - return Square((r << 3) | f); -} - inline bool is_ok(Square s) { return s >= SQ_A1 && s <= SQ_H8; }