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:
Marco Costalba
2017-04-28 20:33:30 -07:00
committed by Joona Kiiski
parent b1b19343cd
commit e06a117d5e
8 changed files with 37 additions and 32 deletions

View File

@@ -595,7 +595,7 @@ bool Position::pseudo_legal(const Move m) const {
&& empty(to - pawn_push(us))))
return false;
}
else if (!(attacks_from(pc, from) & to))
else if (!(attacks_from(type_of(pc), from) & to))
return false;
// Evasions generator already takes care to avoid some kind of illegal moves
@@ -648,7 +648,7 @@ bool Position::gives_check(Move m) const {
return false;
case PROMOTION:
return attacks_bb(Piece(promotion_type(m)), to, pieces() ^ from) & square<KING>(~sideToMove);
return attacks_bb(promotion_type(m), to, pieces() ^ from) & square<KING>(~sideToMove);
// En passant capture with check? We have already handled the case
// of direct checks and ordinary discovered check, so the only case we