Skip to content

Commit

Permalink
Remove redundant king square parameter
Browse files Browse the repository at this point in the history
We don't need to pass the king square as an explicit parameter to the functions
king_safety() and do_king_safety() since we already pass in the position.

STC:
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 69686 W: 14894 L: 14866 D: 39926
http://tests.stockfishchess.org/tests/view/5be84ac20ebc595e0ae3283c

No functional change.
  • Loading branch information
mstembera authored and snicolet committed Nov 12, 2018
1 parent 30a905c commit 68209c9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/evaluate.cpp
Expand Up @@ -415,7 +415,7 @@ namespace {
Bitboard kingFlank, weak, b, b1, b2, safe, unsafeChecks;

// King shelter and enemy pawns storm
Score score = pe->king_safety<Us>(pos, ksq);
Score score = pe->king_safety<Us>(pos);

// Find the squares that opponent attacks in our king flank, and the squares
// which are attacked twice in that flank but not defended by our pawns.
Expand Down
7 changes: 4 additions & 3 deletions src/pawns.cpp
Expand Up @@ -237,8 +237,9 @@ Value Entry::evaluate_shelter(const Position& pos, Square ksq) {
/// when king square changes, which is about 20% of total king_safety() calls.

template<Color Us>
Score Entry::do_king_safety(const Position& pos, Square ksq) {
Score Entry::do_king_safety(const Position& pos) {

Square ksq = pos.square<KING>(Us);
kingSquares[Us] = ksq;
castlingRights[Us] = pos.can_castle(Us);
int minKingPawnDistance = 0;
Expand All @@ -260,7 +261,7 @@ Score Entry::do_king_safety(const Position& pos, Square ksq) {
}

// Explicit template instantiation
template Score Entry::do_king_safety<WHITE>(const Position& pos, Square ksq);
template Score Entry::do_king_safety<BLACK>(const Position& pos, Square ksq);
template Score Entry::do_king_safety<WHITE>(const Position& pos);
template Score Entry::do_king_safety<BLACK>(const Position& pos);

} // namespace Pawns
8 changes: 4 additions & 4 deletions src/pawns.h
Expand Up @@ -50,13 +50,13 @@ struct Entry {
}

template<Color Us>
Score king_safety(const Position& pos, Square ksq) {
return kingSquares[Us] == ksq && castlingRights[Us] == pos.can_castle(Us)
? kingSafety[Us] : (kingSafety[Us] = do_king_safety<Us>(pos, ksq));
Score king_safety(const Position& pos) {
return kingSquares[Us] == pos.square<KING>(Us) && castlingRights[Us] == pos.can_castle(Us)
? kingSafety[Us] : (kingSafety[Us] = do_king_safety<Us>(pos));
}

template<Color Us>
Score do_king_safety(const Position& pos, Square ksq);
Score do_king_safety(const Position& pos);

template<Color Us>
Value evaluate_shelter(const Position& pos, Square ksq);
Expand Down

0 comments on commit 68209c9

Please sign in to comment.