Skip to content

Commit d0b4fa2

Browse files
committed
implemented legal knights moves generation
1 parent 39b2baa commit d0b4fa2

File tree

2 files changed

+501
-0
lines changed

2 files changed

+501
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#pragma once
2+
3+
#include <bitbishop/board.hpp>
4+
#include <bitbishop/color.hpp>
5+
#include <bitbishop/lookups/knight_attacks.hpp>
6+
#include <bitbishop/move.hpp>
7+
#include <bitbishop/movegen/pins.hpp>
8+
#include <utility>
9+
#include <vector>
10+
11+
void generate_knight_legal_moves(std::vector<Move>& moves, const Board& board, Color us, const Bitboard& check_mask,
12+
const PinResult& pins) {
13+
const Bitboard own = board.friendly(us);
14+
const Bitboard enemy = board.enemy(us);
15+
Bitboard knights = board.knights(us);
16+
knights &= ~pins.pinned;
17+
18+
// warning: this loop is destructive on Bitboard knights
19+
while (auto from_opt = knights.pop_lsb()) {
20+
Square from = from_opt.value();
21+
22+
Bitboard candidates = Lookups::KNIGHT_ATTACKS[from.value()];
23+
candidates &= ~own;
24+
candidates &= check_mask;
25+
26+
for (Square to : candidates) {
27+
const bool is_capture = enemy.test(to);
28+
moves.emplace_back(from, to, std::nullopt, is_capture, false, false);
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)