Skip to content

Commit 2f47844

Browse files
committed
Simplify attacks_bb()
And some formatting while there. No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
1 parent b9bc6e8 commit 2f47844

2 files changed

Lines changed: 12 additions & 17 deletions

File tree

src/bitboard.cpp

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -168,30 +168,27 @@ void Bitboards::init() {
168168
FileBB[FILE_A] = FileABB;
169169
RankBB[RANK_1] = Rank1BB;
170170

171-
for (int f = FILE_B; f <= FILE_H; f++)
171+
for (int i = 1; i < 8; i++)
172172
{
173-
FileBB[f] = FileBB[f - 1] << 1;
174-
RankBB[f] = RankBB[f - 1] << 8;
173+
FileBB[i] = FileBB[i - 1] << 1;
174+
RankBB[i] = RankBB[i - 1] << 8;
175175
}
176176

177-
for (int f = FILE_A; f <= FILE_H; f++)
177+
for (File f = FILE_A; f <= FILE_H; f++)
178178
{
179179
AdjacentFilesBB[f] = (f > FILE_A ? FileBB[f - 1] : 0) | (f < FILE_H ? FileBB[f + 1] : 0);
180180
ThisAndAdjacentFilesBB[f] = FileBB[f] | AdjacentFilesBB[f];
181181
}
182182

183-
for (int rw = RANK_7, rb = RANK_2; rw >= RANK_1; rw--, rb++)
184-
{
185-
InFrontBB[WHITE][rw] = InFrontBB[WHITE][rw + 1] | RankBB[rw + 1];
186-
InFrontBB[BLACK][rb] = InFrontBB[BLACK][rb - 1] | RankBB[rb - 1];
187-
}
183+
for (Rank r = RANK_1; r < RANK_8; r++)
184+
InFrontBB[WHITE][r] = ~(InFrontBB[BLACK][r + 1] = InFrontBB[BLACK][r] | RankBB[r]);
188185

189186
for (Color c = WHITE; c <= BLACK; c++)
190187
for (Square s = SQ_A1; s <= SQ_H8; s++)
191188
{
192-
ForwardBB[c][s] = in_front_bb(c, s) & file_bb(s);
193-
PassedPawnMask[c][s] = in_front_bb(c, s) & this_and_adjacent_files_bb(file_of(s));
194-
AttackSpanMask[c][s] = in_front_bb(c, s) & adjacent_files_bb(file_of(s));
189+
ForwardBB[c][s] = InFrontBB[c][rank_of(s)] & FileBB[file_of(s)];
190+
PassedPawnMask[c][s] = InFrontBB[c][rank_of(s)] & ThisAndAdjacentFilesBB[file_of(s)];
191+
AttackSpanMask[c][s] = InFrontBB[c][rank_of(s)] & AdjacentFilesBB[file_of(s)];
195192
}
196193

197194
for (Square s1 = SQ_A1; s1 <= SQ_H8; s1++)
@@ -231,9 +228,8 @@ void Bitboards::init() {
231228

232229
for (Square s = SQ_A1; s <= SQ_H8; s++)
233230
{
234-
PseudoAttacks[BISHOP][s] = attacks_bb<BISHOP>(s, 0);
235-
PseudoAttacks[ROOK][s] = attacks_bb<ROOK>(s, 0);
236-
PseudoAttacks[QUEEN][s] = PseudoAttacks[BISHOP][s] | PseudoAttacks[ROOK][s];
231+
PseudoAttacks[QUEEN][s] = PseudoAttacks[BISHOP][s] = attacks_bb<BISHOP>(s, 0);
232+
PseudoAttacks[QUEEN][s] |= PseudoAttacks[ ROOK][s] = attacks_bb< ROOK>(s, 0);
237233
}
238234

239235
for (Square s1 = SQ_A1; s1 <= SQ_H8; s1++)

src/bitboard.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,7 @@ FORCE_INLINE unsigned magic_index(Square s, Bitboard occ) {
216216

217217
template<PieceType Pt>
218218
inline Bitboard attacks_bb(Square s, Bitboard occ) {
219-
Bitboard** const Attacks = Pt == ROOK ? RAttacks : BAttacks;
220-
return Attacks[s][magic_index<Pt>(s, occ)];
219+
return (Pt == ROOK ? RAttacks : BAttacks)[s][magic_index<Pt>(s, occ)];
221220
}
222221

223222

0 commit comments

Comments
 (0)