Skip to content

Commit bd76ae4

Browse files
authored
Rewriting movegen (#230)
* rewriting_movegen bench:3720209 * reduced generation for quiets test * minor fix
1 parent c2faee1 commit bd76ae4

File tree

10 files changed

+633
-411
lines changed

10 files changed

+633
-411
lines changed

src_files/attacks.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ using namespace bb;
2727

2828
U64 attacks::ROOK_ATTACKS [N_SQUARES][4096]{};
2929
U64 attacks::BISHOP_ATTACKS[N_SQUARES][ 512]{};
30+
U64 attacks::PAWN_ATTACKS [N_SQUARES][N_COLORS]{};
31+
3032

3133
U64 populateMask(U64 mask, U64 index) {
3234
U64 res = 0;
@@ -73,6 +75,10 @@ void attacks::init() {
7375
#endif
7476
BISHOP_ATTACKS[n][index] = generateBishopAttacks(n, rel_occ);
7577
}
78+
79+
// pawn attacks
80+
PAWN_ATTACKS[n][WHITE] = shiftNorthWest(ONE << n) | shiftNorthEast(ONE << n);
81+
PAWN_ATTACKS[n][BLACK] = shiftSouthWest(ONE << n) | shiftSouthEast(ONE << n);
7682
}
7783
}
7884

src_files/attacks.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,11 @@ constexpr bb::U64 KNIGHT_ATTACKS[] {
154154
0x0004020000000000ULL, 0x0008050000000000ULL, 0x00110a0000000000ULL, 0x0022140000000000ULL,
155155
0x0044280000000000ULL, 0x0088500000000000ULL, 0x0010a00000000000ULL, 0x0020400000000000ULL};
156156

157+
158+
157159
extern bb::U64 ROOK_ATTACKS [bb::N_SQUARES][4096];
158160
extern bb::U64 BISHOP_ATTACKS[bb::N_SQUARES][ 512];
161+
extern bb::U64 PAWN_ATTACKS [bb::N_SQUARES][bb::N_COLORS];
159162

160163
void init();
161164

src_files/bitboard.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
namespace bb {
2424
U64 ALL_HASHES[N_PIECES][N_SQUARES] = {};
2525
U64 IN_BETWEEN_SQUARES[N_SQUARES][N_SQUARES];
26+
U64 PINNED_MOVEMENT_SQUARES[N_SQUARES][N_SQUARES];
2627

2728
U64 seed = 1293812938;
2829

@@ -40,12 +41,12 @@ U64 randU64() {
4041
}
4142

4243
void generateData() {
43-
// in between squares
4444
for (Square n = A1; n <= H8; n++) {
4545
for (Square i = A1; i <= H8; i++) {
4646
if (i == n)
4747
continue;
4848

49+
// in between squares
4950
U64 m = ZERO;
5051
U64 occ = ZERO;
5152
setBit(occ, n);
@@ -65,8 +66,17 @@ void generateData() {
6566
}
6667

6768
m &= ~occ;
68-
6969
IN_BETWEEN_SQUARES[n][i] = m;
70+
71+
// pinned squares (squares where pinned pieces can go to)
72+
// index by king and piece itself
73+
for(Direction d:{NORTH,SOUTH,WEST,EAST,NORTH_WEST,NORTH_EAST,SOUTH_WEST,SOUTH_EAST}){
74+
U64 attacks = attacks::generateSlidingAttacks(n, d, ZERO);
75+
if(attacks & occ){
76+
PINNED_MOVEMENT_SQUARES[n][i] = attacks;
77+
break;
78+
}
79+
}
7080
}
7181
}
7282
}

src_files/bitboard.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,10 @@ constexpr U64 CASTLING_BLACK_KINGSIDE_SAFE = CASTLING_WHITE_KINGSIDE_SAFE << (7
218218
extern U64 seed;
219219

220220

221-
extern U64 ALL_HASHES[N_PIECES][N_SQUARES];
221+
extern U64 ALL_HASHES[N_PIECES][N_SQUARES];
222+
extern U64 IN_BETWEEN_SQUARES[N_SQUARES][N_SQUARES];
223+
extern U64 PINNED_MOVEMENT_SQUARES[N_SQUARES][N_SQUARES];
222224

223-
extern U64 IN_BETWEEN_SQUARES[N_SQUARES][N_SQUARES];
224225
[[nodiscard]] inline Rank rankIndex(Square square_index) {
225226
return square_index >> 3;
226227
}
@@ -272,7 +273,7 @@ extern U64 IN_BETWEEN_SQUARES[N_SQUARES][N_SQUARES];
272273
return p & 0x7;
273274
}
274275

275-
[[nodiscard]] inline Piece getPiece(Color c, PieceType pt) {
276+
[[nodiscard]] inline constexpr Piece getPiece(Color c, PieceType pt) {
276277
return c * 8 + pt;
277278
}
278279

0 commit comments

Comments
 (0)