mirror of
https://github.com/HChaZZY/Stockfish.git
synced 2025-12-23 10:36:26 +08:00
Retire the misdesigned StepAttacks[] array.
StepAttacks[] is misdesigned, the color dependance is specific to pawns, and trying to generalise to king and knights, proves neither useful nor convinient in practice. So this patch reformats the code with the following changes: - Use PieceType instead of Piece in attacks_() functions - Use PseudoAttacks for KING and KNIGHT - Rename StepAttacks[] into PawnAttacks[] Original patch and idea from Alain Savard. No functional change. Closes #1086
This commit is contained in:
committed by
Joona Kiiski
parent
b1b19343cd
commit
e06a117d5e
@@ -117,7 +117,7 @@ namespace {
|
||||
if ( distance(ksq[WHITE], ksq[BLACK]) <= 1
|
||||
|| ksq[WHITE] == psq
|
||||
|| ksq[BLACK] == psq
|
||||
|| (us == WHITE && (StepAttacksBB[W_PAWN][psq] & ksq[BLACK])))
|
||||
|| (us == WHITE && (PawnAttacks[WHITE][psq] & ksq[BLACK])))
|
||||
result = INVALID;
|
||||
|
||||
// Immediate win if a pawn can be promoted without getting captured
|
||||
@@ -125,13 +125,13 @@ namespace {
|
||||
&& rank_of(psq) == RANK_7
|
||||
&& ksq[us] != psq + NORTH
|
||||
&& ( distance(ksq[~us], psq + NORTH) > 1
|
||||
|| (StepAttacksBB[KING][ksq[us]] & (psq + NORTH))))
|
||||
|| (PseudoAttacks[KING][ksq[us]] & (psq + NORTH))))
|
||||
result = WIN;
|
||||
|
||||
// Immediate draw if it is a stalemate or a king captures undefended pawn
|
||||
else if ( us == BLACK
|
||||
&& ( !(StepAttacksBB[KING][ksq[us]] & ~(StepAttacksBB[KING][ksq[~us]] | StepAttacksBB[W_PAWN][psq]))
|
||||
|| (StepAttacksBB[KING][ksq[us]] & psq & ~StepAttacksBB[KING][ksq[~us]])))
|
||||
&& ( !(PseudoAttacks[KING][ksq[us]] & ~(PseudoAttacks[KING][ksq[~us]] | PawnAttacks[~us][psq]))
|
||||
|| (PseudoAttacks[KING][ksq[us]] & psq & ~PseudoAttacks[KING][ksq[~us]])))
|
||||
result = DRAW;
|
||||
|
||||
// Position will be classified later
|
||||
@@ -157,7 +157,7 @@ namespace {
|
||||
const Result Bad = (Us == WHITE ? DRAW : WIN);
|
||||
|
||||
Result r = INVALID;
|
||||
Bitboard b = StepAttacksBB[KING][ksq[Us]];
|
||||
Bitboard b = PseudoAttacks[KING][ksq[Us]];
|
||||
|
||||
while (b)
|
||||
r |= Us == WHITE ? db[index(Them, ksq[Them] , pop_lsb(&b), psq)]
|
||||
|
||||
Reference in New Issue
Block a user