From: Marco Costalba Date: Sat, 22 Mar 2014 22:35:30 +0000 (+0100) Subject: Retire operator|(File f, Rank r) X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=5f12069cbfc882fdf989d04618ad9c33e603c419 Retire operator|(File f, Rank r) Use make_square() instead. Less fancy but more clear. No functional change. --- diff --git a/src/bitbase.cpp b/src/bitbase.cpp index cd6a7329..b73b72c4 100644 --- a/src/bitbase.cpp +++ b/src/bitbase.cpp @@ -110,7 +110,7 @@ namespace { wksq = Square((idx >> 0) & 0x3F); bksq = Square((idx >> 6) & 0x3F); us = Color ((idx >> 12) & 0x01); - psq = File ((idx >> 13) & 0x03) | Rank(RANK_7 - (idx >> 15)); + psq = make_square(File((idx >> 13) & 0x03), Rank(RANK_7 - (idx >> 15))); result = UNKNOWN; // Check if two pieces are on the same square or if a king can be captured diff --git a/src/endgame.cpp b/src/endgame.cpp index 572c160d..94967c25 100644 --- a/src/endgame.cpp +++ b/src/endgame.cpp @@ -240,7 +240,7 @@ Value Endgame::operator()(const Position& pos) const { Square rsq = relative_square(strongSide, pos.list(strongSide)[0]); Square psq = relative_square(strongSide, pos.list(weakSide)[0]); - Square queeningSq = file_of(psq) | RANK_1; + Square queeningSq = make_square(file_of(psq), RANK_1); Value result; // If the stronger side's king is in front of the pawn, it's a win @@ -371,7 +371,7 @@ ScaleFactor Endgame::operator()(const Position& pos) const { && !(pawns & ~file_bb(pawnFile))) { Square bishopSq = pos.list(strongSide)[0]; - Square queeningSq = relative_square(strongSide, pawnFile | RANK_8); + Square queeningSq = relative_square(strongSide, make_square(pawnFile, RANK_8)); Square kingSq = pos.king_square(weakSide); if ( opposite_colors(queeningSq, bishopSq) @@ -463,7 +463,7 @@ ScaleFactor Endgame::operator()(const Position& pos) const { File f = file_of(wpsq); Rank r = rank_of(wpsq); - Square queeningSq = f | RANK_8; + Square queeningSq = make_square(f, RANK_8); int tempo = (pos.side_to_move() == strongSide); // If the pawn is not too far advanced and the defending king defends the @@ -721,12 +721,12 @@ ScaleFactor Endgame::operator()(const Position& pos) const { if (relative_rank(strongSide, psq1) > relative_rank(strongSide, psq2)) { blockSq1 = psq1 + pawn_push(strongSide); - blockSq2 = file_of(psq2) | rank_of(psq1); + blockSq2 = make_square(file_of(psq2), rank_of(psq1)); } else { blockSq1 = psq2 + pawn_push(strongSide); - blockSq2 = file_of(psq1) | rank_of(psq2); + blockSq2 = make_square(file_of(psq1), rank_of(psq2)); } switch (file_distance(psq1, psq2)) diff --git a/src/notation.cpp b/src/notation.cpp index 3ca43deb..c74346c0 100644 --- a/src/notation.cpp +++ b/src/notation.cpp @@ -70,7 +70,7 @@ const string move_to_uci(Move m, bool chess960) { return "0000"; if (type_of(m) == CASTLING && !chess960) - to = (to > from ? FILE_G : FILE_C) | rank_of(from); + to = make_square(to > from ? FILE_G : FILE_C, rank_of(from)); string move = to_string(from) + to_string(to); diff --git a/src/pawns.cpp b/src/pawns.cpp index 88c63ce3..89911e50 100644 --- a/src/pawns.cpp +++ b/src/pawns.cpp @@ -257,7 +257,7 @@ Value Entry::shelter_storm(const Position& pos, Square ksq) { b = theirPawns & file_bb(f); rkThem = b ? relative_rank(Us, frontmost_sq(Them, b)) : RANK_1; - if ( (MiddleEdges & (f | rkThem)) + if ( (MiddleEdges & make_square(f, rkThem)) && file_of(ksq) == f && relative_rank(Us, ksq) == rkThem - 1) safety += Value(200); diff --git a/src/position.cpp b/src/position.cpp index b89c645f..788a2207 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -274,7 +274,7 @@ void Position::set(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 = File(token - 'A') | relative_rank(c, RANK_1); + rsq = make_square(File(token - 'A'), relative_rank(c, RANK_1)); else continue; @@ -286,7 +286,7 @@ void Position::set(const string& fenStr, bool isChess960, Thread* th) { if ( ((ss >> col) && (col >= 'a' && col <= 'h')) && ((ss >> row) && (row == '3' || row == '6'))) { - st->epSquare = File(col - 'a') | Rank(row - '1'); + st->epSquare = make_square(File(col - 'a'), Rank(row - '1')); if (!(attackers_to(st->epSquare) & pieces(sideToMove, PAWN))) st->epSquare = SQ_NONE; @@ -392,14 +392,14 @@ const string Position::fen() const { { for (File file = FILE_A; file <= FILE_H; ++file) { - for (emptyCnt = 0; file <= FILE_H && empty(file | rank); ++file) + for (emptyCnt = 0; file <= FILE_H && empty(make_square(file, rank)); ++file) ++emptyCnt; if (emptyCnt) ss << emptyCnt; if (file <= FILE_H) - ss << PieceToChar[piece_on(file | rank)]; + ss << PieceToChar[piece_on(make_square(file, rank))]; } if (rank > RANK_1) @@ -664,7 +664,7 @@ bool Position::gives_check(Move m, const CheckInfo& ci) const { // the captured pawn. case ENPASSANT: { - Square capsq = file_of(to) | rank_of(from); + Square capsq = make_square(file_of(to), rank_of(from)); Bitboard b = (pieces() ^ from ^ capsq) | to; return (attacks_bb< ROOK>(ci.ksq, b) & pieces(sideToMove, QUEEN, ROOK)) diff --git a/src/types.h b/src/types.h index 5002ece8..812a3700 100644 --- a/src/types.h +++ b/src/types.h @@ -337,10 +337,6 @@ inline Square operator~(Square s) { return Square(s ^ SQ_A8); // Vertical flip SQ_A1 -> SQ_A8 } -inline Square operator|(File f, Rank r) { - return Square((r << 3) | f); -} - inline CastlingRight operator|(Color c, CastlingSide s) { return CastlingRight(WHITE_OO << ((s == QUEEN_SIDE) + 2 * c)); } @@ -353,6 +349,10 @@ inline Value mated_in(int ply) { return -VALUE_MATE + ply; } +inline Square make_square(File f, Rank r) { + return Square((r << 3) | f); +} + inline Piece make_piece(Color c, PieceType pt) { return Piece((c << 3) | pt); }