Skip to content

Commit 2236ac9

Browse files
committed
implemented king legal moves
1 parent 01b7c07 commit 2236ac9

File tree

2 files changed

+499
-0
lines changed

2 files changed

+499
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <bitbishop/board.hpp>
2+
#include <bitbishop/color.hpp>
3+
#include <bitbishop/lookups/king_attacks.hpp>
4+
#include <bitbishop/move.hpp>
5+
#include <utility>
6+
#include <vector>
7+
8+
void generate_legal_king_moves(std::vector<Move>& moves, const Board& board, Color us, Square king_sq,
9+
const Bitboard& enemy_attacks, const Bitboard& check_mask) {
10+
const Bitboard own = board.friendly(us);
11+
const Bitboard enemy = board.enemy(us);
12+
13+
Bitboard candidates = Lookups::KING_ATTACKS[king_sq.value()];
14+
15+
candidates &= ~own;
16+
candidates &= ~enemy_attacks;
17+
candidates &= check_mask;
18+
19+
for (Square to : candidates) {
20+
const bool is_capture = enemy.test(to);
21+
moves.emplace_back(king_sq, to, std::nullopt, is_capture, false, false);
22+
}
23+
}

0 commit comments

Comments
 (0)