mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 16:53:09 +00:00
Replace make_square() with operator|(File, Rank)
Be fancy :-) No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
9c7e2c8f9d
commit
5f5d056c8f
7 changed files with 20 additions and 20 deletions
|
@ -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) {
|
||||
|
|
|
@ -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";
|
||||
}
|
||||
|
|
|
@ -262,7 +262,7 @@ Value Endgame<KRKP>::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<KBPsK>::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<KRPKR>::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<KBPPKB>::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))
|
||||
|
|
|
@ -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());
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue