Rename shift_bb() to shift()

Rename shift_bb() to shift(), and DELTA_S to SOUTH, etc.
to improve code readability, especially in evaluate.cpp
when they are used together:

    old b = shift_bb<DELTA_S>(pos.pieces(PAWN))
    new b = shift<SOUTH>(pos.pieces(PAWN))

While there fix some small code style issues.

No functional change.
This commit is contained in:
Stéphane Nicolet
2016-09-23 19:28:34 +02:00
committed by Marco Costalba
parent 351844061e
commit 7ae3c05795
12 changed files with 103 additions and 100 deletions

View File

@@ -123,9 +123,9 @@ namespace {
// Immediate win if a pawn can be promoted without getting captured // Immediate win if a pawn can be promoted without getting captured
else if ( us == WHITE else if ( us == WHITE
&& rank_of(psq) == RANK_7 && rank_of(psq) == RANK_7
&& ksq[us] != psq + DELTA_N && ksq[us] != psq + NORTH
&& ( distance(ksq[~us], psq + DELTA_N) > 1 && ( distance(ksq[~us], psq + NORTH) > 1
|| (StepAttacksBB[KING][ksq[us]] & (psq + DELTA_N)))) || (StepAttacksBB[KING][ksq[us]] & (psq + NORTH))))
result = WIN; result = WIN;
// Immediate draw if it is a stalemate or a king captures undefended pawn // Immediate draw if it is a stalemate or a king captures undefended pawn
@@ -166,12 +166,12 @@ namespace {
if (Us == WHITE) if (Us == WHITE)
{ {
if (rank_of(psq) < RANK_7) // Single push if (rank_of(psq) < RANK_7) // Single push
r |= db[index(Them, ksq[Them], ksq[Us], psq + DELTA_N)]; r |= db[index(Them, ksq[Them], ksq[Us], psq + NORTH)];
if ( rank_of(psq) == RANK_2 // Double push if ( rank_of(psq) == RANK_2 // Double push
&& psq + DELTA_N != ksq[Us] && psq + NORTH != ksq[Us]
&& psq + DELTA_N != ksq[Them]) && psq + NORTH != ksq[Them])
r |= db[index(Them, ksq[Them], ksq[Us], psq + DELTA_N + DELTA_N)]; r |= db[index(Them, ksq[Them], ksq[Us], psq + NORTH + NORTH)];
} }
return result = r & Good ? Good : r & UNKNOWN ? UNKNOWN : Bad; return result = r & Good ? Good : r & UNKNOWN ? UNKNOWN : Bad;

View File

@@ -205,8 +205,8 @@ void Bitboards::init() {
StepAttacksBB[make_piece(c, pt)][s] |= to; StepAttacksBB[make_piece(c, pt)][s] |= to;
} }
Square RookDeltas[] = { DELTA_N, DELTA_E, DELTA_S, DELTA_W }; Square RookDeltas[] = { NORTH, EAST, SOUTH, WEST };
Square BishopDeltas[] = { DELTA_NE, DELTA_SE, DELTA_SW, DELTA_NW }; Square BishopDeltas[] = { NORTH_EAST, SOUTH_EAST, SOUTH_WEST, NORTH_WEST };
init_magics(RookTable, RookAttacks, RookMagics, RookMasks, RookShifts, RookDeltas, magic_index<ROOK>); init_magics(RookTable, RookAttacks, RookMagics, RookMasks, RookShifts, RookDeltas, magic_index<ROOK>);
init_magics(BishopTable, BishopAttacks, BishopMagics, BishopMasks, BishopShifts, BishopDeltas, magic_index<BISHOP>); init_magics(BishopTable, BishopAttacks, BishopMagics, BishopMasks, BishopShifts, BishopDeltas, magic_index<BISHOP>);

View File

@@ -124,13 +124,13 @@ inline Bitboard file_bb(Square s) {
} }
/// shift_bb() moves a bitboard one step along direction Delta. Mainly for pawns /// shift() moves a bitboard one step along direction D. Mainly for pawns
template<Square Delta> template<Square D>
inline Bitboard shift_bb(Bitboard b) { inline Bitboard shift(Bitboard b) {
return Delta == DELTA_N ? b << 8 : Delta == DELTA_S ? b >> 8 return D == NORTH ? b << 8 : D == SOUTH ? b >> 8
: Delta == DELTA_NE ? (b & ~FileHBB) << 9 : Delta == DELTA_SE ? (b & ~FileHBB) >> 7 : D == NORTH_EAST ? (b & ~FileHBB) << 9 : D == SOUTH_EAST ? (b & ~FileHBB) >> 7
: Delta == DELTA_NW ? (b & ~FileABB) << 7 : Delta == DELTA_SW ? (b & ~FileABB) >> 9 : D == NORTH_WEST ? (b & ~FileABB) << 7 : D == SOUTH_WEST ? (b & ~FileABB) >> 9
: 0; : 0;
} }

