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
|
//-----------------------------------------------------------------------------
/** @file libpentobi_base/Piece.h
@author Markus Enzenberger
@copyright GNU General Public License version 3 or later */
//-----------------------------------------------------------------------------
#ifndef LIBPENTOBI_BASE_PIECE_H
#define LIBPENTOBI_BASE_PIECE_H
#include <cstdint>
#include "libboardgame_base/Assert.h"
namespace libpentobi_base {
//-----------------------------------------------------------------------------
/** Wrapper around an integer representing a piece type in a certain
game variant. */
class Piece
{
public:
using IntType = std::uint_fast8_t;
/** Maximum number of unique pieces per color. */
static constexpr IntType max_pieces = 24;
Piece();
explicit Piece(IntType i);
bool operator==(Piece piece) const { return m_i == piece.m_i; }
bool operator!=(Piece piece) const { return ! operator==(piece); }
/** Return move as an integer between 0 and Piece::range */
IntType to_int() const;
private:
static constexpr IntType value_uninitialized = max_pieces;
IntType m_i;
#ifdef LIBBOARDGAME_DEBUG
bool is_initialized() const { return m_i < value_uninitialized; }
#endif
};
inline Piece::Piece()
{
#ifdef LIBBOARDGAME_DEBUG
m_i = value_uninitialized;
#endif
}
inline Piece::Piece(IntType i)
{
LIBBOARDGAME_ASSERT(i < max_pieces);
m_i = i;
}
inline auto Piece::to_int() const -> IntType
{
LIBBOARDGAME_ASSERT(is_initialized());
return m_i;
}
//-----------------------------------------------------------------------------
} // namespace libpentobi_base
//-----------------------------------------------------------------------------
#endif // LIBPENTOBI_BASE_PIECE_H
|