-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
knight.cpp
executable file
·35 lines (31 loc) · 1.02 KB
/
knight.cpp
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
#include "knight.h"
#include "compassrose.h"
#include "movedatabase.h"
#include "utils.h"
#include "board.h"
namespace Napoleon
{
BitBoard Knight::GetAllTargets(BitBoard knights, Board& board)
{
BitBoard targets = MoveDatabase::KnightAttacks[(Utils::BitBoard::BitScanForward(knights))];
return targets & ~board.PlayerPieces();
}
BitBoard Knight::TargetsFrom(Square square, Color color, Board& board)
{
BitBoard targets = MoveDatabase::KnightAttacks[square];
return targets & ~board.Pieces(color);
}
BitBoard Knight::GetKnightAttacks(BitBoard knights)
{
BitBoard west, east, attacks;
east = CompassRose::OneStepEast(knights);
west = CompassRose::OneStepWest(knights);
attacks = (east | west) << 16;
attacks |= (east | west) >> 16;
east = CompassRose::OneStepEast(east);
west = CompassRose::OneStepWest(west);
attacks |= (east | west) << 8;
attacks |= (east | west) >> 8;
return attacks;
}
}