Skip to content

Commit 384bff4

Browse files
committed
Assorted trivial cleanups January 2020
Assorted trivial cleanups. No functional change
1 parent bae019b commit 384bff4

File tree

5 files changed

+38
-35
lines changed

5 files changed

+38
-35
lines changed

src/endgame.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ Value Endgame<KBNK>::operator()(const Position& pos) const {
155155
Square loserKSq = pos.square<KING>(weakSide);
156156
Square bishopSq = pos.square<BISHOP>(strongSide);
157157

158-
// If our Bishop does not attack A1/H8, we flip the enemy king square
158+
// If our bishop does not attack A1/H8, we flip the enemy king square
159159
// to drive to opposite corners (A8/H1).
160160

161161
Value result = VALUE_KNOWN_WIN
@@ -167,7 +167,7 @@ Value Endgame<KBNK>::operator()(const Position& pos) const {
167167
}
168168

169169

170-
/// KP vs K. This endgame is evaluated with the help of a bitbase.
170+
/// KP vs K. This endgame is evaluated with the help of a bitbase
171171
template<>
172172
Value Endgame<KPK>::operator()(const Position& pos) const {
173173

src/evaluate.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -317,20 +317,19 @@ namespace {
317317
// Bonus for bishop on a long diagonal which can "see" both center squares
318318
if (more_than_one(attacks_bb<BISHOP>(s, pos.pieces(PAWN)) & Center))
319319
score += LongDiagonalBishop;
320-
}
321320

322-
// An important Chess960 pattern: A cornered bishop blocked by a friendly
323-
// pawn diagonally in front of it is a very serious problem, especially
324-
// when that pawn is also blocked.
325-
if ( Pt == BISHOP
326-
&& pos.is_chess960()
327-
&& (s == relative_square(Us, SQ_A1) || s == relative_square(Us, SQ_H1)))
328-
{
329-
Direction d = pawn_push(Us) + (file_of(s) == FILE_A ? EAST : WEST);
330-
if (pos.piece_on(s + d) == make_piece(Us, PAWN))
331-
score -= !pos.empty(s + d + pawn_push(Us)) ? CorneredBishop * 4
332-
: pos.piece_on(s + d + d) == make_piece(Us, PAWN) ? CorneredBishop * 2
333-
: CorneredBishop;
321+
// An important Chess960 pattern: a cornered bishop blocked by a friendly
322+
// pawn diagonally in front of it is a very serious problem, especially
323+
// when that pawn is also blocked.
324+
if ( pos.is_chess960()
325+
&& (s == relative_square(Us, SQ_A1) || s == relative_square(Us, SQ_H1)))
326+
{
327+
Direction d = pawn_push(Us) + (file_of(s) == FILE_A ? EAST : WEST);
328+
if (pos.piece_on(s + d) == make_piece(Us, PAWN))
329+
score -= !pos.empty(s + d + pawn_push(Us)) ? CorneredBishop * 4
330+
: pos.piece_on(s + d + d) == make_piece(Us, PAWN) ? CorneredBishop * 2
331+
: CorneredBishop;
332+
}
334333
}
335334
}
336335

src/position.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,7 @@ void Position::do_move(Move m, StateInfo& newSt, bool givesCheck) {
817817
st->nonPawnMaterial[us] += PieceValue[MG][promotion];
818818
}
819819

820-
// Update pawn hash key and prefetch access to pawnsTable
820+
// Update pawn hash key
821821
st->pawnKey ^= Zobrist::psq[pc][from] ^ Zobrist::psq[pc][to];
822822

823823
// Reset rule 50 draw counter
@@ -944,7 +944,7 @@ void Position::do_castling(Color us, Square from, Square& to, Square& rfrom, Squ
944944
}
945945

946946

947-
/// Position::do(undo)_null_move() is used to do(undo) a "null move": It flips
947+
/// Position::do(undo)_null_move() is used to do(undo) a "null move": it flips
948948
/// the side to move without executing any move on the board.
949949

950950
void Position::do_null_move(StateInfo& newSt) {
@@ -1027,24 +1027,24 @@ bool Position::see_ge(Move m, Value threshold) const {
10271027
if (swap <= 0)
10281028
return true;
10291029

1030-
Bitboard occ = pieces() ^ from ^ to;
1030+
Bitboard occupied = pieces() ^ from ^ to;
10311031
Color stm = color_of(piece_on(from));
1032-
Bitboard attackers = attackers_to(to, occ);
1032+
Bitboard attackers = attackers_to(to, occupied);
10331033
Bitboard stmAttackers, bb;
10341034
int res = 1;
10351035

10361036
while (true)
10371037
{
10381038
stm = ~stm;
1039-
attackers &= occ;
1039+
attackers &= occupied;
10401040

10411041
// If stm has no more attackers then give up: stm loses
10421042
if (!(stmAttackers = attackers & pieces(stm)))
10431043
break;
10441044

10451045
// Don't allow pinned pieces to attack (except the king) as long as
10461046
// there are pinners on their original square.
1047-
if (st->pinners[~stm] & occ)
1047+
if (st->pinners[~stm] & occupied)
10481048
stmAttackers &= ~st->blockersForKing[stm];
10491049

10501050
if (!stmAttackers)
@@ -1059,44 +1059,44 @@ bool Position::see_ge(Move m, Value threshold) const {
10591059
if ((swap = PawnValueMg - swap) < res)
10601060
break;
10611061

1062-
occ ^= lsb(bb);
1063-
attackers |= attacks_bb<BISHOP>(to, occ) & pieces(BISHOP, QUEEN);
1062+
occupied ^= lsb(bb);
1063+
attackers |= attacks_bb<BISHOP>(to, occupied) & pieces(BISHOP, QUEEN);
10641064
}
10651065

10661066
else if ((bb = stmAttackers & pieces(KNIGHT)))
10671067
{
10681068
if ((swap = KnightValueMg - swap) < res)
10691069
break;
10701070

1071-
occ ^= lsb(bb);
1071+
occupied ^= lsb(bb);
10721072
}
10731073

10741074
else if ((bb = stmAttackers & pieces(BISHOP)))
10751075
{
10761076
if ((swap = BishopValueMg - swap) < res)
10771077
break;
10781078

1079-
occ ^= lsb(bb);
1080-
attackers |= attacks_bb<BISHOP>(to, occ) & pieces(BISHOP, QUEEN);
1079+
occupied ^= lsb(bb);
1080+
attackers |= attacks_bb<BISHOP>(to, occupied) & pieces(BISHOP, QUEEN);
10811081
}
10821082

10831083
else if ((bb = stmAttackers & pieces(ROOK)))
10841084
{
10851085
if ((swap = RookValueMg - swap) < res)
10861086
break;
10871087

1088-
occ ^= lsb(bb);
1089-
attackers |= attacks_bb<ROOK>(to, occ) & pieces(ROOK, QUEEN);
1088+
occupied ^= lsb(bb);
1089+
attackers |= attacks_bb<ROOK>(to, occupied) & pieces(ROOK, QUEEN);
10901090
}
10911091

10921092
else if ((bb = stmAttackers & pieces(QUEEN)))
10931093
{
10941094
if ((swap = QueenValueMg - swap) < res)
10951095
break;
10961096

1097-
occ ^= lsb(bb);
1098-
attackers |= (attacks_bb<BISHOP>(to, occ) & pieces(BISHOP, QUEEN))
1099-
| (attacks_bb<ROOK >(to, occ) & pieces(ROOK , QUEEN));
1097+
occupied ^= lsb(bb);
1098+
attackers |= (attacks_bb<BISHOP>(to, occupied) & pieces(BISHOP, QUEEN))
1099+
| (attacks_bb<ROOK >(to, occupied) & pieces(ROOK , QUEEN));
11001100
}
11011101

11021102
else // KING
@@ -1105,7 +1105,7 @@ bool Position::see_ge(Move m, Value threshold) const {
11051105
return (attackers & ~pieces(stm)) ? res ^ 1 : res;
11061106
}
11071107

1108-
return res;
1108+
return bool(res);
11091109
}
11101110

11111111
/// Position::is_draw() tests whether the position is drawn by 50-move rule

src/position.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ struct StateInfo {
4646
Square epSquare;
4747

4848
// Not copied when making a move (will be recomputed anyhow)
49-
int repetition;
5049
Key key;
5150
Bitboard checkersBB;
5251
Piece capturedPiece;
5352
StateInfo* previous;
5453
Bitboard blockersForKing[COLOR_NB];
5554
Bitboard pinners[COLOR_NB];
5655
Bitboard checkSquares[PIECE_TYPE_NB];
56+
int repetition;
5757
};
5858

5959
/// A list to keep track of the position states along the setup moves (from the
@@ -277,10 +277,14 @@ inline int Position::castling_rights(Color c) const {
277277
}
278278

279279
inline bool Position::castling_impeded(CastlingRights cr) const {
280+
assert(cr == WHITE_OO || cr == WHITE_OOO || cr == BLACK_OO || cr == BLACK_OOO);
281+
280282
return byTypeBB[ALL_PIECES] & castlingPath[cr];
281283
}
282284

283285
inline Square Position::castling_rook_square(CastlingRights cr) const {
286+
assert(cr == WHITE_OO || cr == WHITE_OOO || cr == BLACK_OO || cr == BLACK_OOO);
287+
284288
return castlingRookSquare[cr];
285289
}
286290

src/syzygy/tbprobe.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ Ret do_probe_table(const Position& pos, T* entry, WDLScore wdl, ProbeState* resu
683683
bool blackStronger = (pos.material_key() != entry->key);
684684

685685
int flipColor = (symmetricBlackToMove || blackStronger) * 8;
686-
int flipSquares = (symmetricBlackToMove || blackStronger) * 070;
686+
int flipSquares = (symmetricBlackToMove || blackStronger) * 56;
687687
int stm = (symmetricBlackToMove || blackStronger) ^ pos.side_to_move();
688688

689689
// For pawns, TB files store 4 separate tables according if leading pawn is on
@@ -762,7 +762,7 @@ Ret do_probe_table(const Position& pos, T* entry, WDLScore wdl, ProbeState* resu
762762
// piece is below RANK_5.
763763
if (rank_of(squares[0]) > RANK_4)
764764
for (int i = 0; i < size; ++i)
765-
squares[i] ^= 070; // Vertical flip: SQ_A8 -> SQ_A1
765+
squares[i] ^= SQ_A8; // Vertical flip: SQ_A8 -> SQ_A1
766766

767767
// Look for the first piece of the leading group not on the A1-D4 diagonal
768768
// and ensure it is mapped below the diagonal.

0 commit comments

Comments
 (0)