blob: 0938de9f5a18fa75589c0f71c6ddfa80120adb07 (
plain)
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
|
#define MOVES_INTERNAL
#include "engine/moves.h"
void __forloop_rook_moves_gen(
moves_t* moves,
bitboard_t friendly_type,
bitboard_t friendly_pieces,
bitboard_t enemy_pieces
) {
bitboard_t all_occupied = friendly_pieces | enemy_pieces;
while (friendly_type) {
int from = __builtin_ctzll(friendly_type);
friendly_type &= friendly_type - 1;
bitboard_t attacks = get_rook_attacks(from, all_occupied) & ~friendly_pieces;
while (attacks) {
int to = __builtin_ctzll(attacks);
attacks &= attacks - 1;
add_move(moves, from, to, .flags = ((enemy_pieces >> to) & 1) ? MOVE_CAPTURE : 0);
}
}
}
void get_rook_moves(moves_t* moves, position_t position) {
assert_valid_position(position);
bitboard_t friendly_rooks;
bitboard_t friendly_pieces;
bitboard_t enemy_pieces;
if (position.turn == WHITE_TURN) {
friendly_pieces = whites(position);
enemy_pieces = blacks(position);
friendly_rooks = position.bitboards[WHITE_ROOK];
} else {
friendly_pieces = blacks(position);
enemy_pieces = whites(position);
friendly_rooks = position.bitboards[BLACK_ROOK];
}
__forloop_rook_moves_gen(
moves,
friendly_rooks,
friendly_pieces,
enemy_pieces
);
}
|