-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmovegen.cpp
More file actions
105 lines (96 loc) · 4.08 KB
/
Copy pathmovegen.cpp
File metadata and controls
105 lines (96 loc) · 4.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include "defs.h"
#include <iostream>
void add_move(MoveList *move_list, int source, int target, int piece, int capture) {
Move move;
move.source = source;
move.target = target;
move.piece = piece;
move.capture = capture;
move_list->moves[move_list->count] = move;
move_list->count++;
}
void generate_moves(MoveList *move_list) {
move_list->count = 0;
int source_square, target_square;
U64 bitboard, attacks;
U64 occupancy[3];
occupancy[WHITE] = bitboards[P] | bitboards[N] | bitboards[B] | bitboards[R] | bitboards[Q] | bitboards[K];
occupancy[BLACK] = bitboards[p] | bitboards[n] | bitboards[b] | bitboards[r] | bitboards[q] | bitboards[k];
occupancy[BOTH] = occupancy[WHITE] | occupancy[BLACK];
if (side == WHITE) {
bitboard = bitboards[N];
while (bitboard) {
source_square = get_ls1b_index(bitboard);
attacks = knight_attacks[source_square] & ~occupancy[WHITE];
while (attacks) {
target_square = get_ls1b_index(attacks);
int capture = GET_BIT(occupancy[BLACK], target_square) ? 1 : 0;
add_move(move_list, source_square, target_square, N, capture);
POP_BIT(attacks, target_square);
}
POP_BIT(bitboard, source_square);
}
bitboard = bitboards[K];
while (bitboard) {
source_square = get_ls1b_index(bitboard);
attacks = king_attacks[source_square] & ~occupancy[WHITE];
while (attacks) {
target_square = get_ls1b_index(attacks);
int capture = GET_BIT(occupancy[BLACK], target_square) ? 1 : 0;
add_move(move_list, source_square, target_square, K, capture);
POP_BIT(attacks, target_square);
}
POP_BIT(bitboard, source_square);
}
bitboard = bitboards[R];
while (bitboard) {
source_square = get_ls1b_index(bitboard);
attacks = get_rook_attacks(source_square, occupancy[BOTH]) & ~occupancy[WHITE];
while (attacks) {
target_square = get_ls1b_index(attacks);
int capture = GET_BIT(occupancy[BLACK], target_square) ? 1 : 0;
add_move(move_list, source_square, target_square, R, capture);
POP_BIT(attacks, target_square);
}
POP_BIT(bitboard, source_square);
}
}
else {
bitboard = bitboards[n];
while (bitboard) {
source_square = get_ls1b_index(bitboard);
attacks = knight_attacks[source_square] & ~occupancy[BLACK];
while (attacks) {
target_square = get_ls1b_index(attacks);
int capture = GET_BIT(occupancy[WHITE], target_square) ? 1 : 0;
add_move(move_list, source_square, target_square, n, capture);
POP_BIT(attacks, target_square);
}
POP_BIT(bitboard, source_square);
}
bitboard = bitboards[k];
while (bitboard) {
source_square = get_ls1b_index(bitboard);
attacks = king_attacks[source_square] & ~occupancy[BLACK];
while (attacks) {
target_square = get_ls1b_index(attacks);
int capture = GET_BIT(occupancy[WHITE], target_square) ? 1 : 0;
add_move(move_list, source_square, target_square, k, capture);
POP_BIT(attacks, target_square);
}
POP_BIT(bitboard, source_square);
}
bitboard = bitboards[r];
while (bitboard) {
source_square = get_ls1b_index(bitboard);
attacks = get_rook_attacks(source_square, occupancy[BOTH]) & ~occupancy[BLACK];
while (attacks) {
target_square = get_ls1b_index(attacks);
int capture = GET_BIT(occupancy[WHITE], target_square) ? 1 : 0;
add_move(move_list, source_square, target_square, r, capture);
POP_BIT(attacks, target_square);
}
POP_BIT(bitboard, source_square);
}
}
}