- Construct a neighborhood bitmask around the king consisting of the squares the king can see plus the three directly in front of the king.
- For each attacking piece (knight, bishop, rook, queen), get a mask of the squares the piece can attack, and bitwise and it with the neighborhood mask
to get the piece's king-attack set. - Multiply the number of ones in the piece's king attack set by a fixed score for each piece (2 for minor pieces, 3 for rooks, 5 for queens) and add to the total quantity of attack units.
- Look up the bonus or malus for the given number of attack units and add it to the evaluation.
- Repeat the process for the opposing side.
After tuning, my first confusing result was that the bonus given to an attack (after tuning) was much smaller than the examples shown in the wiki. The highest bonus given is only +7 centipawns for a large attack. Compare to Stockfish, which gave +500 centipawns for a large attack before it moved to NNUE.
When benchmarking, it turned out that my implementation resulted in a -10 Elo regression in playing strength. Clearly I've missed something - so what's wrong here? Some possibilities:
- Do I need to include pawn structure information in king safety?
- Have I misinterpreted the description on the wiki somehow?
- I'm currently using attacks. Should I instead consider legal moves (thus eliminating ally-attacks and pinned pieces)?