Othello8.hpp
A simple Othello game state handler limited to an 8x8 board.
- Todo:
Add Hash for boards to be able to cachce moves.
Setup OPTIONAL caching of expensive board measures.
-
class Othello8
- #include <Othello8.hpp>
Class for size-8 othello games.
NOTE: This game could be made more black-box.
Hide almost everything. Only give users access to game-advancing functions (don’t allow willy-nilly board manipulation, etc). This would let us make lots of assumptions about calculating flip lists, scores, etc, which would speed up asking for flip lists, etc. multiple times during a turn.
Public Types
Public Functions
-
inline Othello8()
-
inline ~Othello8()
-
inline void Reset()
Reset the board to the starting condition.
-
inline size_t GetNumCells() const
-
inline size_t GetHash() const
-
inline Index GetNeighbor(Index id, Facing dir)
Get location adjacent to ID in direction dir. GetNeighbor function is save with garbage ID values.
-
inline Player GetPosOwner(Index id) const
Get the value (light, dark, or open) at a position on the board.
-
inline bool IsOver() const
-
inline void SetupCache()
-
inline const vector<Index> &GetFlipList(Player player, Index pos)
Get positions that would flip if a player (player) made a particular move (pos). Note: May be called before or after piece is placed.
-
inline size_t GetFlipCount(Player player, Index pos)
Count the number of positions that would flip if we placed a piece at a specific location.
-
inline vector<Index> GetMoveOptions(Player player)
Get a list of valid move options for given player.
-
inline vector<Index> GetMoveOptions()
GetMoveOptions() without a specified player used current player.
-
inline bool HasMoveOptions(Player player)
Determine if there are any move options for given player.
-
inline size_t CountFrontierPos(Player player)
Count the number of empty squares adjacent to a player’s pieces (frontier size)
-
inline bool IsAdjacentTo(Index pos, Player owner)
Is position given by ID adjacent to the given owner?
-
inline void SetPositions(vector<Index> ids, Player player)
Set positions given by ids to be owned by the given player.
-
inline void SetBoard(const Board &other_board)
Configure board as given by copy_board input. copy_board size must match game_board’s size.
-
inline void SetBoard(const this_t &other_othello)
Set current board to be the same as board from other othello game.
-
inline bool DoNextMove(Index pos)
Do current player’s move (moveID). Return bool indicating whether current player goes again. (false=new cur player or game over)
Public Static Functions
-
static inline constexpr size_t GetBoardWidth()
Public Static Attributes
-
static constexpr size_t NUM_DIRECTIONS = 8
Number of neighbors each board space has.
-
static constexpr size_t BOARD_SIZE = 8
Size of a side of the board.
-
static constexpr size_t NUM_CELLS = 64
Number of cells on total board.
Protected Attributes
-
bool over = false
Is the game over?
-
std::array<flip_list_t, NUM_CELLS> light_flips
-
std::array<flip_list_t, NUM_CELLS> dark_flips
-
bool cache_ok
Protected Static Functions
-
static inline const auto &ALL_DIRECTIONS()
All eight cardinal directions.
-
static inline size_t GetNeighborIndex(Index pos, Facing dir)
Internal function for accessing the neighbors vector.
-
static inline const auto &NEIGHBORS()
Precalculated neighbors.
-
struct Index
- #include <Othello8.hpp>
Public Functions
-
inline constexpr Index()
-
inline constexpr Index(size_t _pos)
-
inline constexpr Index(size_t x, size_t y)
-
inline constexpr operator size_t() const
-
inline constexpr size_t x() const
-
inline constexpr size_t y() const
-
inline constexpr void Set(size_t x, size_t y)
-
inline constexpr bool IsValid() const
Public Members
-
size_t pos
-
inline constexpr Index()