View File

@@ -259,8 +259,8 @@ Value Endgame<KRKP>::operator()(const Position& pos) const {
result = Value(80) - 8 * distance(wksq, psq); result = Value(80) - 8 * distance(wksq, psq);
else else
result = Value(200) - 8 * ( distance(wksq, psq + DELTA_S) result = Value(200) - 8 * ( distance(wksq, psq + SOUTH)
- distance(bksq, psq + DELTA_S) - distance(bksq, psq + SOUTH)
- distance(psq, queeningSq)); - distance(psq, queeningSq));
return strongSide == pos.side_to_move() ? result : -result; return strongSide == pos.side_to_move() ? result : -result;
@@ -496,7 +496,7 @@ ScaleFactor Endgame<KRPKR>::operator()(const Position& pos) const {
// 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
// away, it's a draw. // away, it's a draw.
if ( r <= RANK_5 if ( r <= RANK_5
&& bksq == wpsq + DELTA_N && bksq == wpsq + NORTH
&& distance(wksq, wpsq) - tempo >= 2 && distance(wksq, wpsq) - tempo >= 2
&& distance(wksq, brsq) - tempo >= 2) && distance(wksq, brsq) - tempo >= 2)
return SCALE_FACTOR_DRAW; return SCALE_FACTOR_DRAW;
@@ -517,10 +517,10 @@ ScaleFactor Endgame<KRPKR>::operator()(const Position& pos) const {
&& file_of(wrsq) == f && file_of(wrsq) == f
&& wrsq < wpsq && wrsq < wpsq
&& (distance(wksq, queeningSq) < distance(bksq, queeningSq) - 2 + tempo) && (distance(wksq, queeningSq) < distance(bksq, queeningSq) - 2 + tempo)
&& (distance(wksq, wpsq + DELTA_N) < distance(bksq, wpsq + DELTA_N) - 2 + tempo) && (distance(wksq, wpsq + NORTH) < distance(bksq, wpsq + NORTH) - 2 + tempo)
&& ( distance(bksq, wrsq) + tempo >= 3 && ( distance(bksq, wrsq) + tempo >= 3
|| ( distance(wksq, queeningSq) < distance(bksq, wrsq) + tempo || ( distance(wksq, queeningSq) < distance(bksq, wrsq) + tempo
&& (distance(wksq, wpsq + DELTA_N) < distance(bksq, wrsq) + tempo)))) && (distance(wksq, wpsq + NORTH) < distance(bksq, wrsq) + tempo))))
return ScaleFactor( SCALE_FACTOR_MAX return ScaleFactor( SCALE_FACTOR_MAX
- 8 * distance(wpsq, queeningSq) - 8 * distance(wpsq, queeningSq)
- 2 * distance(wksq, queeningSq)); - 2 * distance(wksq, queeningSq));

View File

@@ -156,7 +156,8 @@ namespace {
// ThreatBySafePawn[PieceType] contains bonuses according to which piece // ThreatBySafePawn[PieceType] contains bonuses according to which piece
// type is attacked by a pawn which is protected or is not attacked. // type is attacked by a pawn which is protected or is not attacked.
const Score ThreatBySafePawn[PIECE_TYPE_NB] = { const Score ThreatBySafePawn[PIECE_TYPE_NB] = {
S(0, 0), S(0, 0), S(176, 139), S(131, 127), S(217, 218), S(203, 215) }; S(0, 0), S(0, 0), S(176, 139), S(131, 127), S(217, 218), S(203, 215)
};
// Threat[by minor/by rook][attacked PieceType] contains // Threat[by minor/by rook][attacked PieceType] contains
// bonuses according to which piece type attacks which one. // bonuses according to which piece type attacks which one.
@@ -223,8 +224,8 @@ namespace {
template<Color Us> template<Color Us>
void eval_init(const Position& pos, EvalInfo& ei) { void eval_init(const Position& pos, EvalInfo& ei) {
const Color Them = (Us == WHITE ? BLACK : WHITE); const Color Them = (Us == WHITE ? BLACK : WHITE);
const Square Down = (Us == WHITE ? DELTA_S : DELTA_N); const Square Down = (Us == WHITE ? SOUTH : NORTH);
ei.pinnedPieces[Us] = pos.pinned_pieces(Us); ei.pinnedPieces[Us] = pos.pinned_pieces(Us);
Bitboard b = ei.attackedBy[Them][KING]; Bitboard b = ei.attackedBy[Them][KING];
@@ -235,7 +236,7 @@ namespace {
// Init king safety tables only if we are going to use them // Init king safety tables only if we are going to use them
if (pos.non_pawn_material(Us) >= QueenValueMg) if (pos.non_pawn_material(Us) >= QueenValueMg)
{ {
ei.kingRing[Them] = b | shift_bb<Down>(b); ei.kingRing[Them] = b | shift<Down>(b);
b &= ei.attackedBy[Us][PAWN]; b &= ei.attackedBy[Us][PAWN];
ei.kingAttackersCount[Us] = popcount(b); ei.kingAttackersCount[Us] = popcount(b);
ei.kingAdjacentZoneAttacksCount[Us] = ei.kingAttackersWeight[Us] = 0; ei.kingAdjacentZoneAttacksCount[Us] = ei.kingAttackersWeight[Us] = 0;
@@ -321,7 +322,7 @@ namespace {
&& pos.is_chess960() && pos.is_chess960()
&& (s == relative_square(Us, SQ_A1) || s == relative_square(Us, SQ_H1))) && (s == relative_square(Us, SQ_A1) || s == relative_square(Us, SQ_H1)))
{ {
Square d = pawn_push(Us) + (file_of(s) == FILE_A ? DELTA_E : DELTA_W); Square d = pawn_push(Us) + (file_of(s) == FILE_A ? EAST : WEST);
if (pos.piece_on(s + d) == make_piece(Us, PAWN)) if (pos.piece_on(s + d) == make_piece(Us, PAWN))
score -= !pos.empty(s + d + pawn_push(Us)) ? TrappedBishopA1H1 * 4 score -= !pos.empty(s + d + pawn_push(Us)) ? TrappedBishopA1H1 * 4
: pos.piece_on(s + d + d) == make_piece(Us, PAWN) ? TrappedBishopA1H1 * 2 : pos.piece_on(s + d + d) == make_piece(Us, PAWN) ? TrappedBishopA1H1 * 2
@@ -391,8 +392,8 @@ namespace {
template<Color Us, bool DoTrace> template<Color Us, bool DoTrace>
Score evaluate_king(const Position& pos, const EvalInfo& ei) { Score evaluate_king(const Position& pos, const EvalInfo& ei) {
const Color Them = (Us == WHITE ? BLACK : WHITE); const Color Them = (Us == WHITE ? BLACK : WHITE);
const Square Up = (Us == WHITE ? DELTA_N : DELTA_S); const Square Up = (Us == WHITE ? NORTH : SOUTH);
Bitboard undefended, b, b1, b2, safe, other; Bitboard undefended, b, b1, b2, safe, other;
int kingDanger; int kingDanger;
@@ -438,7 +439,7 @@ namespace {
// ... and some other potential checks, only requiring the square to be // ... and some other potential checks, only requiring the square to be
// safe from pawn-attacks, and not being occupied by a blocked pawn. // safe from pawn-attacks, and not being occupied by a blocked pawn.
other = ~( ei.attackedBy[Us][PAWN] other = ~( ei.attackedBy[Us][PAWN]
| (pos.pieces(Them, PAWN) & shift_bb<Up>(pos.pieces(PAWN)))); | (pos.pieces(Them, PAWN) & shift<Up>(pos.pieces(PAWN))));
b1 = pos.attacks_from<ROOK >(ksq); b1 = pos.attacks_from<ROOK >(ksq);
b2 = pos.attacks_from<BISHOP>(ksq); b2 = pos.attacks_from<BISHOP>(ksq);
@@ -506,12 +507,12 @@ namespace {
template<Color Us, bool DoTrace> template<Color Us, bool DoTrace>
Score evaluate_threats(const Position& pos, const EvalInfo& ei) { Score evaluate_threats(const Position& pos, const EvalInfo& ei) {
const Color Them = (Us == WHITE ? BLACK : WHITE); const Color Them = (Us == WHITE ? BLACK : WHITE);
const Square Up = (Us == WHITE ? DELTA_N : DELTA_S); const Square Up = (Us == WHITE ? NORTH : SOUTH);
const Square Left = (Us == WHITE ? DELTA_NW : DELTA_SE); const Square Left = (Us == WHITE ? NORTH_WEST : SOUTH_EAST);
const Square Right = (Us == WHITE ? DELTA_NE : DELTA_SW); const Square Right = (Us == WHITE ? NORTH_EAST : SOUTH_WEST);
const Bitboard TRank2BB = (Us == WHITE ? Rank2BB : Rank7BB); const Bitboard TRank2BB = (Us == WHITE ? Rank2BB : Rank7BB);
const Bitboard TRank7BB = (Us == WHITE ? Rank7BB : Rank2BB); const Bitboard TRank7BB = (Us == WHITE ? Rank7BB : Rank2BB);
enum { Minor, Rook }; enum { Minor, Rook };
@@ -531,7 +532,7 @@ namespace {
b = pos.pieces(Us, PAWN) & ( ~ei.attackedBy[Them][ALL_PIECES] b = pos.pieces(Us, PAWN) & ( ~ei.attackedBy[Them][ALL_PIECES]
| ei.attackedBy[Us][ALL_PIECES]); | ei.attackedBy[Us][ALL_PIECES]);
safeThreats = (shift_bb<Right>(b) | shift_bb<Left>(b)) & weak; safeThreats = (shift<Right>(b) | shift<Left>(b)) & weak;
if (weak ^ safeThreats) if (weak ^ safeThreats)
score += ThreatByHangingPawn; score += ThreatByHangingPawn;
@@ -568,13 +569,13 @@ namespace {
// Bonus if some pawns can safely push and attack an enemy piece // Bonus if some pawns can safely push and attack an enemy piece
b = pos.pieces(Us, PAWN) & ~TRank7BB; b = pos.pieces(Us, PAWN) & ~TRank7BB;
b = shift_bb<Up>(b | (shift_bb<Up>(b & TRank2BB) & ~pos.pieces())); b = shift<Up>(b | (shift<Up>(b & TRank2BB) & ~pos.pieces()));
b &= ~pos.pieces() b &= ~pos.pieces()
& ~ei.attackedBy[Them][PAWN] & ~ei.attackedBy[Them][PAWN]
& (ei.attackedBy[Us][ALL_PIECES] | ~ei.attackedBy[Them][ALL_PIECES]); & (ei.attackedBy[Us][ALL_PIECES] | ~ei.attackedBy[Them][ALL_PIECES]);
b = (shift_bb<Left>(b) | shift_bb<Right>(b)) b = (shift<Left>(b) | shift<Right>(b))
& pos.pieces(Them) & pos.pieces(Them)
& ~ei.attackedBy[Us][PAWN]; & ~ei.attackedBy[Us][PAWN];
@@ -803,8 +804,8 @@ Value Eval::evaluate(const Position& pos) {
// Pawns blocked or on ranks 2 and 3 will be excluded from the mobility area // Pawns blocked or on ranks 2 and 3 will be excluded from the mobility area
Bitboard blockedPawns[] = { Bitboard blockedPawns[] = {
pos.pieces(WHITE, PAWN) & (shift_bb<DELTA_S>(pos.pieces()) | Rank2BB | Rank3BB), pos.pieces(WHITE, PAWN) & (shift<SOUTH>(pos.pieces()) | Rank2BB | Rank3BB),
pos.pieces(BLACK, PAWN) & (shift_bb<DELTA_N>(pos.pieces()) | Rank7BB | Rank6BB) pos.pieces(BLACK, PAWN) & (shift<NORTH>(pos.pieces()) | Rank7BB | Rank6BB)
}; };
// Do not include in mobility area squares protected by enemy pawns, or occupied // Do not include in mobility area squares protected by enemy pawns, or occupied

View File

@@ -42,8 +42,8 @@ namespace {
assert(!pos.checkers()); assert(!pos.checkers());
const Square K = Chess960 ? kto > kfrom ? DELTA_W : DELTA_E const Square K = Chess960 ? kto > kfrom ? WEST : EAST
: KingSide ? DELTA_W : DELTA_E; : KingSide ? WEST : EAST;
for (Square s = kto; s != kfrom; s += K) for (Square s = kto; s != kfrom; s += K)
if (pos.attackers_to(s) & enemies) if (pos.attackers_to(s) & enemies)
@@ -65,23 +65,23 @@ namespace {
} }
template<GenType Type, Square Delta> template<GenType Type, Square D>
ExtMove* make_promotions(ExtMove* moveList, Square to, Square ksq) { ExtMove* make_promotions(ExtMove* moveList, Square to, Square ksq) {
if (Type == CAPTURES || Type == EVASIONS || Type == NON_EVASIONS) if (Type == CAPTURES || Type == EVASIONS || Type == NON_EVASIONS)
*moveList++ = make<PROMOTION>(to - Delta, to, QUEEN); *moveList++ = make<PROMOTION>(to - D, to, QUEEN);
if (Type == QUIETS || Type == EVASIONS || Type == NON_EVASIONS) if (Type == QUIETS || Type == EVASIONS || Type == NON_EVASIONS)
{ {
*moveList++ = make<PROMOTION>(to - Delta, to, ROOK); *moveList++ = make<PROMOTION>(to - D, to, ROOK);
*moveList++ = make<PROMOTION>(to - Delta, to, BISHOP); *moveList++ = make<PROMOTION>(to - D, to, BISHOP);
*moveList++ = make<PROMOTION>(to - Delta, to, KNIGHT); *moveList++ = make<PROMOTION>(to - D, to, KNIGHT);
} }
// Knight promotion is the only promotion that can give a direct check // Knight promotion is the only promotion that can give a direct check
// that's not already included in the queen promotion. // that's not already included in the queen promotion.
if (Type == QUIET_CHECKS && (StepAttacksBB[W_KNIGHT][to] & ksq)) if (Type == QUIET_CHECKS && (StepAttacksBB[W_KNIGHT][to] & ksq))
*moveList++ = make<PROMOTION>(to - Delta, to, KNIGHT); *moveList++ = make<PROMOTION>(to - D, to, KNIGHT);
else else
(void)ksq; // Silence a warning under MSVC (void)ksq; // Silence a warning under MSVC
@@ -94,13 +94,13 @@ namespace {
// Compute our parametrized parameters at compile time, named according to // Compute our parametrized parameters at compile time, named according to
// the point of view of white side. // the point of view of white side.
const Color Them = (Us == WHITE ? BLACK : WHITE); const Color Them = (Us == WHITE ? BLACK : WHITE);
const Bitboard TRank8BB = (Us == WHITE ? Rank8BB : Rank1BB); const Bitboard TRank8BB = (Us == WHITE ? Rank8BB : Rank1BB);
const Bitboard TRank7BB = (Us == WHITE ? Rank7BB : Rank2BB); const Bitboard TRank7BB = (Us == WHITE ? Rank7BB : Rank2BB);
const Bitboard TRank3BB = (Us == WHITE ? Rank3BB : Rank6BB); const Bitboard TRank3BB = (Us == WHITE ? Rank3BB : Rank6BB);
const Square Up = (Us == WHITE ? DELTA_N : DELTA_S); const Square Up = (Us == WHITE ? NORTH : SOUTH);
const Square Right = (Us == WHITE ? DELTA_NE : DELTA_SW); const Square Right = (Us == WHITE ? NORTH_EAST : SOUTH_WEST);
const Square Left = (Us == WHITE ? DELTA_NW : DELTA_SE); const Square Left = (Us == WHITE ? NORTH_WEST : SOUTH_EAST);
Bitboard emptySquares; Bitboard emptySquares;
@@ -115,8 +115,8 @@ namespace {
{ {
emptySquares = (Type == QUIETS || Type == QUIET_CHECKS ? target : ~pos.pieces()); emptySquares = (Type == QUIETS || Type == QUIET_CHECKS ? target : ~pos.pieces());
Bitboard b1 = shift_bb<Up>(pawnsNotOn7) & emptySquares; Bitboard b1 = shift<Up>(pawnsNotOn7) & emptySquares;
Bitboard b2 = shift_bb<Up>(b1 & TRank3BB) & emptySquares; Bitboard b2 = shift<Up>(b1 & TRank3BB) & emptySquares;
if (Type == EVASIONS) // Consider only blocking squares if (Type == EVASIONS) // Consider only blocking squares
{ {
@@ -138,8 +138,8 @@ namespace {
Bitboard dcCandidates = pos.discovered_check_candidates(); Bitboard dcCandidates = pos.discovered_check_candidates();
if (pawnsNotOn7 & dcCandidates) if (pawnsNotOn7 & dcCandidates)
{ {
Bitboard dc1 = shift_bb<Up>(pawnsNotOn7 & dcCandidates) & emptySquares & ~file_bb(ksq); Bitboard dc1 = shift<Up>(pawnsNotOn7 & dcCandidates) & emptySquares & ~file_bb(ksq);
Bitboard dc2 = shift_bb<Up>(dc1 & TRank3BB) & emptySquares; Bitboard dc2 = shift<Up>(dc1 & TRank3BB) & emptySquares;
b1 |= dc1; b1 |= dc1;
b2 |= dc2; b2 |= dc2;
@@ -168,9 +168,9 @@ namespace {
if (Type == EVASIONS) if (Type == EVASIONS)
emptySquares &= target; emptySquares &= target;
Bitboard b1 = shift_bb<Right>(pawnsOn7) & enemies; Bitboard b1 = shift<Right>(pawnsOn7) & enemies;
Bitboard b2 = shift_bb<Left >(pawnsOn7) & enemies; Bitboard b2 = shift<Left >(pawnsOn7) & enemies;
Bitboard b3 = shift_bb<Up >(pawnsOn7) & emptySquares; Bitboard b3 = shift<Up >(pawnsOn7) & emptySquares;
Square ksq = pos.square<KING>(Them); Square ksq = pos.square<KING>(Them);
@@ -187,8 +187,8 @@ namespace {
// Standard and en-passant captures // Standard and en-passant captures
if (Type == CAPTURES || Type == EVASIONS || Type == NON_EVASIONS) if (Type == CAPTURES || Type == EVASIONS || Type == NON_EVASIONS)
{ {
Bitboard b1 = shift_bb<Right>(pawnsNotOn7) & enemies; Bitboard b1 = shift<Right>(pawnsNotOn7) & enemies;
Bitboard b2 = shift_bb<Left >(pawnsNotOn7) & enemies; Bitboard b2 = shift<Left >(pawnsNotOn7) & enemies;
while (b1) while (b1)
{ {

View File

@@ -50,14 +50,16 @@ namespace {
// Lever bonus by rank // Lever bonus by rank
const Score Lever[RANK_NB] = { const Score Lever[RANK_NB] = {
S( 0, 0), S( 0, 0), S(0, 0), S(0, 0), S( 0, 0), S( 0, 0), S(0, 0), S(0, 0),
S(17, 16), S(33, 32), S(0, 0), S(0, 0) }; S(17, 16), S(33, 32), S(0, 0), S(0, 0)
};
// Weakness of our pawn shelter in front of the king by [distance from edge][rank] // Weakness of our pawn shelter in front of the king by [distance from edge][rank]
const Value ShelterWeakness[][RANK_NB] = { const Value ShelterWeakness[][RANK_NB] = {
{ V( 97), V(21), V(26), V(51), V(87), V( 89), V( 99) }, { V( 97), V(21), V(26), V(51), V(87), V( 89), V( 99) },
{ V(120), V( 0), V(28), V(76), V(88), V(103), V(104) }, { V(120), V( 0), V(28), V(76), V(88), V(103), V(104) },
{ V(101), V( 7), V(54), V(78), V(77), V( 92), V(101) }, { V(101), V( 7), V(54), V(78), V(77), V( 92), V(101) },
{ V( 80), V(11), V(44), V(68), V(87), V( 90), V(119) } }; { V( 80), V(11), V(44), V(68), V(87), V( 90), V(119) }
};
// Danger of enemy pawns moving toward our king by [type][distance from edge][rank] // Danger of enemy pawns moving toward our king by [type][distance from edge][rank]
const Value StormDanger[][4][RANK_NB] = { const Value StormDanger[][4][RANK_NB] = {
@@ -76,7 +78,8 @@ namespace {
{ { V( 0), V(-283), V(-281), V(57), V(31) }, { { V( 0), V(-283), V(-281), V(57), V(31) },
{ V( 0), V( 58), V( 141), V(39), V(18) }, { V( 0), V( 58), V( 141), V(39), V(18) },
{ V( 0), V( 65), V( 142), V(48), V(32) }, { V( 0), V( 65), V( 142), V(48), V(32) },
{ V( 0), V( 60), V( 126), V(51), V(19) } } }; { V( 0), V( 60), V( 126), V(51), V(19) } }
};
// Max bonus for king safety. Corresponds to start position with all the pawns // Max bonus for king safety. Corresponds to start position with all the pawns
// in front of the king and no enemy pawn on the horizon. // in front of the king and no enemy pawn on the horizon.
@@ -88,10 +91,10 @@ namespace {
template<Color Us> template<Color Us>
Score evaluate(const Position& pos, Pawns::Entry* e) { Score evaluate(const Position& pos, Pawns::Entry* e) {
const Color Them = (Us == WHITE ? BLACK : WHITE); const Color Them = (Us == WHITE ? BLACK : WHITE);
const Square Up = (Us == WHITE ? DELTA_N : DELTA_S); const Square Up = (Us == WHITE ? NORTH : SOUTH);
const Square Right = (Us == WHITE ? DELTA_NE : DELTA_SW); const Square Right = (Us == WHITE ? NORTH_EAST : SOUTH_WEST);
const Square Left = (Us == WHITE ? DELTA_NW : DELTA_SE); const Square Left = (Us == WHITE ? NORTH_WEST : SOUTH_EAST);
Bitboard b, neighbours, stoppers, doubled, supported, phalanx; Bitboard b, neighbours, stoppers, doubled, supported, phalanx;
Square s; Square s;
@@ -103,10 +106,10 @@ namespace {
Bitboard ourPawns = pos.pieces(Us , PAWN); Bitboard ourPawns = pos.pieces(Us , PAWN);
Bitboard theirPawns = pos.pieces(Them, PAWN); Bitboard theirPawns = pos.pieces(Them, PAWN);
e->passedPawns[Us] = e->pawnAttacksSpan[Us] = 0; e->passedPawns[Us] = e->pawnAttacksSpan[Us] = 0;
e->kingSquares[Us] = SQ_NONE;
e->semiopenFiles[Us] = 0xFF; e->semiopenFiles[Us] = 0xFF;
e->pawnAttacks[Us] = shift_bb<Right>(ourPawns) | shift_bb<Left>(ourPawns); e->kingSquares[Us] = SQ_NONE;
e->pawnAttacks[Us] = shift<Right>(ourPawns) | shift<Left>(ourPawns);
e->pawnsOnSquares[Us][BLACK] = popcount(ourPawns & DarkSquares); e->pawnsOnSquares[Us][BLACK] = popcount(ourPawns & DarkSquares);
e->pawnsOnSquares[Us][WHITE] = pos.count<PAWN>(Us) - e->pawnsOnSquares[Us][BLACK]; e->pawnsOnSquares[Us][WHITE] = pos.count<PAWN>(Us) - e->pawnsOnSquares[Us][BLACK];
@@ -117,7 +120,7 @@ namespace {
File f = file_of(s); File f = file_of(s);
e->semiopenFiles[Us] &= ~(1 << f); e->semiopenFiles[Us] &= ~(1 << f);
e->pawnAttacksSpan[Us] |= pawn_attack_span(Us, s); e->pawnAttacksSpan[Us] |= pawn_attack_span(Us, s);
// Flag the pawn // Flag the pawn
@@ -142,7 +145,7 @@ namespace {
// The pawn is backward when it cannot safely progress to that rank: // The pawn is backward when it cannot safely progress to that rank:
// either there is a stopper in the way on this rank, or there is a // either there is a stopper in the way on this rank, or there is a
// stopper on adjacent file which controls the way to that rank. // stopper on adjacent file which controls the way to that rank.
backward = (b | shift_bb<Up>(b & adjacent_files_bb(f))) & stoppers; backward = (b | shift<Up>(b & adjacent_files_bb(f))) & stoppers;
assert(!backward || !(pawn_attack_span(Them, s + Up) & neighbours)); assert(!backward || !(pawn_attack_span(Them, s + Up) & neighbours));
} }
@@ -183,8 +186,8 @@ namespace Pawns {
/// hard-coded tables, when makes sense, we prefer to calculate them with a formula /// hard-coded tables, when makes sense, we prefer to calculate them with a formula
/// to reduce independent parameters and to allow easier tuning and better insight. /// to reduce independent parameters and to allow easier tuning and better insight.
void init() void init() {
{
static const int Seed[RANK_NB] = { 0, 8, 19, 13, 71, 94, 169, 324 }; static const int Seed[RANK_NB] = { 0, 8, 19, 13, 71, 94, 169, 324 };
for (int opposed = 0; opposed <= 1; ++opposed) for (int opposed = 0; opposed <= 1; ++opposed)

View File

@@ -23,8 +23,9 @@
#include "types.h" #include "types.h"
Value PieceValue[PHASE_NB][PIECE_NB] = { Value PieceValue[PHASE_NB][PIECE_NB] = {
{ VALUE_ZERO, PawnValueMg, KnightValueMg, BishopValueMg, RookValueMg, QueenValueMg }, { VALUE_ZERO, PawnValueMg, KnightValueMg, BishopValueMg, RookValueMg, QueenValueMg },
{ VALUE_ZERO, PawnValueEg, KnightValueEg, BishopValueEg, RookValueEg, QueenValueEg } }; { VALUE_ZERO, PawnValueEg, KnightValueEg, BishopValueEg, RookValueEg, QueenValueEg }
};
namespace PSQT { namespace PSQT {

View File

@@ -1588,8 +1588,8 @@ string UCI::pv(const Position& pos, Depth depth, Value alpha, Value beta) {
/// fail high at root. We try hard to have a ponder move to return to the GUI, /// fail high at root. We try hard to have a ponder move to return to the GUI,
/// otherwise in case of 'ponder on' we have nothing to think on. /// otherwise in case of 'ponder on' we have nothing to think on.
bool RootMove::extract_ponder_from_tt(Position& pos) bool RootMove::extract_ponder_from_tt(Position& pos) {
{
StateInfo st; StateInfo st;
bool ttHit; bool ttHit;

View File

@@ -52,8 +52,8 @@ namespace {
} }
template<TimeType T> template<TimeType T>
int remaining(int myTime, int movesToGo, int ply, int slowMover) int remaining(int myTime, int movesToGo, int ply, int slowMover) {
{
const double TMaxRatio = (T == OptimumTime ? 1 : MaxRatio); const double TMaxRatio = (T == OptimumTime ? 1 : MaxRatio);
const double TStealRatio = (T == OptimumTime ? 0 : StealRatio); const double TStealRatio = (T == OptimumTime ? 0 : StealRatio);
@@ -81,8 +81,8 @@ namespace {
/// inc > 0 && movestogo == 0 means: x basetime + z increment /// inc > 0 && movestogo == 0 means: x basetime + z increment
/// inc > 0 && movestogo != 0 means: x moves in y minutes + z increment /// inc > 0 && movestogo != 0 means: x moves in y minutes + z increment
void TimeManagement::init(Search::LimitsType& limits, Color us, int ply) void TimeManagement::init(Search::LimitsType& limits, Color us, int ply) {
{
int minThinkingTime = Options["Minimum Thinking Time"]; int minThinkingTime = Options["Minimum Thinking Time"];
int moveOverhead = Options["Move Overhead"]; int moveOverhead = Options["Move Overhead"];
int slowMover = Options["Slow Mover"]; int slowMover = Options["Slow Mover"];

View File

@@ -100,11 +100,11 @@ TTEntry* TranspositionTable::probe(const Key key, bool& found) const {
} }
/// Returns an approximation of the hashtable occupation during a search. The /// TranspositionTable::hashfull() returns an approximation of the hashtable
/// hash is x permill full, as per UCI protocol. /// occupation during a search. The hash is x permill full, as per UCI protocol.
int TranspositionTable::hashfull() const {
int TranspositionTable::hashfull() const
{
int cnt = 0; int cnt = 0;
for (int i = 0; i < 1000 / ClusterSize; i++) for (int i = 0; i < 1000 / ClusterSize; i++)
{ {

View File

@@ -237,17 +237,15 @@ enum Square {
SQUARE_NB = 64, SQUARE_NB = 64,
DELTA_N = 8, NORTH = 8,
DELTA_E = 1, EAST = 1,
DELTA_S = -8, SOUTH = -8,
DELTA_W = -1, WEST = -1,
DELTA_NN = DELTA_N + DELTA_N, NORTH_EAST = NORTH + EAST,
DELTA_NE = DELTA_N + DELTA_E, SOUTH_EAST = SOUTH + EAST,
DELTA_SE = DELTA_S + DELTA_E, SOUTH_WEST = SOUTH + WEST,
DELTA_SS = DELTA_S + DELTA_S, NORTH_WEST = NORTH + WEST
DELTA_SW = DELTA_S + DELTA_W,
DELTA_NW = DELTA_N + DELTA_W
}; };
enum File { enum File {
@@ -401,7 +399,7 @@ inline bool opposite_colors(Square s1, Square s2) {
} }
inline Square pawn_push(Color c) { inline Square pawn_push(Color c) {
return c == WHITE ? DELTA_N : DELTA_S; return c == WHITE ? NORTH : SOUTH;
} }
inline Square from_sq(Move m) { inline Square from_sq(Move m) {