Add Pseudo Move Generator #12
@@ -76,6 +76,53 @@ static int pop_lsb_index(uint64_t *bb) {
|
||||
return idx;
|
||||
}
|
||||
|
||||
static inline uint64_t ray_attacks(int start_square, int delta_file, int delta_rank, uint64_t occupied)
|
||||
{
|
||||
uint64_t attacks = 0;
|
||||
|
||||
int start_file = start_square % 8;
|
||||
int start_rank = start_square / 8;
|
||||
|
||||
int next_file = start_file + delta_file;
|
||||
int next_rank = start_rank + delta_rank;
|
||||
|
||||
while (next_file >= 0 && next_file < 8 && next_rank >= 0 && next_rank < 8) {
|
||||
int next_square = next_rank * 8 + next_file;
|
||||
uint64_t next_bit = 1ULL << next_square;
|
||||
|
||||
// can attack this square
|
||||
attacks |= next_bit;
|
||||
|
||||
// blocker: include it, then stop
|
||||
if (occupied & next_bit)
|
||||
break;
|
||||
|
||||
next_file += delta_file;
|
||||
next_rank += delta_rank;
|
||||
}
|
||||
|
||||
return attacks;
|
||||
}
|
||||
|
||||
static inline uint64_t rook_attacks(int square, uint64_t occupied) {
|
||||
return ray_attacks(square, +1, 0, occupied) // east
|
||||
| ray_attacks(square, -1, 0, occupied) // west
|
||||
| ray_attacks(square, 0, +1, occupied) // north
|
||||
| ray_attacks(square, 0, -1, occupied); // south
|
||||
}
|
||||
|
||||
static inline uint64_t bishop_attacks(int square, uint64_t occupied) {
|
||||
return ray_attacks(square, +1, +1, occupied) // NE
|
||||
| ray_attacks(square, -1, +1, occupied) // NW
|
||||
| ray_attacks(square, +1, -1, occupied) // SE
|
||||
| ray_attacks(square, -1, -1, occupied); // SW
|
||||
}
|
||||
|
||||
static inline uint64_t queen_attacks(int square, uint64_t occupied) {
|
||||
// Simply combine both types of attacks
|
||||
return rook_attacks(square, occupied) | bishop_attacks(square, occupied);
|
||||
}
|
||||
|
||||
void print_board(const struct Board *b) {
|
||||
static const char PIECE_CH[12] = {
|
||||
'P','N','B','R','Q','K',
|
||||
|
||||
Reference in New Issue
Block a user