-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathMove.h
130 lines (88 loc) · 3.2 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
//-----------------------------------------------------------------------------
/** @file libpentobi_base/Move.h
@author Markus Enzenberger
@copyright GNU General Public License version 3 or later */
//-----------------------------------------------------------------------------
#ifndef LIBPENTOBI_BASE_MOVE_H
#define LIBPENTOBI_BASE_MOVE_H
#include <cstdint>
#include "libboardgame_base/Assert.h"
namespace libpentobi_base {
//-----------------------------------------------------------------------------
class Move
{
public:
/** Integer type used internally in this class to store a move.
This class is optimized for size not for speed because there are
large precomputed data structures that store moves and move lists.
Therefore it uses uint_least16_t, not uint_fast16_t. */
using IntType = std::uint_least16_t;
static constexpr IntType onboard_moves_classic = 30433;
static constexpr IntType onboard_moves_trigon = 32131;
static constexpr IntType onboard_moves_trigon_3 = 24859;
static constexpr IntType onboard_moves_duo = 13729;
static constexpr IntType onboard_moves_junior = 7217;
static constexpr IntType onboard_moves_nexos = 15157;
static constexpr IntType onboard_moves_callisto = 9433;
static constexpr IntType onboard_moves_callisto_2 = 4265;
static constexpr IntType onboard_moves_callisto_3 = 6885;
static constexpr IntType onboard_moves_gembloq = 31254;
static constexpr IntType onboard_moves_gembloq_2 = 15018;
static constexpr IntType onboard_moves_gembloq_3 = 23518;
/** Integer range of moves.
The maximum is given by the number of on-board moves in any game
variant, plus a null move. */
static constexpr IntType range = onboard_moves_trigon + 1;
static Move null() { return Move(0); }
Move();
explicit Move(IntType i);
bool operator==(Move mv) const;
bool operator!=(Move mv) const { return ! operator==(mv); }
bool operator<(Move mv) const;
bool is_null() const;
/** Return move as an integer between 0 and Move::range */
IntType to_int() const;
private:
static constexpr IntType value_uninitialized = range;
IntType m_i;
#ifdef LIBBOARDGAME_DEBUG
bool is_initialized() const { return m_i < value_uninitialized; }
#endif
};
inline Move::Move()
{
#ifdef LIBBOARDGAME_DEBUG
m_i = value_uninitialized;
#endif
}
inline Move::Move(IntType i)
{
LIBBOARDGAME_ASSERT(i < range);
m_i = i;
}
inline bool Move::operator==(Move mv) const
{
LIBBOARDGAME_ASSERT(is_initialized());
LIBBOARDGAME_ASSERT(mv.is_initialized());
return m_i == mv.m_i;
}
inline bool Move::operator<(Move mv) const
{
LIBBOARDGAME_ASSERT(is_initialized());
LIBBOARDGAME_ASSERT(mv.is_initialized());
return m_i < mv.m_i;
}
inline bool Move::is_null() const
{
LIBBOARDGAME_ASSERT(is_initialized());
return m_i == 0;
}
inline Move::IntType Move::to_int() const
{
LIBBOARDGAME_ASSERT(is_initialized());
return m_i;
}
//-----------------------------------------------------------------------------
} // namespace libpentobi_base
//-----------------------------------------------------------------------------
#endif // LIBPENTOBI_BASE_MOVE_H