-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCastlingRights.cpp
53 lines (42 loc) · 1.45 KB
/
CastlingRights.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
#include "CastlingRights.hpp"
#include <type_traits>
#include <ostream>
CastlingRights operator&(CastlingRights lhs, CastlingRights rhs) {
using T = std::underlying_type_t<CastlingRights>;
return static_cast<CastlingRights>(static_cast<T>(lhs) & static_cast<T>(rhs));
}
CastlingRights& operator&=(CastlingRights& lhs, CastlingRights rhs) {
lhs = lhs & rhs;
return lhs;
}
CastlingRights operator|(CastlingRights lhs, CastlingRights rhs) {
using T = std::underlying_type_t<CastlingRights>;
return static_cast<CastlingRights>(static_cast<T>(lhs) | static_cast<T>(rhs));
}
CastlingRights& operator|=(CastlingRights& lhs, CastlingRights rhs) {
lhs = lhs | rhs;
return lhs;
}
CastlingRights operator~(CastlingRights cr) {
using T = std::underlying_type_t<CastlingRights>;
return static_cast<CastlingRights>(~static_cast<T>(cr));
}
std::ostream& operator<<(std::ostream& os, CastlingRights cr) {
if (cr == CastlingRights::None) {
return os << "-";
} else {
if ((cr & CastlingRights::WhiteKingside) != CastlingRights::None) {
os << "K";
}
if ((cr & CastlingRights::WhiteQueenside) != CastlingRights::None) {
os << "Q";
}
if ((cr & CastlingRights::BlackKingside) != CastlingRights::None) {
os << "k";
}
if ((cr & CastlingRights::BlackQueenside) != CastlingRights::None) {
os << "q";
}
return os;
}
}