-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
move.h
executable file
·103 lines (84 loc) · 2.26 KB
/
move.h
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#ifndef MOVE_H
#define MOVE_H
#include "defines.h"
#include "piece.h"
namespace Napoleon
{
enum MoveType
{
KingCastle = 0x2, QueenCastle = 0x3, EnPassant = 0x5, QueenPromotion = 0xB,
RookPromotion = 0xA, BishopPromotion = 0x9, KnightPromotion = 0x8
};
class Board;
class Move
{
public:
Move();
Move(Square, Square);
Move(Square, Square, Square);
Square FromSquare() const;
Square ToSquare() const;
Square PiecePromoted() const;
int ButterflyIndex() const;
bool IsNull() const;
bool IsCastle() const;
bool IsCastleOO() const;
bool IsCastleOOO() const;
bool IsPromotion() const;
bool IsEnPassant() const;
bool operator== (const Move&) const;
bool operator!= (const Move&) const;
std::string ToAlgebraic() const;
std::string ToSan(Board&) const;
private:
unsigned short move;
};
INLINE Move::Move() { }
inline Move::Move(Square from, Square to)
{
move = (from & 0x3f) | ((to & 0x3f) << 6);
}
inline Move::Move(Square from, Square to, Square flag)
{
move = (from & 0x3f) | ((to & 0x3f) << 6) | ((flag & 0xf) << 12);
}
inline Square Move::FromSquare() const
{
return move & 0x3f;
}
inline Square Move::ToSquare() const
{
return (move >> 6) & 0x3f;
}
inline int Move::ButterflyIndex() const // used to index from-to based tables
{
return (move & 0xfff);
}
inline Square Move::PiecePromoted() const
{
if (!IsPromotion())
return PieceType::None;
return ((move >> 12) & 0x3) + 1;
}
inline bool Move::IsEnPassant() const
{
return ((move >> 12) == EnPassant); // e.p. are encoded 0101
}
inline bool Move::IsCastle() const
{
return (((move >> 12) == KingCastle) || ((move >> 12) == QueenCastle));
}
inline bool Move::IsPromotion() const
{
return ((move >> 12) & 0x8);
}
inline bool Move::operator ==(const Move& other) const
{
return (move == other.move);
}
inline bool Move::operator !=(const Move& other) const
{
return (move != other.move);
}
}
#endif // MOVE_H