mirror of
https://github.com/sockspls/badfish
synced 2025-04-29 16:23:09 +00:00
Better naming borrowed from Critter
In line with http://chessprogramming.wikispaces.com conventions. No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
25b4d0c127
commit
c2c185423b
16 changed files with 213 additions and 214 deletions
|
@ -104,9 +104,9 @@ namespace {
|
||||||
|
|
||||||
int compute_index(Square wksq, Square bksq, Square wpsq, Color stm) {
|
int compute_index(Square wksq, Square bksq, Square wpsq, Color stm) {
|
||||||
|
|
||||||
assert(square_file(wpsq) <= FILE_D);
|
assert(file_of(wpsq) <= FILE_D);
|
||||||
|
|
||||||
int p = square_file(wpsq) + 4 * (square_rank(wpsq) - 1);
|
int p = file_of(wpsq) + 4 * (rank_of(wpsq) - 1);
|
||||||
int r = stm + 2 * bksq + 128 * wksq + 8192 * p;
|
int r = stm + 2 * bksq + 128 * wksq + 8192 * p;
|
||||||
|
|
||||||
assert(r >= 0 && r < IndexMax);
|
assert(r >= 0 && r < IndexMax);
|
||||||
|
@ -140,7 +140,7 @@ namespace {
|
||||||
|
|
||||||
// The position is an immediate win if it is white to move and the
|
// The position is an immediate win if it is white to move and the
|
||||||
// white pawn can be promoted without getting captured.
|
// white pawn can be promoted without getting captured.
|
||||||
if ( square_rank(pawnSquare) == RANK_7
|
if ( rank_of(pawnSquare) == RANK_7
|
||||||
&& sideToMove == WHITE
|
&& sideToMove == WHITE
|
||||||
&& whiteKingSquare != pawnSquare + DELTA_N
|
&& whiteKingSquare != pawnSquare + DELTA_N
|
||||||
&& ( square_distance(blackKingSquare, pawnSquare + DELTA_N) > 1
|
&& ( square_distance(blackKingSquare, pawnSquare + DELTA_N) > 1
|
||||||
|
@ -161,19 +161,19 @@ namespace {
|
||||||
|
|
||||||
// Case 3: Black king in front of white pawn
|
// Case 3: Black king in front of white pawn
|
||||||
if ( blackKingSquare == pawnSquare + DELTA_N
|
if ( blackKingSquare == pawnSquare + DELTA_N
|
||||||
&& square_rank(pawnSquare) < RANK_7)
|
&& rank_of(pawnSquare) < RANK_7)
|
||||||
return RESULT_DRAW;
|
return RESULT_DRAW;
|
||||||
|
|
||||||
// Case 4: White king in front of pawn and black has opposition
|
// Case 4: White king in front of pawn and black has opposition
|
||||||
if ( whiteKingSquare == pawnSquare + DELTA_N
|
if ( whiteKingSquare == pawnSquare + DELTA_N
|
||||||
&& blackKingSquare == pawnSquare + DELTA_N + DELTA_N + DELTA_N
|
&& blackKingSquare == pawnSquare + DELTA_N + DELTA_N + DELTA_N
|
||||||
&& square_rank(pawnSquare) < RANK_5
|
&& rank_of(pawnSquare) < RANK_5
|
||||||
&& sideToMove == WHITE)
|
&& sideToMove == WHITE)
|
||||||
return RESULT_DRAW;
|
return RESULT_DRAW;
|
||||||
|
|
||||||
// Case 5: Stalemate with rook pawn
|
// Case 5: Stalemate with rook pawn
|
||||||
if ( blackKingSquare == SQ_A8
|
if ( blackKingSquare == SQ_A8
|
||||||
&& square_file(pawnSquare) == FILE_A)
|
&& file_of(pawnSquare) == FILE_A)
|
||||||
return RESULT_DRAW;
|
return RESULT_DRAW;
|
||||||
|
|
||||||
return RESULT_UNKNOWN;
|
return RESULT_UNKNOWN;
|
||||||
|
@ -213,7 +213,7 @@ namespace {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pawn moves
|
// Pawn moves
|
||||||
if (square_rank(pawnSquare) < RANK_7)
|
if (rank_of(pawnSquare) < RANK_7)
|
||||||
{
|
{
|
||||||
s = pawnSquare + DELTA_N;
|
s = pawnSquare + DELTA_N;
|
||||||
r = db[compute_index(whiteKingSquare, blackKingSquare, s, BLACK)];
|
r = db[compute_index(whiteKingSquare, blackKingSquare, s, BLACK)];
|
||||||
|
@ -225,7 +225,7 @@ namespace {
|
||||||
unknownFound = true;
|
unknownFound = true;
|
||||||
|
|
||||||
// Double pawn push
|
// Double pawn push
|
||||||
if (square_rank(s) == RANK_3 && r != RESULT_INVALID)
|
if (rank_of(s) == RANK_3 && r != RESULT_INVALID)
|
||||||
{
|
{
|
||||||
s += DELTA_N;
|
s += DELTA_N;
|
||||||
r = db[compute_index(whiteKingSquare, blackKingSquare, s, BLACK)];
|
r = db[compute_index(whiteKingSquare, blackKingSquare, s, BLACK)];
|
||||||
|
|
|
@ -325,7 +325,7 @@ namespace {
|
||||||
} while (b);
|
} while (b);
|
||||||
|
|
||||||
offset += maxKey;
|
offset += maxKey;
|
||||||
booster = MagicBoosters[CpuIs64Bit][square_rank(s)];
|
booster = MagicBoosters[CpuIs64Bit][rank_of(s)];
|
||||||
|
|
||||||
// Then find a possible magic and the corresponding attacks
|
// Then find a possible magic and the corresponding attacks
|
||||||
do {
|
do {
|
||||||
|
|
|
@ -113,7 +113,7 @@ inline Bitboard rank_bb(Rank r) {
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard rank_bb(Square s) {
|
inline Bitboard rank_bb(Square s) {
|
||||||
return RankBB[square_rank(s)];
|
return RankBB[rank_of(s)];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard file_bb(File f) {
|
inline Bitboard file_bb(File f) {
|
||||||
|
@ -121,7 +121,7 @@ inline Bitboard file_bb(File f) {
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard file_bb(Square s) {
|
inline Bitboard file_bb(Square s) {
|
||||||
return FileBB[square_file(s)];
|
return FileBB[file_of(s)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -133,7 +133,7 @@ inline Bitboard neighboring_files_bb(File f) {
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard neighboring_files_bb(Square s) {
|
inline Bitboard neighboring_files_bb(Square s) {
|
||||||
return NeighboringFilesBB[square_file(s)];
|
return NeighboringFilesBB[file_of(s)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -145,7 +145,7 @@ inline Bitboard this_and_neighboring_files_bb(File f) {
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard this_and_neighboring_files_bb(Square s) {
|
inline Bitboard this_and_neighboring_files_bb(Square s) {
|
||||||
return ThisAndNeighboringFilesBB[square_file(s)];
|
return ThisAndNeighboringFilesBB[file_of(s)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -160,7 +160,7 @@ inline Bitboard in_front_bb(Color c, Rank r) {
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Bitboard in_front_bb(Color c, Square s) {
|
inline Bitboard in_front_bb(Color c, Square s) {
|
||||||
return InFrontBB[c][square_rank(s)];
|
return InFrontBB[c][rank_of(s)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -335,7 +335,7 @@ namespace {
|
||||||
result ^= ZobCastle[3];
|
result ^= ZobCastle[3];
|
||||||
|
|
||||||
if (pos.ep_square() != SQ_NONE)
|
if (pos.ep_square() != SQ_NONE)
|
||||||
result ^= ZobEnPassant[square_file(pos.ep_square())];
|
result ^= ZobEnPassant[file_of(pos.ep_square())];
|
||||||
|
|
||||||
if (pos.side_to_move() == WHITE)
|
if (pos.side_to_move() == WHITE)
|
||||||
result ^= ZobTurn[0];
|
result ^= ZobTurn[0];
|
||||||
|
|
126
src/endgame.cpp
126
src/endgame.cpp
|
@ -189,8 +189,8 @@ Value Endgame<KBNK>::apply(const Position& pos) const {
|
||||||
// mirror the kings so to drive enemy toward corners A8 or H1.
|
// mirror the kings so to drive enemy toward corners A8 or H1.
|
||||||
if (opposite_color_squares(bishopSquare, SQ_A1))
|
if (opposite_color_squares(bishopSquare, SQ_A1))
|
||||||
{
|
{
|
||||||
winnerKSq = flop_square(winnerKSq);
|
winnerKSq = mirror(winnerKSq);
|
||||||
loserKSq = flop_square(loserKSq);
|
loserKSq = mirror(loserKSq);
|
||||||
}
|
}
|
||||||
|
|
||||||
Value result = VALUE_KNOWN_WIN
|
Value result = VALUE_KNOWN_WIN
|
||||||
|
@ -222,17 +222,17 @@ Value Endgame<KPK>::apply(const Position& pos) const {
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
wksq = flip_square(pos.king_square(BLACK));
|
wksq = flip(pos.king_square(BLACK));
|
||||||
bksq = flip_square(pos.king_square(WHITE));
|
bksq = flip(pos.king_square(WHITE));
|
||||||
wpsq = flip_square(pos.piece_list(BLACK, PAWN)[0]);
|
wpsq = flip(pos.piece_list(BLACK, PAWN)[0]);
|
||||||
stm = opposite_color(pos.side_to_move());
|
stm = flip(pos.side_to_move());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (square_file(wpsq) >= FILE_E)
|
if (file_of(wpsq) >= FILE_E)
|
||||||
{
|
{
|
||||||
wksq = flop_square(wksq);
|
wksq = mirror(wksq);
|
||||||
bksq = flop_square(bksq);
|
bksq = mirror(bksq);
|
||||||
wpsq = flop_square(wpsq);
|
wpsq = mirror(wpsq);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!probe_kpk_bitbase(wksq, wpsq, bksq, stm))
|
if (!probe_kpk_bitbase(wksq, wpsq, bksq, stm))
|
||||||
|
@ -240,7 +240,7 @@ Value Endgame<KPK>::apply(const Position& pos) const {
|
||||||
|
|
||||||
Value result = VALUE_KNOWN_WIN
|
Value result = VALUE_KNOWN_WIN
|
||||||
+ PawnValueEndgame
|
+ PawnValueEndgame
|
||||||
+ Value(square_rank(wpsq));
|
+ Value(rank_of(wpsq));
|
||||||
|
|
||||||
return strongerSide == pos.side_to_move() ? result : -result;
|
return strongerSide == pos.side_to_move() ? result : -result;
|
||||||
}
|
}
|
||||||
|
@ -268,17 +268,17 @@ Value Endgame<KRKP>::apply(const Position& pos) const {
|
||||||
|
|
||||||
if (strongerSide == BLACK)
|
if (strongerSide == BLACK)
|
||||||
{
|
{
|
||||||
wksq = flip_square(wksq);
|
wksq = flip(wksq);
|
||||||
wrsq = flip_square(wrsq);
|
wrsq = flip(wrsq);
|
||||||
bksq = flip_square(bksq);
|
bksq = flip(bksq);
|
||||||
bpsq = flip_square(bpsq);
|
bpsq = flip(bpsq);
|
||||||
}
|
}
|
||||||
|
|
||||||
Square queeningSq = make_square(square_file(bpsq), RANK_1);
|
Square queeningSq = make_square(file_of(bpsq), RANK_1);
|
||||||
Value result;
|
Value result;
|
||||||
|
|
||||||
// If the stronger side's king is in front of the pawn, it's a win
|
// If the stronger side's king is in front of the pawn, it's a win
|
||||||
if (wksq < bpsq && square_file(wksq) == square_file(bpsq))
|
if (wksq < bpsq && file_of(wksq) == file_of(bpsq))
|
||||||
result = RookValueEndgame - Value(square_distance(wksq, bpsq));
|
result = RookValueEndgame - Value(square_distance(wksq, bpsq));
|
||||||
|
|
||||||
// If the weaker side's king is too far from the pawn and the rook,
|
// If the weaker side's king is too far from the pawn and the rook,
|
||||||
|
@ -289,9 +289,9 @@ Value Endgame<KRKP>::apply(const Position& pos) const {
|
||||||
|
|
||||||
// If the pawn is far advanced and supported by the defending king,
|
// If the pawn is far advanced and supported by the defending king,
|
||||||
// the position is drawish
|
// the position is drawish
|
||||||
else if ( square_rank(bksq) <= RANK_3
|
else if ( rank_of(bksq) <= RANK_3
|
||||||
&& square_distance(bksq, bpsq) == 1
|
&& square_distance(bksq, bpsq) == 1
|
||||||
&& square_rank(wksq) >= RANK_4
|
&& rank_of(wksq) >= RANK_4
|
||||||
&& square_distance(wksq, bpsq) - tempo > 2)
|
&& square_distance(wksq, bpsq) - tempo > 2)
|
||||||
result = Value(80 - square_distance(wksq, bpsq) * 8);
|
result = Value(80 - square_distance(wksq, bpsq) * 8);
|
||||||
|
|
||||||
|
@ -423,7 +423,7 @@ ScaleFactor Endgame<KBPsK>::apply(const Position& pos) const {
|
||||||
// be detected even when the weaker side has some pawns.
|
// be detected even when the weaker side has some pawns.
|
||||||
|
|
||||||
Bitboard pawns = pos.pieces(PAWN, strongerSide);
|
Bitboard pawns = pos.pieces(PAWN, strongerSide);
|
||||||
File pawnFile = square_file(pos.piece_list(strongerSide, PAWN)[0]);
|
File pawnFile = file_of(pos.piece_list(strongerSide, PAWN)[0]);
|
||||||
|
|
||||||
// All pawns are on a single rook file ?
|
// All pawns are on a single rook file ?
|
||||||
if ( (pawnFile == FILE_A || pawnFile == FILE_H)
|
if ( (pawnFile == FILE_A || pawnFile == FILE_H)
|
||||||
|
@ -434,7 +434,7 @@ ScaleFactor Endgame<KBPsK>::apply(const Position& pos) const {
|
||||||
Square kingSq = pos.king_square(weakerSide);
|
Square kingSq = pos.king_square(weakerSide);
|
||||||
|
|
||||||
if ( opposite_color_squares(queeningSq, bishopSq)
|
if ( opposite_color_squares(queeningSq, bishopSq)
|
||||||
&& abs(square_file(kingSq) - pawnFile) <= 1)
|
&& abs(file_of(kingSq) - pawnFile) <= 1)
|
||||||
{
|
{
|
||||||
// The bishop has the wrong color, and the defending king is on the
|
// The bishop has the wrong color, and the defending king is on the
|
||||||
// file of the pawn(s) or the neighboring file. Find the rank of the
|
// file of the pawn(s) or the neighboring file. Find the rank of the
|
||||||
|
@ -515,23 +515,23 @@ ScaleFactor Endgame<KRPKR>::apply(const Position& pos) const {
|
||||||
// pawn is on the left half of the board.
|
// pawn is on the left half of the board.
|
||||||
if (strongerSide == BLACK)
|
if (strongerSide == BLACK)
|
||||||
{
|
{
|
||||||
wksq = flip_square(wksq);
|
wksq = flip(wksq);
|
||||||
wrsq = flip_square(wrsq);
|
wrsq = flip(wrsq);
|
||||||
wpsq = flip_square(wpsq);
|
wpsq = flip(wpsq);
|
||||||
bksq = flip_square(bksq);
|
bksq = flip(bksq);
|
||||||
brsq = flip_square(brsq);
|
brsq = flip(brsq);
|
||||||
}
|
}
|
||||||
if (square_file(wpsq) > FILE_D)
|
if (file_of(wpsq) > FILE_D)
|
||||||
{
|
{
|
||||||
wksq = flop_square(wksq);
|
wksq = mirror(wksq);
|
||||||
wrsq = flop_square(wrsq);
|
wrsq = mirror(wrsq);
|
||||||
wpsq = flop_square(wpsq);
|
wpsq = mirror(wpsq);
|
||||||
bksq = flop_square(bksq);
|
bksq = mirror(bksq);
|
||||||
brsq = flop_square(brsq);
|
brsq = mirror(brsq);
|
||||||
}
|
}
|
||||||
|
|
||||||
File f = square_file(wpsq);
|
File f = file_of(wpsq);
|
||||||
Rank r = square_rank(wpsq);
|
Rank r = rank_of(wpsq);
|
||||||
Square queeningSq = make_square(f, RANK_8);
|
Square queeningSq = make_square(f, RANK_8);
|
||||||
int tempo = (pos.side_to_move() == strongerSide);
|
int tempo = (pos.side_to_move() == strongerSide);
|
||||||
|
|
||||||
|
@ -540,20 +540,20 @@ ScaleFactor Endgame<KRPKR>::apply(const Position& pos) const {
|
||||||
if ( r <= RANK_5
|
if ( r <= RANK_5
|
||||||
&& square_distance(bksq, queeningSq) <= 1
|
&& square_distance(bksq, queeningSq) <= 1
|
||||||
&& wksq <= SQ_H5
|
&& wksq <= SQ_H5
|
||||||
&& (square_rank(brsq) == RANK_6 || (r <= RANK_3 && square_rank(wrsq) != RANK_6)))
|
&& (rank_of(brsq) == RANK_6 || (r <= RANK_3 && rank_of(wrsq) != RANK_6)))
|
||||||
return SCALE_FACTOR_ZERO;
|
return SCALE_FACTOR_ZERO;
|
||||||
|
|
||||||
// The defending side saves a draw by checking from behind in case the pawn
|
// The defending side saves a draw by checking from behind in case the pawn
|
||||||
// has advanced to the 6th rank with the king behind.
|
// has advanced to the 6th rank with the king behind.
|
||||||
if ( r == RANK_6
|
if ( r == RANK_6
|
||||||
&& square_distance(bksq, queeningSq) <= 1
|
&& square_distance(bksq, queeningSq) <= 1
|
||||||
&& square_rank(wksq) + tempo <= RANK_6
|
&& rank_of(wksq) + tempo <= RANK_6
|
||||||
&& (square_rank(brsq) == RANK_1 || (!tempo && abs(square_file(brsq) - f) >= 3)))
|
&& (rank_of(brsq) == RANK_1 || (!tempo && abs(file_of(brsq) - f) >= 3)))
|
||||||
return SCALE_FACTOR_ZERO;
|
return SCALE_FACTOR_ZERO;
|
||||||
|
|
||||||
if ( r >= RANK_6
|
if ( r >= RANK_6
|
||||||
&& bksq == queeningSq
|
&& bksq == queeningSq
|
||||||
&& square_rank(brsq) == RANK_1
|
&& rank_of(brsq) == RANK_1
|
||||||
&& (!tempo || square_distance(wksq, wpsq) >= 2))
|
&& (!tempo || square_distance(wksq, wpsq) >= 2))
|
||||||
return SCALE_FACTOR_ZERO;
|
return SCALE_FACTOR_ZERO;
|
||||||
|
|
||||||
|
@ -562,8 +562,8 @@ ScaleFactor Endgame<KRPKR>::apply(const Position& pos) const {
|
||||||
if ( wpsq == SQ_A7
|
if ( wpsq == SQ_A7
|
||||||
&& wrsq == SQ_A8
|
&& wrsq == SQ_A8
|
||||||
&& (bksq == SQ_H7 || bksq == SQ_G7)
|
&& (bksq == SQ_H7 || bksq == SQ_G7)
|
||||||
&& square_file(brsq) == FILE_A
|
&& file_of(brsq) == FILE_A
|
||||||
&& (square_rank(brsq) <= RANK_3 || square_file(wksq) >= FILE_D || square_rank(wksq) <= RANK_5))
|
&& (rank_of(brsq) <= RANK_3 || file_of(wksq) >= FILE_D || rank_of(wksq) <= RANK_5))
|
||||||
return SCALE_FACTOR_ZERO;
|
return SCALE_FACTOR_ZERO;
|
||||||
|
|
||||||
// If the defending king blocks the pawn and the attacking king is too far
|
// If the defending king blocks the pawn and the attacking king is too far
|
||||||
|
@ -579,7 +579,7 @@ ScaleFactor Endgame<KRPKR>::apply(const Position& pos) const {
|
||||||
// and the defending king cannot gain tempi by threatening the attacking rook.
|
// and the defending king cannot gain tempi by threatening the attacking rook.
|
||||||
if ( r == RANK_7
|
if ( r == RANK_7
|
||||||
&& f != FILE_A
|
&& f != FILE_A
|
||||||
&& square_file(wrsq) == f
|
&& file_of(wrsq) == f
|
||||||
&& wrsq != queeningSq
|
&& wrsq != queeningSq
|
||||||
&& (square_distance(wksq, queeningSq) < square_distance(bksq, queeningSq) - 2 + tempo)
|
&& (square_distance(wksq, queeningSq) < square_distance(bksq, queeningSq) - 2 + tempo)
|
||||||
&& (square_distance(wksq, queeningSq) < square_distance(bksq, wrsq) + tempo))
|
&& (square_distance(wksq, queeningSq) < square_distance(bksq, wrsq) + tempo))
|
||||||
|
@ -587,7 +587,7 @@ ScaleFactor Endgame<KRPKR>::apply(const Position& pos) const {
|
||||||
|
|
||||||
// Similar to the above, but with the pawn further back
|
// Similar to the above, but with the pawn further back
|
||||||
if ( f != FILE_A
|
if ( f != FILE_A
|
||||||
&& square_file(wrsq) == f
|
&& file_of(wrsq) == f
|
||||||
&& wrsq < wpsq
|
&& wrsq < wpsq
|
||||||
&& (square_distance(wksq, queeningSq) < square_distance(bksq, queeningSq) - 2 + tempo)
|
&& (square_distance(wksq, queeningSq) < square_distance(bksq, queeningSq) - 2 + tempo)
|
||||||
&& (square_distance(wksq, wpsq + DELTA_N) < square_distance(bksq, wpsq + DELTA_N) - 2 + tempo)
|
&& (square_distance(wksq, wpsq + DELTA_N) < square_distance(bksq, wpsq + DELTA_N) - 2 + tempo)
|
||||||
|
@ -602,9 +602,9 @@ ScaleFactor Endgame<KRPKR>::apply(const Position& pos) const {
|
||||||
// the pawn's path, it's probably a draw.
|
// the pawn's path, it's probably a draw.
|
||||||
if (r <= RANK_4 && bksq > wpsq)
|
if (r <= RANK_4 && bksq > wpsq)
|
||||||
{
|
{
|
||||||
if (square_file(bksq) == square_file(wpsq))
|
if (file_of(bksq) == file_of(wpsq))
|
||||||
return ScaleFactor(10);
|
return ScaleFactor(10);
|
||||||
if ( abs(square_file(bksq) - square_file(wpsq)) == 1
|
if ( abs(file_of(bksq) - file_of(wpsq)) == 1
|
||||||
&& square_distance(wksq, bksq) > 2)
|
&& square_distance(wksq, bksq) > 2)
|
||||||
return ScaleFactor(24 - 2 * square_distance(wksq, bksq));
|
return ScaleFactor(24 - 2 * square_distance(wksq, bksq));
|
||||||
}
|
}
|
||||||
|
@ -670,7 +670,7 @@ ScaleFactor Endgame<KPsK>::apply(const Position& pos) const {
|
||||||
{
|
{
|
||||||
// Does the defending king block the pawns?
|
// Does the defending king block the pawns?
|
||||||
if ( square_distance(ksq, relative_square(strongerSide, SQ_A8)) <= 1
|
if ( square_distance(ksq, relative_square(strongerSide, SQ_A8)) <= 1
|
||||||
|| ( square_file(ksq) == FILE_A
|
|| ( file_of(ksq) == FILE_A
|
||||||
&& (in_front_bb(strongerSide, ksq) & pawns) == EmptyBoardBB))
|
&& (in_front_bb(strongerSide, ksq) & pawns) == EmptyBoardBB))
|
||||||
return SCALE_FACTOR_ZERO;
|
return SCALE_FACTOR_ZERO;
|
||||||
}
|
}
|
||||||
|
@ -679,7 +679,7 @@ ScaleFactor Endgame<KPsK>::apply(const Position& pos) const {
|
||||||
{
|
{
|
||||||
// Does the defending king block the pawns?
|
// Does the defending king block the pawns?
|
||||||
if ( square_distance(ksq, relative_square(strongerSide, SQ_H8)) <= 1
|
if ( square_distance(ksq, relative_square(strongerSide, SQ_H8)) <= 1
|
||||||
|| ( square_file(ksq) == FILE_H
|
|| ( file_of(ksq) == FILE_H
|
||||||
&& (in_front_bb(strongerSide, ksq) & pawns) == EmptyBoardBB))
|
&& (in_front_bb(strongerSide, ksq) & pawns) == EmptyBoardBB))
|
||||||
return SCALE_FACTOR_ZERO;
|
return SCALE_FACTOR_ZERO;
|
||||||
}
|
}
|
||||||
|
@ -708,7 +708,7 @@ ScaleFactor Endgame<KBPKB>::apply(const Position& pos) const {
|
||||||
Square weakerKingSq = pos.king_square(weakerSide);
|
Square weakerKingSq = pos.king_square(weakerSide);
|
||||||
|
|
||||||
// Case 1: Defending king blocks the pawn, and cannot be driven away
|
// Case 1: Defending king blocks the pawn, and cannot be driven away
|
||||||
if ( square_file(weakerKingSq) == square_file(pawnSq)
|
if ( file_of(weakerKingSq) == file_of(pawnSq)
|
||||||
&& relative_rank(strongerSide, pawnSq) < relative_rank(strongerSide, weakerKingSq)
|
&& relative_rank(strongerSide, pawnSq) < relative_rank(strongerSide, weakerKingSq)
|
||||||
&& ( opposite_color_squares(weakerKingSq, strongerBishopSq)
|
&& ( opposite_color_squares(weakerKingSq, strongerBishopSq)
|
||||||
|| relative_rank(strongerSide, weakerKingSq) <= RANK_6))
|
|| relative_rank(strongerSide, weakerKingSq) <= RANK_6))
|
||||||
|
@ -766,19 +766,19 @@ ScaleFactor Endgame<KBPPKB>::apply(const Position& pos) const {
|
||||||
Square ksq = pos.king_square(weakerSide);
|
Square ksq = pos.king_square(weakerSide);
|
||||||
Square psq1 = pos.piece_list(strongerSide, PAWN)[0];
|
Square psq1 = pos.piece_list(strongerSide, PAWN)[0];
|
||||||
Square psq2 = pos.piece_list(strongerSide, PAWN)[1];
|
Square psq2 = pos.piece_list(strongerSide, PAWN)[1];
|
||||||
Rank r1 = square_rank(psq1);
|
Rank r1 = rank_of(psq1);
|
||||||
Rank r2 = square_rank(psq2);
|
Rank r2 = rank_of(psq2);
|
||||||
Square blockSq1, blockSq2;
|
Square blockSq1, blockSq2;
|
||||||
|
|
||||||
if (relative_rank(strongerSide, psq1) > relative_rank(strongerSide, psq2))
|
if (relative_rank(strongerSide, psq1) > relative_rank(strongerSide, psq2))
|
||||||
{
|
{
|
||||||
blockSq1 = psq1 + pawn_push(strongerSide);
|
blockSq1 = psq1 + pawn_push(strongerSide);
|
||||||
blockSq2 = make_square(square_file(psq2), square_rank(psq1));
|
blockSq2 = make_square(file_of(psq2), rank_of(psq1));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
blockSq1 = psq2 + pawn_push(strongerSide);
|
blockSq1 = psq2 + pawn_push(strongerSide);
|
||||||
blockSq2 = make_square(square_file(psq1), square_rank(psq2));
|
blockSq2 = make_square(file_of(psq1), rank_of(psq2));
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (file_distance(psq1, psq2))
|
switch (file_distance(psq1, psq2))
|
||||||
|
@ -786,7 +786,7 @@ ScaleFactor Endgame<KBPPKB>::apply(const Position& pos) const {
|
||||||
case 0:
|
case 0:
|
||||||
// Both pawns are on the same file. Easy draw if defender firmly controls
|
// Both pawns are on the same file. Easy draw if defender firmly controls
|
||||||
// some square in the frontmost pawn's path.
|
// some square in the frontmost pawn's path.
|
||||||
if ( square_file(ksq) == square_file(blockSq1)
|
if ( file_of(ksq) == file_of(blockSq1)
|
||||||
&& relative_rank(strongerSide, ksq) >= relative_rank(strongerSide, blockSq1)
|
&& relative_rank(strongerSide, ksq) >= relative_rank(strongerSide, blockSq1)
|
||||||
&& opposite_color_squares(ksq, wbsq))
|
&& opposite_color_squares(ksq, wbsq))
|
||||||
return SCALE_FACTOR_ZERO;
|
return SCALE_FACTOR_ZERO;
|
||||||
|
@ -837,7 +837,7 @@ ScaleFactor Endgame<KBPKN>::apply(const Position& pos) const {
|
||||||
Square strongerBishopSq = pos.piece_list(strongerSide, BISHOP)[0];
|
Square strongerBishopSq = pos.piece_list(strongerSide, BISHOP)[0];
|
||||||
Square weakerKingSq = pos.king_square(weakerSide);
|
Square weakerKingSq = pos.king_square(weakerSide);
|
||||||
|
|
||||||
if ( square_file(weakerKingSq) == square_file(pawnSq)
|
if ( file_of(weakerKingSq) == file_of(pawnSq)
|
||||||
&& relative_rank(strongerSide, pawnSq) < relative_rank(strongerSide, weakerKingSq)
|
&& relative_rank(strongerSide, pawnSq) < relative_rank(strongerSide, weakerKingSq)
|
||||||
&& ( opposite_color_squares(weakerKingSq, strongerBishopSq)
|
&& ( opposite_color_squares(weakerKingSq, strongerBishopSq)
|
||||||
|| relative_rank(strongerSide, weakerKingSq) <= RANK_6))
|
|| relative_rank(strongerSide, weakerKingSq) <= RANK_6))
|
||||||
|
@ -900,23 +900,23 @@ ScaleFactor Endgame<KPKP>::apply(const Position& pos) const {
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
wksq = flip_square(pos.king_square(BLACK));
|
wksq = flip(pos.king_square(BLACK));
|
||||||
bksq = flip_square(pos.king_square(WHITE));
|
bksq = flip(pos.king_square(WHITE));
|
||||||
wpsq = flip_square(pos.piece_list(BLACK, PAWN)[0]);
|
wpsq = flip(pos.piece_list(BLACK, PAWN)[0]);
|
||||||
stm = opposite_color(pos.side_to_move());
|
stm = flip(pos.side_to_move());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (square_file(wpsq) >= FILE_E)
|
if (file_of(wpsq) >= FILE_E)
|
||||||
{
|
{
|
||||||
wksq = flop_square(wksq);
|
wksq = mirror(wksq);
|
||||||
bksq = flop_square(bksq);
|
bksq = mirror(bksq);
|
||||||
wpsq = flop_square(wpsq);
|
wpsq = mirror(wpsq);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the pawn has advanced to the fifth rank or further, and is not a
|
// If the pawn has advanced to the fifth rank or further, and is not a
|
||||||
// rook pawn, it's too dangerous to assume that it's at least a draw.
|
// rook pawn, it's too dangerous to assume that it's at least a draw.
|
||||||
if ( square_rank(wpsq) >= RANK_5
|
if ( rank_of(wpsq) >= RANK_5
|
||||||
&& square_file(wpsq) != FILE_A)
|
&& file_of(wpsq) != FILE_A)
|
||||||
return SCALE_FACTOR_NONE;
|
return SCALE_FACTOR_NONE;
|
||||||
|
|
||||||
// Probe the KPK bitbase with the weakest side's pawn removed. If it's a
|
// Probe the KPK bitbase with the weakest side's pawn removed. If it's a
|
||||||
|
|
|
@ -82,7 +82,7 @@ struct EndgameBase {
|
||||||
template<EndgameType E, typename T = typename eg_family<E>::type>
|
template<EndgameType E, typename T = typename eg_family<E>::type>
|
||||||
struct Endgame : public EndgameBase<T> {
|
struct Endgame : public EndgameBase<T> {
|
||||||
|
|
||||||
explicit Endgame(Color c) : strongerSide(c), weakerSide(opposite_color(c)) {}
|
explicit Endgame(Color c) : strongerSide(c), weakerSide(flip(c)) {}
|
||||||
Color color() const { return strongerSide; }
|
Color color() const { return strongerSide; }
|
||||||
T apply(const Position&) const;
|
T apply(const Position&) const;
|
||||||
|
|
||||||
|
|
|
@ -546,7 +546,7 @@ namespace {
|
||||||
// problem, especially when that pawn is also blocked.
|
// problem, especially when that pawn is also blocked.
|
||||||
if (s == relative_square(Us, SQ_A1) || s == relative_square(Us, SQ_H1))
|
if (s == relative_square(Us, SQ_A1) || s == relative_square(Us, SQ_H1))
|
||||||
{
|
{
|
||||||
Square d = pawn_push(Us) + (square_file(s) == FILE_A ? DELTA_E : DELTA_W);
|
Square d = pawn_push(Us) + (file_of(s) == FILE_A ? DELTA_E : DELTA_W);
|
||||||
if (pos.piece_on(s + d) == make_piece(Us, PAWN))
|
if (pos.piece_on(s + d) == make_piece(Us, PAWN))
|
||||||
{
|
{
|
||||||
if (!pos.square_is_empty(s + d + pawn_push(Us)))
|
if (!pos.square_is_empty(s + d + pawn_push(Us)))
|
||||||
|
@ -563,7 +563,7 @@ namespace {
|
||||||
if (Piece == ROOK)
|
if (Piece == ROOK)
|
||||||
{
|
{
|
||||||
// Open and half-open files
|
// Open and half-open files
|
||||||
f = square_file(s);
|
f = file_of(s);
|
||||||
if (ei.pi->file_is_half_open(Us, f))
|
if (ei.pi->file_is_half_open(Us, f))
|
||||||
{
|
{
|
||||||
if (ei.pi->file_is_half_open(Them, f))
|
if (ei.pi->file_is_half_open(Them, f))
|
||||||
|
@ -579,21 +579,21 @@ namespace {
|
||||||
|
|
||||||
ksq = pos.king_square(Us);
|
ksq = pos.king_square(Us);
|
||||||
|
|
||||||
if ( square_file(ksq) >= FILE_E
|
if ( file_of(ksq) >= FILE_E
|
||||||
&& square_file(s) > square_file(ksq)
|
&& file_of(s) > file_of(ksq)
|
||||||
&& (relative_rank(Us, ksq) == RANK_1 || square_rank(ksq) == square_rank(s)))
|
&& (relative_rank(Us, ksq) == RANK_1 || rank_of(ksq) == rank_of(s)))
|
||||||
{
|
{
|
||||||
// Is there a half-open file between the king and the edge of the board?
|
// Is there a half-open file between the king and the edge of the board?
|
||||||
if (!ei.pi->has_open_file_to_right(Us, square_file(ksq)))
|
if (!ei.pi->has_open_file_to_right(Us, file_of(ksq)))
|
||||||
score -= make_score(pos.can_castle(Us) ? (TrappedRookPenalty - mob * 16) / 2
|
score -= make_score(pos.can_castle(Us) ? (TrappedRookPenalty - mob * 16) / 2
|
||||||
: (TrappedRookPenalty - mob * 16), 0);
|
: (TrappedRookPenalty - mob * 16), 0);
|
||||||
}
|
}
|
||||||
else if ( square_file(ksq) <= FILE_D
|
else if ( file_of(ksq) <= FILE_D
|
||||||
&& square_file(s) < square_file(ksq)
|
&& file_of(s) < file_of(ksq)
|
||||||
&& (relative_rank(Us, ksq) == RANK_1 || square_rank(ksq) == square_rank(s)))
|
&& (relative_rank(Us, ksq) == RANK_1 || rank_of(ksq) == rank_of(s)))
|
||||||
{
|
{
|
||||||
// Is there a half-open file between the king and the edge of the board?
|
// Is there a half-open file between the king and the edge of the board?
|
||||||
if (!ei.pi->has_open_file_to_left(Us, square_file(ksq)))
|
if (!ei.pi->has_open_file_to_left(Us, file_of(ksq)))
|
||||||
score -= make_score(pos.can_castle(Us) ? (TrappedRookPenalty - mob * 16) / 2
|
score -= make_score(pos.can_castle(Us) ? (TrappedRookPenalty - mob * 16) / 2
|
||||||
: (TrappedRookPenalty - mob * 16), 0);
|
: (TrappedRookPenalty - mob * 16), 0);
|
||||||
}
|
}
|
||||||
|
@ -816,7 +816,7 @@ namespace {
|
||||||
ebonus -= Value(square_distance(pos.king_square(Us), blockSq) * 3 * rr);
|
ebonus -= Value(square_distance(pos.king_square(Us), blockSq) * 3 * rr);
|
||||||
|
|
||||||
// If blockSq is not the queening square then consider also a second push
|
// If blockSq is not the queening square then consider also a second push
|
||||||
if (square_rank(blockSq) != (Us == WHITE ? RANK_8 : RANK_1))
|
if (rank_of(blockSq) != (Us == WHITE ? RANK_8 : RANK_1))
|
||||||
ebonus -= Value(square_distance(pos.king_square(Us), blockSq + pawn_push(Us)) * rr);
|
ebonus -= Value(square_distance(pos.king_square(Us), blockSq + pawn_push(Us)) * rr);
|
||||||
|
|
||||||
// If the pawn is free to advance, increase bonus
|
// If the pawn is free to advance, increase bonus
|
||||||
|
@ -866,7 +866,7 @@ namespace {
|
||||||
// we try the following: Increase the value for rook pawns if the
|
// we try the following: Increase the value for rook pawns if the
|
||||||
// other side has no pieces apart from a knight, and decrease the
|
// other side has no pieces apart from a knight, and decrease the
|
||||||
// value if the other side has a rook or queen.
|
// value if the other side has a rook or queen.
|
||||||
if (square_file(s) == FILE_A || square_file(s) == FILE_H)
|
if (file_of(s) == FILE_A || file_of(s) == FILE_H)
|
||||||
{
|
{
|
||||||
if (pos.non_pawn_material(Them) <= KnightValueMidgame)
|
if (pos.non_pawn_material(Them) <= KnightValueMidgame)
|
||||||
ebonus += ebonus / 4;
|
ebonus += ebonus / 4;
|
||||||
|
@ -902,7 +902,7 @@ namespace {
|
||||||
for (c = WHITE; c <= BLACK; c++)
|
for (c = WHITE; c <= BLACK; c++)
|
||||||
{
|
{
|
||||||
// Skip if other side has non-pawn pieces
|
// Skip if other side has non-pawn pieces
|
||||||
if (pos.non_pawn_material(opposite_color(c)))
|
if (pos.non_pawn_material(flip(c)))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
b = ei.pi->passed_pawns(c);
|
b = ei.pi->passed_pawns(c);
|
||||||
|
@ -910,12 +910,12 @@ namespace {
|
||||||
while (b)
|
while (b)
|
||||||
{
|
{
|
||||||
s = pop_1st_bit(&b);
|
s = pop_1st_bit(&b);
|
||||||
queeningSquare = relative_square(c, make_square(square_file(s), RANK_8));
|
queeningSquare = relative_square(c, make_square(file_of(s), RANK_8));
|
||||||
queeningPath = squares_in_front_of(c, s);
|
queeningPath = squares_in_front_of(c, s);
|
||||||
|
|
||||||
// Compute plies to queening and check direct advancement
|
// Compute plies to queening and check direct advancement
|
||||||
movesToGo = rank_distance(s, queeningSquare) - int(relative_rank(c, s) == RANK_2);
|
movesToGo = rank_distance(s, queeningSquare) - int(relative_rank(c, s) == RANK_2);
|
||||||
oppMovesToGo = square_distance(pos.king_square(opposite_color(c)), queeningSquare) - int(c != pos.side_to_move());
|
oppMovesToGo = square_distance(pos.king_square(flip(c)), queeningSquare) - int(c != pos.side_to_move());
|
||||||
pathDefended = ((ei.attackedBy[c][0] & queeningPath) == queeningPath);
|
pathDefended = ((ei.attackedBy[c][0] & queeningPath) == queeningPath);
|
||||||
|
|
||||||
if (movesToGo >= oppMovesToGo && !pathDefended)
|
if (movesToGo >= oppMovesToGo && !pathDefended)
|
||||||
|
@ -943,7 +943,7 @@ namespace {
|
||||||
return SCORE_ZERO;
|
return SCORE_ZERO;
|
||||||
|
|
||||||
winnerSide = (pliesToQueen[WHITE] < pliesToQueen[BLACK] ? WHITE : BLACK);
|
winnerSide = (pliesToQueen[WHITE] < pliesToQueen[BLACK] ? WHITE : BLACK);
|
||||||
loserSide = opposite_color(winnerSide);
|
loserSide = flip(winnerSide);
|
||||||
|
|
||||||
// Step 3. Can the losing side possibly create a new passed pawn and thus prevent the loss?
|
// Step 3. Can the losing side possibly create a new passed pawn and thus prevent the loss?
|
||||||
b = candidates = pos.pieces(PAWN, loserSide);
|
b = candidates = pos.pieces(PAWN, loserSide);
|
||||||
|
@ -953,7 +953,7 @@ namespace {
|
||||||
s = pop_1st_bit(&b);
|
s = pop_1st_bit(&b);
|
||||||
|
|
||||||
// Compute plies from queening
|
// Compute plies from queening
|
||||||
queeningSquare = relative_square(loserSide, make_square(square_file(s), RANK_8));
|
queeningSquare = relative_square(loserSide, make_square(file_of(s), RANK_8));
|
||||||
movesToGo = rank_distance(s, queeningSquare) - int(relative_rank(loserSide, s) == RANK_2);
|
movesToGo = rank_distance(s, queeningSquare) - int(relative_rank(loserSide, s) == RANK_2);
|
||||||
pliesToGo = 2 * movesToGo - int(loserSide == pos.side_to_move());
|
pliesToGo = 2 * movesToGo - int(loserSide == pos.side_to_move());
|
||||||
|
|
||||||
|
@ -977,7 +977,7 @@ namespace {
|
||||||
minKingDist = kingptg = 256;
|
minKingDist = kingptg = 256;
|
||||||
|
|
||||||
// Compute plies from queening
|
// Compute plies from queening
|
||||||
queeningSquare = relative_square(loserSide, make_square(square_file(s), RANK_8));
|
queeningSquare = relative_square(loserSide, make_square(file_of(s), RANK_8));
|
||||||
movesToGo = rank_distance(s, queeningSquare) - int(relative_rank(loserSide, s) == RANK_2);
|
movesToGo = rank_distance(s, queeningSquare) - int(relative_rank(loserSide, s) == RANK_2);
|
||||||
pliesToGo = 2 * movesToGo - int(loserSide == pos.side_to_move());
|
pliesToGo = 2 * movesToGo - int(loserSide == pos.side_to_move());
|
||||||
|
|
||||||
|
|
14
src/move.cpp
14
src/move.cpp
|
@ -45,7 +45,7 @@ const string move_to_uci(Move m, bool chess960) {
|
||||||
return "0000";
|
return "0000";
|
||||||
|
|
||||||
if (move_is_castle(m) && !chess960)
|
if (move_is_castle(m) && !chess960)
|
||||||
to = from + (square_file(to) == FILE_H ? Square(2) : -Square(2));
|
to = from + (file_of(to) == FILE_H ? Square(2) : -Square(2));
|
||||||
|
|
||||||
if (move_is_promotion(m))
|
if (move_is_promotion(m))
|
||||||
promotion = char(tolower(piece_type_to_char(promotion_piece_type(m))));
|
promotion = char(tolower(piece_type_to_char(promotion_piece_type(m))));
|
||||||
|
@ -86,7 +86,7 @@ const string move_to_san(Position& pos, Move m) {
|
||||||
bool ambiguousMove, ambiguousFile, ambiguousRank;
|
bool ambiguousMove, ambiguousFile, ambiguousRank;
|
||||||
Square sq, from = move_from(m);
|
Square sq, from = move_from(m);
|
||||||
Square to = move_to(m);
|
Square to = move_to(m);
|
||||||
PieceType pt = piece_type(pos.piece_on(from));
|
PieceType pt = type_of(pos.piece_on(from));
|
||||||
string san;
|
string san;
|
||||||
|
|
||||||
if (move_is_castle(m))
|
if (move_is_castle(m))
|
||||||
|
@ -107,10 +107,10 @@ const string move_to_san(Position& pos, Move m) {
|
||||||
{
|
{
|
||||||
sq = pop_1st_bit(&attackers);
|
sq = pop_1st_bit(&attackers);
|
||||||
|
|
||||||
if (square_file(sq) == square_file(from))
|
if (file_of(sq) == file_of(from))
|
||||||
ambiguousFile = true;
|
ambiguousFile = true;
|
||||||
|
|
||||||
if (square_rank(sq) == square_rank(from))
|
if (rank_of(sq) == rank_of(from))
|
||||||
ambiguousRank = true;
|
ambiguousRank = true;
|
||||||
|
|
||||||
ambiguousMove = true;
|
ambiguousMove = true;
|
||||||
|
@ -119,9 +119,9 @@ const string move_to_san(Position& pos, Move m) {
|
||||||
if (ambiguousMove)
|
if (ambiguousMove)
|
||||||
{
|
{
|
||||||
if (!ambiguousFile)
|
if (!ambiguousFile)
|
||||||
san += file_to_char(square_file(from));
|
san += file_to_char(file_of(from));
|
||||||
else if (!ambiguousRank)
|
else if (!ambiguousRank)
|
||||||
san += rank_to_char(square_rank(from));
|
san += rank_to_char(rank_of(from));
|
||||||
else
|
else
|
||||||
san += square_to_string(from);
|
san += square_to_string(from);
|
||||||
}
|
}
|
||||||
|
@ -130,7 +130,7 @@ const string move_to_san(Position& pos, Move m) {
|
||||||
if (pos.move_is_capture(m))
|
if (pos.move_is_capture(m))
|
||||||
{
|
{
|
||||||
if (pt == PAWN)
|
if (pt == PAWN)
|
||||||
san += file_to_char(square_file(from));
|
san += file_to_char(file_of(from));
|
||||||
|
|
||||||
san += 'x';
|
san += 'x';
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,7 @@ namespace {
|
||||||
Bitboard b = pos.attacks_from<Pt>(from) & pos.empty_squares();
|
Bitboard b = pos.attacks_from<Pt>(from) & pos.empty_squares();
|
||||||
|
|
||||||
if (Pt == KING)
|
if (Pt == KING)
|
||||||
b &= ~QueenPseudoAttacks[pos.king_square(opposite_color(pos.side_to_move()))];
|
b &= ~QueenPseudoAttacks[pos.king_square(flip(pos.side_to_move()))];
|
||||||
|
|
||||||
SERIALIZE_MOVES(b);
|
SERIALIZE_MOVES(b);
|
||||||
return mlist;
|
return mlist;
|
||||||
|
@ -158,7 +158,7 @@ MoveStack* generate(const Position& pos, MoveStack* mlist) {
|
||||||
Bitboard target;
|
Bitboard target;
|
||||||
|
|
||||||
if (Type == MV_CAPTURE || Type == MV_NON_EVASION)
|
if (Type == MV_CAPTURE || Type == MV_NON_EVASION)
|
||||||
target = pos.pieces(opposite_color(us));
|
target = pos.pieces(flip(us));
|
||||||
else if (Type == MV_NON_CAPTURE)
|
else if (Type == MV_NON_CAPTURE)
|
||||||
target = pos.empty_squares();
|
target = pos.empty_squares();
|
||||||
else
|
else
|
||||||
|
@ -207,9 +207,9 @@ MoveStack* generate<MV_NON_CAPTURE_CHECK>(const Position& pos, MoveStack* mlist)
|
||||||
Bitboard b, dc;
|
Bitboard b, dc;
|
||||||
Square from;
|
Square from;
|
||||||
Color us = pos.side_to_move();
|
Color us = pos.side_to_move();
|
||||||
Square ksq = pos.king_square(opposite_color(us));
|
Square ksq = pos.king_square(flip(us));
|
||||||
|
|
||||||
assert(pos.piece_on(ksq) == make_piece(opposite_color(us), KING));
|
assert(pos.piece_on(ksq) == make_piece(flip(us), KING));
|
||||||
|
|
||||||
// Discovered non-capture checks
|
// Discovered non-capture checks
|
||||||
b = dc = pos.discovered_check_candidates();
|
b = dc = pos.discovered_check_candidates();
|
||||||
|
@ -217,7 +217,7 @@ MoveStack* generate<MV_NON_CAPTURE_CHECK>(const Position& pos, MoveStack* mlist)
|
||||||
while (b)
|
while (b)
|
||||||
{
|
{
|
||||||
from = pop_1st_bit(&b);
|
from = pop_1st_bit(&b);
|
||||||
switch (piece_type(pos.piece_on(from)))
|
switch (type_of(pos.piece_on(from)))
|
||||||
{
|
{
|
||||||
case PAWN: /* Will be generated togheter with pawns direct checks */ break;
|
case PAWN: /* Will be generated togheter with pawns direct checks */ break;
|
||||||
case KNIGHT: mlist = generate_discovered_checks<KNIGHT>(pos, mlist, from); break;
|
case KNIGHT: mlist = generate_discovered_checks<KNIGHT>(pos, mlist, from); break;
|
||||||
|
@ -264,9 +264,9 @@ MoveStack* generate<MV_EVASION>(const Position& pos, MoveStack* mlist) {
|
||||||
checkersCnt++;
|
checkersCnt++;
|
||||||
checksq = pop_1st_bit(&b);
|
checksq = pop_1st_bit(&b);
|
||||||
|
|
||||||
assert(piece_color(pos.piece_on(checksq)) == opposite_color(us));
|
assert(color_of(pos.piece_on(checksq)) == flip(us));
|
||||||
|
|
||||||
switch (piece_type(pos.piece_on(checksq)))
|
switch (type_of(pos.piece_on(checksq)))
|
||||||
{
|
{
|
||||||
case BISHOP: sliderAttacks |= BishopPseudoAttacks[checksq]; break;
|
case BISHOP: sliderAttacks |= BishopPseudoAttacks[checksq]; break;
|
||||||
case ROOK: sliderAttacks |= RookPseudoAttacks[checksq]; break;
|
case ROOK: sliderAttacks |= RookPseudoAttacks[checksq]; break;
|
||||||
|
@ -473,8 +473,8 @@ namespace {
|
||||||
// En passant captures
|
// En passant captures
|
||||||
if ((Type == MV_CAPTURE || Type == MV_EVASION) && pos.ep_square() != SQ_NONE)
|
if ((Type == MV_CAPTURE || Type == MV_EVASION) && pos.ep_square() != SQ_NONE)
|
||||||
{
|
{
|
||||||
assert(Us != WHITE || square_rank(pos.ep_square()) == RANK_6);
|
assert(Us != WHITE || rank_of(pos.ep_square()) == RANK_6);
|
||||||
assert(Us != BLACK || square_rank(pos.ep_square()) == RANK_3);
|
assert(Us != BLACK || rank_of(pos.ep_square()) == RANK_3);
|
||||||
|
|
||||||
// An en passant capture can be an evasion only if the checking piece
|
// An en passant capture can be an evasion only if the checking piece
|
||||||
// is the double pushed pawn and so is in the target. Otherwise this
|
// is the double pushed pawn and so is in the target. Otherwise this
|
||||||
|
@ -499,7 +499,7 @@ namespace {
|
||||||
MoveStack* generate_castle_moves(const Position& pos, MoveStack* mlist, Color us) {
|
MoveStack* generate_castle_moves(const Position& pos, MoveStack* mlist, Color us) {
|
||||||
|
|
||||||
CastleRight f = CastleRight((Side == KING_SIDE ? WHITE_OO : WHITE_OOO) << us);
|
CastleRight f = CastleRight((Side == KING_SIDE ? WHITE_OO : WHITE_OOO) << us);
|
||||||
Color them = opposite_color(us);
|
Color them = flip(us);
|
||||||
|
|
||||||
// After castling, the rook and king's final positions are exactly the same
|
// After castling, the rook and king's final positions are exactly the same
|
||||||
// in Chess960 as they would be in standard chess.
|
// in Chess960 as they would be in standard chess.
|
||||||
|
|
|
@ -252,7 +252,7 @@ void MovePicker::score_captures() {
|
||||||
{
|
{
|
||||||
m = cur->move;
|
m = cur->move;
|
||||||
cur->score = piece_value_midgame(pos.piece_on(move_to(m)))
|
cur->score = piece_value_midgame(pos.piece_on(move_to(m)))
|
||||||
- piece_type(pos.piece_on(move_from(m)));
|
- type_of(pos.piece_on(move_from(m)));
|
||||||
|
|
||||||
if (move_is_promotion(m))
|
if (move_is_promotion(m))
|
||||||
cur->score += piece_value_midgame(Piece(promotion_piece_type(m)));
|
cur->score += piece_value_midgame(Piece(promotion_piece_type(m)));
|
||||||
|
@ -291,7 +291,7 @@ void MovePicker::score_evasions() {
|
||||||
cur->score = seeScore - History::MaxValue; // Be sure we are at the bottom
|
cur->score = seeScore - History::MaxValue; // Be sure we are at the bottom
|
||||||
else if (pos.move_is_capture(m))
|
else if (pos.move_is_capture(m))
|
||||||
cur->score = piece_value_midgame(pos.piece_on(move_to(m)))
|
cur->score = piece_value_midgame(pos.piece_on(move_to(m)))
|
||||||
- piece_type(pos.piece_on(move_from(m))) + History::MaxValue;
|
- type_of(pos.piece_on(move_from(m))) + History::MaxValue;
|
||||||
else
|
else
|
||||||
cur->score = H.value(pos.piece_on(move_from(m)), move_to(m));
|
cur->score = H.value(pos.piece_on(move_from(m)), move_to(m));
|
||||||
}
|
}
|
||||||
|
|
|
@ -132,8 +132,8 @@ Score PawnInfoTable::evaluate_pawns(const Position& pos, Bitboard ourPawns,
|
||||||
{
|
{
|
||||||
assert(pos.piece_on(s) == make_piece(Us, PAWN));
|
assert(pos.piece_on(s) == make_piece(Us, PAWN));
|
||||||
|
|
||||||
f = square_file(s);
|
f = file_of(s);
|
||||||
r = square_rank(s);
|
r = rank_of(s);
|
||||||
|
|
||||||
// This file cannot be half open
|
// This file cannot be half open
|
||||||
pi->halfOpenFiles[Us] &= ~(1 << f);
|
pi->halfOpenFiles[Us] &= ~(1 << f);
|
||||||
|
|
151
src/position.cpp
151
src/position.cpp
|
@ -77,7 +77,7 @@ namespace {
|
||||||
|
|
||||||
CheckInfo::CheckInfo(const Position& pos) {
|
CheckInfo::CheckInfo(const Position& pos) {
|
||||||
|
|
||||||
Color them = opposite_color(pos.side_to_move());
|
Color them = flip(pos.side_to_move());
|
||||||
Square ksq = pos.king_square(them);
|
Square ksq = pos.king_square(them);
|
||||||
|
|
||||||
pinned = pos.pinned_pieces();
|
pinned = pos.pinned_pieces();
|
||||||
|
@ -183,7 +183,7 @@ void Position::from_fen(const string& fenStr, bool isChess960) {
|
||||||
&& ((fen >> row) && (row == '3' || row == '6')))
|
&& ((fen >> row) && (row == '3' || row == '6')))
|
||||||
{
|
{
|
||||||
st->epSquare = make_square(File(col - 'a'), Rank(row - '1'));
|
st->epSquare = make_square(File(col - 'a'), Rank(row - '1'));
|
||||||
Color them = opposite_color(sideToMove);
|
Color them = flip(sideToMove);
|
||||||
|
|
||||||
if (!(attacks_from<PAWN>(st->epSquare, them) & pieces(PAWN, sideToMove)))
|
if (!(attacks_from<PAWN>(st->epSquare, them) & pieces(PAWN, sideToMove)))
|
||||||
st->epSquare = SQ_NONE;
|
st->epSquare = SQ_NONE;
|
||||||
|
@ -198,7 +198,7 @@ void Position::from_fen(const string& fenStr, bool isChess960) {
|
||||||
|
|
||||||
// Various initialisations
|
// Various initialisations
|
||||||
chess960 = isChess960;
|
chess960 = isChess960;
|
||||||
st->checkersBB = attackers_to(king_square(sideToMove)) & pieces(opposite_color(sideToMove));
|
st->checkersBB = attackers_to(king_square(sideToMove)) & pieces(flip(sideToMove));
|
||||||
|
|
||||||
st->key = compute_key();
|
st->key = compute_key();
|
||||||
st->pawnKey = compute_pawn_key();
|
st->pawnKey = compute_pawn_key();
|
||||||
|
@ -251,7 +251,7 @@ void Position::set_castling_rights(char token) {
|
||||||
|
|
||||||
else return;
|
else return;
|
||||||
|
|
||||||
if (square_file(rsq) < square_file(ksq))
|
if (file_of(rsq) < file_of(ksq))
|
||||||
set_castle(WHITE_OOO << c, ksq, rsq);
|
set_castle(WHITE_OOO << c, ksq, rsq);
|
||||||
else
|
else
|
||||||
set_castle(WHITE_OO << c, ksq, rsq);
|
set_castle(WHITE_OO << c, ksq, rsq);
|
||||||
|
@ -300,16 +300,16 @@ const string Position::to_fen() const {
|
||||||
if (st->castleRights != CASTLES_NONE)
|
if (st->castleRights != CASTLES_NONE)
|
||||||
{
|
{
|
||||||
if (can_castle(WHITE_OO))
|
if (can_castle(WHITE_OO))
|
||||||
fen << (chess960 ? char(toupper(file_to_char(square_file(castle_rook_square(WHITE_OO))))) : 'K');
|
fen << (chess960 ? char(toupper(file_to_char(file_of(castle_rook_square(WHITE_OO))))) : 'K');
|
||||||
|
|
||||||
if (can_castle(WHITE_OOO))
|
if (can_castle(WHITE_OOO))
|
||||||
fen << (chess960 ? char(toupper(file_to_char(square_file(castle_rook_square(WHITE_OOO))))) : 'Q');
|
fen << (chess960 ? char(toupper(file_to_char(file_of(castle_rook_square(WHITE_OOO))))) : 'Q');
|
||||||
|
|
||||||
if (can_castle(BLACK_OO))
|
if (can_castle(BLACK_OO))
|
||||||
fen << (chess960 ? file_to_char(square_file(castle_rook_square(BLACK_OO))) : 'k');
|
fen << (chess960 ? file_to_char(file_of(castle_rook_square(BLACK_OO))) : 'k');
|
||||||
|
|
||||||
if (can_castle(BLACK_OOO))
|
if (can_castle(BLACK_OOO))
|
||||||
fen << (chess960 ? file_to_char(square_file(castle_rook_square(BLACK_OOO))) : 'q');
|
fen << (chess960 ? file_to_char(file_of(castle_rook_square(BLACK_OOO))) : 'q');
|
||||||
} else
|
} else
|
||||||
fen << '-';
|
fen << '-';
|
||||||
|
|
||||||
|
@ -345,7 +345,7 @@ void Position::print(Move move) const {
|
||||||
if (piece == PIECE_NONE && square_color(sq) == DARK)
|
if (piece == PIECE_NONE && square_color(sq) == DARK)
|
||||||
piece = PIECE_NONE_DARK_SQ;
|
piece = PIECE_NONE_DARK_SQ;
|
||||||
|
|
||||||
char c = (piece_color(piece_on(sq)) == BLACK ? '=' : ' ');
|
char c = (color_of(piece_on(sq)) == BLACK ? '=' : ' ');
|
||||||
cout << c << PieceToChar[piece] << c << '|';
|
cout << c << PieceToChar[piece] << c << '|';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -363,8 +363,8 @@ Bitboard Position::hidden_checkers() const {
|
||||||
|
|
||||||
// Pinned pieces protect our king, dicovery checks attack the enemy king
|
// Pinned pieces protect our king, dicovery checks attack the enemy king
|
||||||
Bitboard b, result = EmptyBoardBB;
|
Bitboard b, result = EmptyBoardBB;
|
||||||
Bitboard pinners = pieces(FindPinned ? opposite_color(sideToMove) : sideToMove);
|
Bitboard pinners = pieces(FindPinned ? flip(sideToMove) : sideToMove);
|
||||||
Square ksq = king_square(FindPinned ? sideToMove : opposite_color(sideToMove));
|
Square ksq = king_square(FindPinned ? sideToMove : flip(sideToMove));
|
||||||
|
|
||||||
// Pinners are sliders, that give check when candidate pinned is removed
|
// Pinners are sliders, that give check when candidate pinned is removed
|
||||||
pinners &= (pieces(ROOK, QUEEN) & RookPseudoAttacks[ksq])
|
pinners &= (pieces(ROOK, QUEEN) & RookPseudoAttacks[ksq])
|
||||||
|
@ -474,7 +474,7 @@ bool Position::move_attacks_square(Move m, Square s) const {
|
||||||
do_move_bb(&occ, make_move_bb(f, t));
|
do_move_bb(&occ, make_move_bb(f, t));
|
||||||
xray = ( (rook_attacks_bb(s, occ) & pieces(ROOK, QUEEN))
|
xray = ( (rook_attacks_bb(s, occ) & pieces(ROOK, QUEEN))
|
||||||
|(bishop_attacks_bb(s, occ) & pieces(BISHOP, QUEEN)))
|
|(bishop_attacks_bb(s, occ) & pieces(BISHOP, QUEEN)))
|
||||||
& pieces(piece_color(piece_on(f)));
|
& pieces(color_of(piece_on(f)));
|
||||||
|
|
||||||
// If we have attacks we need to verify that are caused by our move
|
// If we have attacks we need to verify that are caused by our move
|
||||||
// and are not already existent ones.
|
// and are not already existent ones.
|
||||||
|
@ -492,7 +492,7 @@ bool Position::pl_move_is_legal(Move m, Bitboard pinned) const {
|
||||||
Color us = side_to_move();
|
Color us = side_to_move();
|
||||||
Square from = move_from(m);
|
Square from = move_from(m);
|
||||||
|
|
||||||
assert(piece_color(piece_on(from)) == us);
|
assert(color_of(piece_on(from)) == us);
|
||||||
assert(piece_on(king_square(us)) == make_piece(us, KING));
|
assert(piece_on(king_square(us)) == make_piece(us, KING));
|
||||||
|
|
||||||
// En passant captures are a tricky special case. Because they are rather
|
// En passant captures are a tricky special case. Because they are rather
|
||||||
|
@ -500,7 +500,7 @@ bool Position::pl_move_is_legal(Move m, Bitboard pinned) const {
|
||||||
// the move is made.
|
// the move is made.
|
||||||
if (move_is_ep(m))
|
if (move_is_ep(m))
|
||||||
{
|
{
|
||||||
Color them = opposite_color(us);
|
Color them = flip(us);
|
||||||
Square to = move_to(m);
|
Square to = move_to(m);
|
||||||
Square capsq = to + pawn_push(them);
|
Square capsq = to + pawn_push(them);
|
||||||
Square ksq = king_square(us);
|
Square ksq = king_square(us);
|
||||||
|
@ -522,8 +522,8 @@ bool Position::pl_move_is_legal(Move m, Bitboard pinned) const {
|
||||||
// If the moving piece is a king, check whether the destination
|
// If the moving piece is a king, check whether the destination
|
||||||
// square is attacked by the opponent. Castling moves are checked
|
// square is attacked by the opponent. Castling moves are checked
|
||||||
// for legality during move generation.
|
// for legality during move generation.
|
||||||
if (piece_type(piece_on(from)) == KING)
|
if (type_of(piece_on(from)) == KING)
|
||||||
return move_is_castle(m) || !(attackers_to(move_to(m)) & pieces(opposite_color(us)));
|
return move_is_castle(m) || !(attackers_to(move_to(m)) & pieces(flip(us)));
|
||||||
|
|
||||||
// A non-king move is legal if and only if it is not pinned or it
|
// A non-king move is legal if and only if it is not pinned or it
|
||||||
// is moving along the ray towards or away from the king.
|
// is moving along the ray towards or away from the king.
|
||||||
|
@ -553,7 +553,7 @@ bool Position::move_is_legal(const Move m) const {
|
||||||
bool Position::move_is_pl(const Move m) const {
|
bool Position::move_is_pl(const Move m) const {
|
||||||
|
|
||||||
Color us = sideToMove;
|
Color us = sideToMove;
|
||||||
Color them = opposite_color(sideToMove);
|
Color them = flip(sideToMove);
|
||||||
Square from = move_from(m);
|
Square from = move_from(m);
|
||||||
Square to = move_to(m);
|
Square to = move_to(m);
|
||||||
Piece pc = piece_on(from);
|
Piece pc = piece_on(from);
|
||||||
|
@ -568,15 +568,15 @@ bool Position::move_is_pl(const Move m) const {
|
||||||
|
|
||||||
// If the from square is not occupied by a piece belonging to the side to
|
// If the from square is not occupied by a piece belonging to the side to
|
||||||
// move, the move is obviously not legal.
|
// move, the move is obviously not legal.
|
||||||
if (pc == PIECE_NONE || piece_color(pc) != us)
|
if (pc == PIECE_NONE || color_of(pc) != us)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// The destination square cannot be occupied by a friendly piece
|
// The destination square cannot be occupied by a friendly piece
|
||||||
if (piece_color(piece_on(to)) == us)
|
if (color_of(piece_on(to)) == us)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Handle the special case of a pawn move
|
// Handle the special case of a pawn move
|
||||||
if (piece_type(pc) == PAWN)
|
if (type_of(pc) == PAWN)
|
||||||
{
|
{
|
||||||
// Move direction must be compatible with pawn color
|
// Move direction must be compatible with pawn color
|
||||||
int direction = to - from;
|
int direction = to - from;
|
||||||
|
@ -585,7 +585,7 @@ bool Position::move_is_pl(const Move m) const {
|
||||||
|
|
||||||
// We have already handled promotion moves, so destination
|
// We have already handled promotion moves, so destination
|
||||||
// cannot be on the 8/1th rank.
|
// cannot be on the 8/1th rank.
|
||||||
if (square_rank(to) == RANK_8 || square_rank(to) == RANK_1)
|
if (rank_of(to) == RANK_8 || rank_of(to) == RANK_1)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Proceed according to the square delta between the origin and
|
// Proceed according to the square delta between the origin and
|
||||||
|
@ -598,11 +598,11 @@ bool Position::move_is_pl(const Move m) const {
|
||||||
case DELTA_SE:
|
case DELTA_SE:
|
||||||
// Capture. The destination square must be occupied by an enemy
|
// Capture. The destination square must be occupied by an enemy
|
||||||
// piece (en passant captures was handled earlier).
|
// piece (en passant captures was handled earlier).
|
||||||
if (piece_color(piece_on(to)) != them)
|
if (color_of(piece_on(to)) != them)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// From and to files must be one file apart, avoids a7h5
|
// From and to files must be one file apart, avoids a7h5
|
||||||
if (abs(square_file(from) - square_file(to)) != 1)
|
if (abs(file_of(from) - file_of(to)) != 1)
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -617,7 +617,7 @@ bool Position::move_is_pl(const Move m) const {
|
||||||
// Double white pawn push. The destination square must be on the fourth
|
// Double white pawn push. The destination square must be on the fourth
|
||||||
// rank, and both the destination square and the square between the
|
// rank, and both the destination square and the square between the
|
||||||
// source and destination squares must be empty.
|
// source and destination squares must be empty.
|
||||||
if ( square_rank(to) != RANK_4
|
if ( rank_of(to) != RANK_4
|
||||||
|| !square_is_empty(to)
|
|| !square_is_empty(to)
|
||||||
|| !square_is_empty(from + DELTA_N))
|
|| !square_is_empty(from + DELTA_N))
|
||||||
return false;
|
return false;
|
||||||
|
@ -627,7 +627,7 @@ bool Position::move_is_pl(const Move m) const {
|
||||||
// Double black pawn push. The destination square must be on the fifth
|
// Double black pawn push. The destination square must be on the fifth
|
||||||
// rank, and both the destination square and the square between the
|
// rank, and both the destination square and the square between the
|
||||||
// source and destination squares must be empty.
|
// source and destination squares must be empty.
|
||||||
if ( square_rank(to) != RANK_5
|
if ( rank_of(to) != RANK_5
|
||||||
|| !square_is_empty(to)
|
|| !square_is_empty(to)
|
||||||
|| !square_is_empty(from + DELTA_S))
|
|| !square_is_empty(from + DELTA_S))
|
||||||
return false;
|
return false;
|
||||||
|
@ -644,11 +644,11 @@ bool Position::move_is_pl(const Move m) const {
|
||||||
{
|
{
|
||||||
// In case of king moves under check we have to remove king so to catch
|
// In case of king moves under check we have to remove king so to catch
|
||||||
// as invalid moves like b1a1 when opposite queen is on c1.
|
// as invalid moves like b1a1 when opposite queen is on c1.
|
||||||
if (piece_type(piece_on(from)) == KING)
|
if (type_of(piece_on(from)) == KING)
|
||||||
{
|
{
|
||||||
Bitboard b = occupied_squares();
|
Bitboard b = occupied_squares();
|
||||||
clear_bit(&b, from);
|
clear_bit(&b, from);
|
||||||
if (attackers_to(move_to(m), b) & pieces(opposite_color(us)))
|
if (attackers_to(move_to(m), b) & pieces(flip(us)))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -676,11 +676,11 @@ bool Position::move_gives_check(Move m, const CheckInfo& ci) const {
|
||||||
|
|
||||||
assert(move_is_ok(m));
|
assert(move_is_ok(m));
|
||||||
assert(ci.dcCandidates == discovered_check_candidates());
|
assert(ci.dcCandidates == discovered_check_candidates());
|
||||||
assert(piece_color(piece_on(move_from(m))) == side_to_move());
|
assert(color_of(piece_on(move_from(m))) == side_to_move());
|
||||||
|
|
||||||
Square from = move_from(m);
|
Square from = move_from(m);
|
||||||
Square to = move_to(m);
|
Square to = move_to(m);
|
||||||
PieceType pt = piece_type(piece_on(from));
|
PieceType pt = type_of(piece_on(from));
|
||||||
|
|
||||||
// Direct check ?
|
// Direct check ?
|
||||||
if (bit_is_set(ci.checkSq[pt], to))
|
if (bit_is_set(ci.checkSq[pt], to))
|
||||||
|
@ -691,7 +691,7 @@ bool Position::move_gives_check(Move m, const CheckInfo& ci) const {
|
||||||
{
|
{
|
||||||
// For pawn and king moves we need to verify also direction
|
// For pawn and king moves we need to verify also direction
|
||||||
if ( (pt != PAWN && pt != KING)
|
if ( (pt != PAWN && pt != KING)
|
||||||
|| !squares_aligned(from, to, king_square(opposite_color(side_to_move()))))
|
|| !squares_aligned(from, to, king_square(flip(side_to_move()))))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -701,7 +701,7 @@ bool Position::move_gives_check(Move m, const CheckInfo& ci) const {
|
||||||
|
|
||||||
Color us = side_to_move();
|
Color us = side_to_move();
|
||||||
Bitboard b = occupied_squares();
|
Bitboard b = occupied_squares();
|
||||||
Square ksq = king_square(opposite_color(us));
|
Square ksq = king_square(flip(us));
|
||||||
|
|
||||||
// Promotion with check ?
|
// Promotion with check ?
|
||||||
if (move_is_promotion(m))
|
if (move_is_promotion(m))
|
||||||
|
@ -729,7 +729,7 @@ bool Position::move_gives_check(Move m, const CheckInfo& ci) const {
|
||||||
// the captured pawn.
|
// the captured pawn.
|
||||||
if (move_is_ep(m))
|
if (move_is_ep(m))
|
||||||
{
|
{
|
||||||
Square capsq = make_square(square_file(to), square_rank(from));
|
Square capsq = make_square(file_of(to), rank_of(from));
|
||||||
clear_bit(&b, from);
|
clear_bit(&b, from);
|
||||||
clear_bit(&b, capsq);
|
clear_bit(&b, capsq);
|
||||||
set_bit(&b, to);
|
set_bit(&b, to);
|
||||||
|
@ -813,18 +813,18 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI
|
||||||
}
|
}
|
||||||
|
|
||||||
Color us = side_to_move();
|
Color us = side_to_move();
|
||||||
Color them = opposite_color(us);
|
Color them = flip(us);
|
||||||
Square from = move_from(m);
|
Square from = move_from(m);
|
||||||
Square to = move_to(m);
|
Square to = move_to(m);
|
||||||
bool ep = move_is_ep(m);
|
bool ep = move_is_ep(m);
|
||||||
bool pm = move_is_promotion(m);
|
bool pm = move_is_promotion(m);
|
||||||
|
|
||||||
Piece piece = piece_on(from);
|
Piece piece = piece_on(from);
|
||||||
PieceType pt = piece_type(piece);
|
PieceType pt = type_of(piece);
|
||||||
PieceType capture = ep ? PAWN : piece_type(piece_on(to));
|
PieceType capture = ep ? PAWN : type_of(piece_on(to));
|
||||||
|
|
||||||
assert(piece_color(piece_on(from)) == us);
|
assert(color_of(piece_on(from)) == us);
|
||||||
assert(piece_color(piece_on(to)) == them || square_is_empty(to));
|
assert(color_of(piece_on(to)) == them || square_is_empty(to));
|
||||||
assert(!(ep || pm) || piece == make_piece(us, PAWN));
|
assert(!(ep || pm) || piece == make_piece(us, PAWN));
|
||||||
assert(!pm || relative_rank(us, to) == RANK_8);
|
assert(!pm || relative_rank(us, to) == RANK_8);
|
||||||
|
|
||||||
|
@ -967,7 +967,7 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finish
|
// Finish
|
||||||
sideToMove = opposite_color(sideToMove);
|
sideToMove = flip(sideToMove);
|
||||||
st->value += (sideToMove == WHITE ? TempoValue : -TempoValue);
|
st->value += (sideToMove == WHITE ? TempoValue : -TempoValue);
|
||||||
|
|
||||||
assert(is_ok());
|
assert(is_ok());
|
||||||
|
@ -992,7 +992,7 @@ void Position::do_capture_move(Key& key, PieceType capture, Color them, Square t
|
||||||
capsq = to + pawn_push(them);
|
capsq = to + pawn_push(them);
|
||||||
|
|
||||||
assert(to == st->epSquare);
|
assert(to == st->epSquare);
|
||||||
assert(relative_rank(opposite_color(them), to) == RANK_6);
|
assert(relative_rank(flip(them), to) == RANK_6);
|
||||||
assert(piece_on(to) == PIECE_NONE);
|
assert(piece_on(to) == PIECE_NONE);
|
||||||
assert(piece_on(capsq) == make_piece(them, PAWN));
|
assert(piece_on(capsq) == make_piece(them, PAWN));
|
||||||
|
|
||||||
|
@ -1048,7 +1048,7 @@ void Position::do_castle_move(Move m) {
|
||||||
assert(move_is_castle(m));
|
assert(move_is_castle(m));
|
||||||
|
|
||||||
Color us = side_to_move();
|
Color us = side_to_move();
|
||||||
Color them = opposite_color(us);
|
Color them = flip(us);
|
||||||
|
|
||||||
// Find source squares for king and rook
|
// Find source squares for king and rook
|
||||||
Square kfrom = move_from(m);
|
Square kfrom = move_from(m);
|
||||||
|
@ -1130,7 +1130,7 @@ void Position::do_castle_move(Move m) {
|
||||||
st->checkersBB = attackers_to(king_square(them)) & pieces(us);
|
st->checkersBB = attackers_to(king_square(them)) & pieces(us);
|
||||||
|
|
||||||
// Finish
|
// Finish
|
||||||
sideToMove = opposite_color(sideToMove);
|
sideToMove = flip(sideToMove);
|
||||||
st->value += (sideToMove == WHITE ? TempoValue : -TempoValue);
|
st->value += (sideToMove == WHITE ? TempoValue : -TempoValue);
|
||||||
|
|
||||||
assert(is_ok());
|
assert(is_ok());
|
||||||
|
@ -1144,7 +1144,7 @@ void Position::undo_move(Move m) {
|
||||||
|
|
||||||
assert(move_is_ok(m));
|
assert(move_is_ok(m));
|
||||||
|
|
||||||
sideToMove = opposite_color(sideToMove);
|
sideToMove = flip(sideToMove);
|
||||||
|
|
||||||
if (move_is_castle(m))
|
if (move_is_castle(m))
|
||||||
{
|
{
|
||||||
|
@ -1153,16 +1153,16 @@ void Position::undo_move(Move m) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Color us = side_to_move();
|
Color us = side_to_move();
|
||||||
Color them = opposite_color(us);
|
Color them = flip(us);
|
||||||
Square from = move_from(m);
|
Square from = move_from(m);
|
||||||
Square to = move_to(m);
|
Square to = move_to(m);
|
||||||
bool ep = move_is_ep(m);
|
bool ep = move_is_ep(m);
|
||||||
bool pm = move_is_promotion(m);
|
bool pm = move_is_promotion(m);
|
||||||
|
|
||||||
PieceType pt = piece_type(piece_on(to));
|
PieceType pt = type_of(piece_on(to));
|
||||||
|
|
||||||
assert(square_is_empty(from));
|
assert(square_is_empty(from));
|
||||||
assert(piece_color(piece_on(to)) == us);
|
assert(color_of(piece_on(to)) == us);
|
||||||
assert(!pm || relative_rank(us, to) == RANK_8);
|
assert(!pm || relative_rank(us, to) == RANK_8);
|
||||||
assert(!ep || to == st->previous->epSquare);
|
assert(!ep || to == st->previous->epSquare);
|
||||||
assert(!ep || relative_rank(us, to) == RANK_6);
|
assert(!ep || relative_rank(us, to) == RANK_6);
|
||||||
|
@ -1335,7 +1335,7 @@ void Position::do_null_move(StateInfo& backupSt) {
|
||||||
st->key ^= zobSideToMove;
|
st->key ^= zobSideToMove;
|
||||||
prefetch((char*)TT.first_entry(st->key));
|
prefetch((char*)TT.first_entry(st->key));
|
||||||
|
|
||||||
sideToMove = opposite_color(sideToMove);
|
sideToMove = flip(sideToMove);
|
||||||
st->epSquare = SQ_NONE;
|
st->epSquare = SQ_NONE;
|
||||||
st->rule50++;
|
st->rule50++;
|
||||||
st->pliesFromNull = 0;
|
st->pliesFromNull = 0;
|
||||||
|
@ -1360,7 +1360,7 @@ void Position::undo_null_move() {
|
||||||
st->pliesFromNull = backupSt->pliesFromNull;
|
st->pliesFromNull = backupSt->pliesFromNull;
|
||||||
|
|
||||||
// Update the necessary information
|
// Update the necessary information
|
||||||
sideToMove = opposite_color(sideToMove);
|
sideToMove = flip(sideToMove);
|
||||||
st->rule50--;
|
st->rule50--;
|
||||||
|
|
||||||
assert(is_ok());
|
assert(is_ok());
|
||||||
|
@ -1407,16 +1407,16 @@ int Position::see(Move m) const {
|
||||||
|
|
||||||
from = move_from(m);
|
from = move_from(m);
|
||||||
to = move_to(m);
|
to = move_to(m);
|
||||||
capturedType = piece_type(piece_on(to));
|
capturedType = type_of(piece_on(to));
|
||||||
occupied = occupied_squares();
|
occupied = occupied_squares();
|
||||||
|
|
||||||
// Handle en passant moves
|
// Handle en passant moves
|
||||||
if (st->epSquare == to && piece_type(piece_on(from)) == PAWN)
|
if (st->epSquare == to && type_of(piece_on(from)) == PAWN)
|
||||||
{
|
{
|
||||||
Square capQq = to - pawn_push(side_to_move());
|
Square capQq = to - pawn_push(side_to_move());
|
||||||
|
|
||||||
assert(capturedType == PIECE_TYPE_NONE);
|
assert(capturedType == PIECE_TYPE_NONE);
|
||||||
assert(piece_type(piece_on(capQq)) == PAWN);
|
assert(type_of(piece_on(capQq)) == PAWN);
|
||||||
|
|
||||||
// Remove the captured pawn
|
// Remove the captured pawn
|
||||||
clear_bit(&occupied, capQq);
|
clear_bit(&occupied, capQq);
|
||||||
|
@ -1429,7 +1429,7 @@ int Position::see(Move m) const {
|
||||||
attackers = attackers_to(to, occupied);
|
attackers = attackers_to(to, occupied);
|
||||||
|
|
||||||
// If the opponent has no attackers we are finished
|
// If the opponent has no attackers we are finished
|
||||||
stm = opposite_color(piece_color(piece_on(from)));
|
stm = flip(color_of(piece_on(from)));
|
||||||
stmAttackers = attackers & pieces(stm);
|
stmAttackers = attackers & pieces(stm);
|
||||||
if (!stmAttackers)
|
if (!stmAttackers)
|
||||||
return PieceValueMidgame[capturedType];
|
return PieceValueMidgame[capturedType];
|
||||||
|
@ -1441,7 +1441,7 @@ int Position::see(Move m) const {
|
||||||
// capture with the least valuable piece. After each capture, we look for
|
// capture with the least valuable piece. After each capture, we look for
|
||||||
// new X-ray attacks from behind the capturing piece.
|
// new X-ray attacks from behind the capturing piece.
|
||||||
swapList[0] = PieceValueMidgame[capturedType];
|
swapList[0] = PieceValueMidgame[capturedType];
|
||||||
capturedType = piece_type(piece_on(from));
|
capturedType = type_of(piece_on(from));
|
||||||
|
|
||||||
do {
|
do {
|
||||||
// Locate the least valuable attacker for the side to move. The loop
|
// Locate the least valuable attacker for the side to move. The loop
|
||||||
|
@ -1467,7 +1467,7 @@ int Position::see(Move m) const {
|
||||||
// Remember the value of the capturing piece, and change the side to
|
// Remember the value of the capturing piece, and change the side to
|
||||||
// move before beginning the next iteration.
|
// move before beginning the next iteration.
|
||||||
capturedType = pt;
|
capturedType = pt;
|
||||||
stm = opposite_color(stm);
|
stm = flip(stm);
|
||||||
stmAttackers = attackers & pieces(stm);
|
stmAttackers = attackers & pieces(stm);
|
||||||
|
|
||||||
// Stop before processing a king capture
|
// Stop before processing a king capture
|
||||||
|
@ -1521,8 +1521,8 @@ void Position::clear() {
|
||||||
|
|
||||||
void Position::put_piece(Piece p, Square s) {
|
void Position::put_piece(Piece p, Square s) {
|
||||||
|
|
||||||
Color c = piece_color(p);
|
Color c = color_of(p);
|
||||||
PieceType pt = piece_type(p);
|
PieceType pt = type_of(p);
|
||||||
|
|
||||||
board[s] = p;
|
board[s] = p;
|
||||||
index[s] = pieceCount[c][pt]++;
|
index[s] = pieceCount[c][pt]++;
|
||||||
|
@ -1545,7 +1545,7 @@ Key Position::compute_key() const {
|
||||||
|
|
||||||
for (Square s = SQ_A1; s <= SQ_H8; s++)
|
for (Square s = SQ_A1; s <= SQ_H8; s++)
|
||||||
if (!square_is_empty(s))
|
if (!square_is_empty(s))
|
||||||
result ^= zobrist[piece_color(piece_on(s))][piece_type(piece_on(s))][s];
|
result ^= zobrist[color_of(piece_on(s))][type_of(piece_on(s))][s];
|
||||||
|
|
||||||
if (ep_square() != SQ_NONE)
|
if (ep_square() != SQ_NONE)
|
||||||
result ^= zobEp[ep_square()];
|
result ^= zobEp[ep_square()];
|
||||||
|
@ -1692,7 +1692,7 @@ bool Position::is_mate() const {
|
||||||
/// startup the various arrays used to compute hash keys and the piece
|
/// startup the various arrays used to compute hash keys and the piece
|
||||||
/// square tables. The latter is a two-step operation: First, the white
|
/// square tables. The latter is a two-step operation: First, the white
|
||||||
/// halves of the tables are copied from the MgPST[][] and EgPST[][] arrays.
|
/// halves of the tables are copied from the MgPST[][] and EgPST[][] arrays.
|
||||||
/// Second, the black halves of the tables are initialized by mirroring
|
/// Second, the black halves of the tables are initialized by flipping
|
||||||
/// and changing the sign of the corresponding white scores.
|
/// and changing the sign of the corresponding white scores.
|
||||||
|
|
||||||
void Position::init() {
|
void Position::init() {
|
||||||
|
@ -1713,20 +1713,19 @@ void Position::init() {
|
||||||
zobSideToMove = rk.rand<Key>();
|
zobSideToMove = rk.rand<Key>();
|
||||||
zobExclusion = rk.rand<Key>();
|
zobExclusion = rk.rand<Key>();
|
||||||
|
|
||||||
for (Square s = SQ_A1; s <= SQ_H8; s++)
|
for (Piece p = WP; p <= WK; p++)
|
||||||
for (Piece p = WP; p <= WK; p++)
|
for (Square s = SQ_A1; s <= SQ_H8; s++)
|
||||||
|
{
|
||||||
pieceSquareTable[p][s] = make_score(MgPST[p][s], EgPST[p][s]);
|
pieceSquareTable[p][s] = make_score(MgPST[p][s], EgPST[p][s]);
|
||||||
|
pieceSquareTable[p+8][flip(s)] = -pieceSquareTable[p][s];
|
||||||
for (Square s = SQ_A1; s <= SQ_H8; s++)
|
}
|
||||||
for (Piece p = BP; p <= BK; p++)
|
|
||||||
pieceSquareTable[p][s] = -pieceSquareTable[p-8][flip_square(s)];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Position::flip() flips position with the white and black sides reversed. This
|
/// Position::flip_me() flips position with the white and black sides reversed. This
|
||||||
/// is only useful for debugging especially for finding evaluation symmetry bugs.
|
/// is only useful for debugging especially for finding evaluation symmetry bugs.
|
||||||
|
|
||||||
void Position::flip() {
|
void Position::flip_me() {
|
||||||
|
|
||||||
// Make a copy of current position before to start changing
|
// Make a copy of current position before to start changing
|
||||||
const Position pos(*this, threadID);
|
const Position pos(*this, threadID);
|
||||||
|
@ -1737,27 +1736,27 @@ void Position::flip() {
|
||||||
// Board
|
// Board
|
||||||
for (Square s = SQ_A1; s <= SQ_H8; s++)
|
for (Square s = SQ_A1; s <= SQ_H8; s++)
|
||||||
if (!pos.square_is_empty(s))
|
if (!pos.square_is_empty(s))
|
||||||
put_piece(Piece(pos.piece_on(s) ^ 8), flip_square(s));
|
put_piece(Piece(pos.piece_on(s) ^ 8), flip(s));
|
||||||
|
|
||||||
// Side to move
|
// Side to move
|
||||||
sideToMove = opposite_color(pos.side_to_move());
|
sideToMove = flip(pos.side_to_move());
|
||||||
|
|
||||||
// Castling rights
|
// Castling rights
|
||||||
if (pos.can_castle(WHITE_OO))
|
if (pos.can_castle(WHITE_OO))
|
||||||
set_castle(BLACK_OO, king_square(BLACK), flip_square(pos.castle_rook_square(WHITE_OO)));
|
set_castle(BLACK_OO, king_square(BLACK), flip(pos.castle_rook_square(WHITE_OO)));
|
||||||
if (pos.can_castle(WHITE_OOO))
|
if (pos.can_castle(WHITE_OOO))
|
||||||
set_castle(BLACK_OOO, king_square(BLACK), flip_square(pos.castle_rook_square(WHITE_OOO)));
|
set_castle(BLACK_OOO, king_square(BLACK), flip(pos.castle_rook_square(WHITE_OOO)));
|
||||||
if (pos.can_castle(BLACK_OO))
|
if (pos.can_castle(BLACK_OO))
|
||||||
set_castle(WHITE_OO, king_square(WHITE), flip_square(pos.castle_rook_square(BLACK_OO)));
|
set_castle(WHITE_OO, king_square(WHITE), flip(pos.castle_rook_square(BLACK_OO)));
|
||||||
if (pos.can_castle(BLACK_OOO))
|
if (pos.can_castle(BLACK_OOO))
|
||||||
set_castle(WHITE_OOO, king_square(WHITE), flip_square(pos.castle_rook_square(BLACK_OOO)));
|
set_castle(WHITE_OOO, king_square(WHITE), flip(pos.castle_rook_square(BLACK_OOO)));
|
||||||
|
|
||||||
// En passant square
|
// En passant square
|
||||||
if (pos.st->epSquare != SQ_NONE)
|
if (pos.st->epSquare != SQ_NONE)
|
||||||
st->epSquare = flip_square(pos.st->epSquare);
|
st->epSquare = flip(pos.st->epSquare);
|
||||||
|
|
||||||
// Checkers
|
// Checkers
|
||||||
st->checkersBB = attackers_to(king_square(sideToMove)) & pieces(opposite_color(sideToMove));
|
st->checkersBB = attackers_to(king_square(sideToMove)) & pieces(flip(sideToMove));
|
||||||
|
|
||||||
// Hash keys
|
// Hash keys
|
||||||
st->key = compute_key();
|
st->key = compute_key();
|
||||||
|
@ -1817,8 +1816,8 @@ bool Position::is_ok(int* failedStep) const {
|
||||||
{
|
{
|
||||||
int kingCount[2] = {0, 0};
|
int kingCount[2] = {0, 0};
|
||||||
for (Square s = SQ_A1; s <= SQ_H8; s++)
|
for (Square s = SQ_A1; s <= SQ_H8; s++)
|
||||||
if (piece_type(piece_on(s)) == KING)
|
if (type_of(piece_on(s)) == KING)
|
||||||
kingCount[piece_color(piece_on(s))]++;
|
kingCount[color_of(piece_on(s))]++;
|
||||||
|
|
||||||
if (kingCount[0] != 1 || kingCount[1] != 1)
|
if (kingCount[0] != 1 || kingCount[1] != 1)
|
||||||
return false;
|
return false;
|
||||||
|
@ -1829,7 +1828,7 @@ bool Position::is_ok(int* failedStep) const {
|
||||||
if (debugKingCapture)
|
if (debugKingCapture)
|
||||||
{
|
{
|
||||||
Color us = side_to_move();
|
Color us = side_to_move();
|
||||||
Color them = opposite_color(us);
|
Color them = flip(us);
|
||||||
Square ksq = king_square(them);
|
Square ksq = king_square(them);
|
||||||
if (attackers_to(ksq) & pieces(us))
|
if (attackers_to(ksq) & pieces(us))
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -204,7 +204,7 @@ public:
|
||||||
|
|
||||||
// Position consistency check, for debugging
|
// Position consistency check, for debugging
|
||||||
bool is_ok(int* failedStep = NULL) const;
|
bool is_ok(int* failedStep = NULL) const;
|
||||||
void flip();
|
void flip_me();
|
||||||
|
|
||||||
// Global initialization
|
// Global initialization
|
||||||
static void init();
|
static void init();
|
||||||
|
@ -380,7 +380,7 @@ inline bool Position::in_check() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Position::pawn_is_passed(Color c, Square s) const {
|
inline bool Position::pawn_is_passed(Color c, Square s) const {
|
||||||
return !(pieces(PAWN, opposite_color(c)) & passed_pawn_mask(c, s));
|
return !(pieces(PAWN, flip(c)) & passed_pawn_mask(c, s));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Key Position::get_key() const {
|
inline Key Position::get_key() const {
|
||||||
|
|
|
@ -270,7 +270,7 @@ namespace {
|
||||||
if (moveIsCheck && pos.see_sign(m) >= 0)
|
if (moveIsCheck && pos.see_sign(m) >= 0)
|
||||||
result += CheckExtension[PvNode];
|
result += CheckExtension[PvNode];
|
||||||
|
|
||||||
if (piece_type(pos.piece_on(move_from(m))) == PAWN)
|
if (type_of(pos.piece_on(move_from(m))) == PAWN)
|
||||||
{
|
{
|
||||||
Color c = pos.side_to_move();
|
Color c = pos.side_to_move();
|
||||||
if (relative_rank(c, move_to(m)) == RANK_7)
|
if (relative_rank(c, move_to(m)) == RANK_7)
|
||||||
|
@ -286,7 +286,7 @@ namespace {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( captureOrPromotion
|
if ( captureOrPromotion
|
||||||
&& piece_type(pos.piece_on(move_to(m))) != PAWN
|
&& type_of(pos.piece_on(move_to(m))) != PAWN
|
||||||
&& ( pos.non_pawn_material(WHITE) + pos.non_pawn_material(BLACK)
|
&& ( pos.non_pawn_material(WHITE) + pos.non_pawn_material(BLACK)
|
||||||
- piece_value_midgame(pos.piece_on(move_to(m))) == VALUE_ZERO)
|
- piece_value_midgame(pos.piece_on(move_to(m))) == VALUE_ZERO)
|
||||||
&& !move_is_special(m))
|
&& !move_is_special(m))
|
||||||
|
@ -1493,7 +1493,7 @@ split_point_start: // At split points actual search starts from here
|
||||||
|
|
||||||
from = move_from(move);
|
from = move_from(move);
|
||||||
to = move_to(move);
|
to = move_to(move);
|
||||||
them = opposite_color(pos.side_to_move());
|
them = flip(pos.side_to_move());
|
||||||
ksq = pos.king_square(them);
|
ksq = pos.king_square(them);
|
||||||
kingAtt = pos.attacks_from<KING>(ksq);
|
kingAtt = pos.attacks_from<KING>(ksq);
|
||||||
pc = pos.piece_on(from);
|
pc = pos.piece_on(from);
|
||||||
|
@ -1509,7 +1509,7 @@ split_point_start: // At split points actual search starts from here
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// Rule 2. Queen contact check is very dangerous
|
// Rule 2. Queen contact check is very dangerous
|
||||||
if ( piece_type(pc) == QUEEN
|
if ( type_of(pc) == QUEEN
|
||||||
&& bit_is_set(kingAtt, to))
|
&& bit_is_set(kingAtt, to))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
@ -1644,7 +1644,7 @@ split_point_start: // At split points actual search starts from here
|
||||||
// value of the threatening piece, don't prune moves which defend it.
|
// value of the threatening piece, don't prune moves which defend it.
|
||||||
if ( pos.move_is_capture(threat)
|
if ( pos.move_is_capture(threat)
|
||||||
&& ( piece_value_midgame(pos.piece_on(tfrom)) >= piece_value_midgame(pos.piece_on(tto))
|
&& ( piece_value_midgame(pos.piece_on(tfrom)) >= piece_value_midgame(pos.piece_on(tto))
|
||||||
|| piece_type(pos.piece_on(tfrom)) == KING)
|
|| type_of(pos.piece_on(tfrom)) == KING)
|
||||||
&& pos.move_attacks_square(m, tto))
|
&& pos.move_attacks_square(m, tto))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
|
24
src/types.h
24
src/types.h
|
@ -370,15 +370,15 @@ inline Piece make_piece(Color c, PieceType pt) {
|
||||||
return Piece((c << 3) | pt);
|
return Piece((c << 3) | pt);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline PieceType piece_type(Piece p) {
|
inline PieceType type_of(Piece p) {
|
||||||
return PieceType(p & 7);
|
return PieceType(p & 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Color piece_color(Piece p) {
|
inline Color color_of(Piece p) {
|
||||||
return Color(p >> 3);
|
return Color(p >> 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Color opposite_color(Color c) {
|
inline Color flip(Color c) {
|
||||||
return Color(c ^ 1);
|
return Color(c ^ 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -395,19 +395,19 @@ inline bool square_is_ok(Square s) {
|
||||||
return s >= SQ_A1 && s <= SQ_H8;
|
return s >= SQ_A1 && s <= SQ_H8;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline File square_file(Square s) {
|
inline File file_of(Square s) {
|
||||||
return File(s & 7);
|
return File(s & 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Rank square_rank(Square s) {
|
inline Rank rank_of(Square s) {
|
||||||
return Rank(s >> 3);
|
return Rank(s >> 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Square flip_square(Square s) {
|
inline Square flip(Square s) {
|
||||||
return Square(s ^ 56);
|
return Square(s ^ 56);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Square flop_square(Square s) {
|
inline Square mirror(Square s) {
|
||||||
return Square(s ^ 7);
|
return Square(s ^ 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -420,11 +420,11 @@ inline Rank relative_rank(Color c, Rank r) {
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Rank relative_rank(Color c, Square s) {
|
inline Rank relative_rank(Color c, Square s) {
|
||||||
return relative_rank(c, square_rank(s));
|
return relative_rank(c, rank_of(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline SquareColor square_color(Square s) {
|
inline SquareColor square_color(Square s) {
|
||||||
return SquareColor(int(square_rank(s) + s) & 1);
|
return SquareColor(int(rank_of(s) + s) & 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool opposite_color_squares(Square s1, Square s2) {
|
inline bool opposite_color_squares(Square s1, Square s2) {
|
||||||
|
@ -433,11 +433,11 @@ inline bool opposite_color_squares(Square s1, Square s2) {
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int file_distance(Square s1, Square s2) {
|
inline int file_distance(Square s1, Square s2) {
|
||||||
return abs(square_file(s1) - square_file(s2));
|
return abs(file_of(s1) - file_of(s2));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int rank_distance(Square s1, Square s2) {
|
inline int rank_distance(Square s1, Square s2) {
|
||||||
return abs(square_rank(s1) - square_rank(s2));
|
return abs(rank_of(s1) - rank_of(s2));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int square_distance(Square s1, Square s2) {
|
inline int square_distance(Square s1, Square s2) {
|
||||||
|
@ -453,7 +453,7 @@ inline char rank_to_char(Rank r) {
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const std::string square_to_string(Square s) {
|
inline const std::string square_to_string(Square s) {
|
||||||
char ch[] = { file_to_char(square_file(s)), rank_to_char(square_rank(s)), 0 };
|
char ch[] = { file_to_char(file_of(s)), rank_to_char(rank_of(s)), 0 };
|
||||||
return std::string(ch);
|
return std::string(ch);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -91,7 +91,7 @@ void uci_loop() {
|
||||||
pos.print();
|
pos.print();
|
||||||
|
|
||||||
else if (token == "flip")
|
else if (token == "flip")
|
||||||
pos.flip();
|
pos.flip_me();
|
||||||
|
|
||||||
else if (token == "eval")
|
else if (token == "eval")
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue