Simplify king shelter cache handling

This is more similar to how get_material_info() and
get_pawn_info() work and also removes some clutter from
evaluate_king().

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba
2009-07-24 12:16:18 +02:00
parent 20224a5bbf
commit 080a4995a3
5 changed files with 30 additions and 35 deletions

View File

@@ -385,3 +385,21 @@ PawnInfo *PawnInfoTable::get_pawn_info(const Position &pos) {
pi->egValue = int16_t(egValue[WHITE] - egValue[BLACK]);
return pi;
}
/// PawnInfo::updateShelter calculates and caches king shelter. It is called
/// only when king square changes, about 20% of total get_king_shelter() calls.
int PawnInfo::updateShelter(const Position& pos, Color c, Square ksq) {
int shelter = 0;
Bitboard pawns = pos.pawns(c) & this_and_neighboring_files_bb(ksq);
unsigned r = ksq & (7 << 3);
for (int i = 1, k = (c ? -8 : 8); i < 4; i++)
{
r += k;
shelter += BitCount8Bit[(pawns >> r) & 0xFF] * (128 >> i);
}
kingSquares[c] = ksq;
kingShelters[c] = shelter;
return shelter;
}