-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
pawn.cpp
executable file
·65 lines (56 loc) · 2.14 KB
/
pawn.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "pawn.h"
#include "board.h"
namespace Napoleon
{
BitBoard Pawn::GetAllTargets(BitBoard pawns, Board& board)
{
BitBoard empty = board.EmptySquares;
return GetQuietTargets(board.SideToMove(), pawns, empty) | GetAnyAttack(pawns, board);
}
BitBoard Pawn::GetAnyAttack(BitBoard pawns, Board& board)
{
return (GetEastAttacks(board.SideToMove(), pawns) | GetWestAttacks(board.SideToMove(), pawns)) & board.EnemyPieces();
}
BitBoard Pawn::GetAnyAttack(BitBoard pawns, Color color, BitBoard squares)
{
return (GetEastAttacks(color, pawns) | GetWestAttacks(color, pawns)) & squares;
}
BitBoard Pawn::GetPawnsAbleToSinglePush(Color color, BitBoard pawns, BitBoard empty)
{
switch (color)
{
case PieceColor::White:
return CompassRose::OneStepSouth(empty) & pawns;
case PieceColor::Black:
return CompassRose::OneStepNorth(empty) & pawns;
default:
throw std::exception();
}
}
BitBoard Pawn::GetPawnsAbleToDoublePush(Color color, BitBoard pawns, BitBoard empty)
{
switch (color)
{
case PieceColor::White:
{
BitBoard emptyRank3 = CompassRose::OneStepSouth(empty & Constants::Ranks::Four) & empty;
return GetPawnsAbleToSinglePush(color, pawns, emptyRank3);
}
case PieceColor::Black:
{
BitBoard emptyRank6 = CompassRose::OneStepNorth(empty & Constants::Ranks::Six) & empty;
return GetPawnsAbleToSinglePush(color, pawns, emptyRank6);
}
default:
throw std::exception();
}
}
BitBoard Pawn::GetEastAttacks(Color color, BitBoard pawns)
{
return color == PieceColor::White ? CompassRose::OneStepNorthEast(pawns) : CompassRose::OneStepSouthEast(pawns);
}
BitBoard Pawn::GetWestAttacks(Color color, BitBoard pawns)
{
return color == PieceColor::White ? CompassRose::OneStepNorthWest(pawns) : CompassRose::OneStepSouthWest(pawns);
}
}