Othello.hpp
A simple Othello game state handler.
- Todo:
Add Hash for boards to be able to cachce moves.
Setup OPTIONAL caching of expensive board measures.
Typedefs
-
using Othello = Othello_Game<8>
-
struct Othello_Base
- #include <Othello.hpp>
Base class for all sizes of 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.
Subclassed by Othello_Game< BOARD_SIZE >
Public Types
Public Static Attributes
-
static constexpr size_t NUM_DIRECTIONS = 8
Number of neighbors each board space has.
-
template<size_t BOARD_SIZE>
class Othello_Game : public Othello_Base - #include <Othello.hpp>
Class for othello games of a specific size.
Public Types
-
using this_t = Othello_Game<BOARD_SIZE>
Public Functions
-
inline Othello_Game()
-
inline ~Othello_Game()
-
inline void Reset()
Reset the board to the starting condition.
-
inline constexpr size_t GetBoardWidth() const
-
inline size_t GetNumCells() const
-
inline Player GetCurPlayer() const
-
inline Player GetOpponent(Player player) const
Get opponent ID of give player ID.
-
inline bool IsValidPlayer(Player player) const
Is the given player ID a valid player?
-
inline auto BuildNeighbors()
-
inline Index GetNeighbor(Index id, Facing dir) const
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 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 double GetScore(Player player)
Get the current score for a 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_t &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 void SetCurPlayer(Player player)
Set the current player.
-
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 Attributes
-
static constexpr size_t NUM_CELLS = BOARD_SIZE * BOARD_SIZE
Protected Attributes
-
bool over = false
Is the game over?
-
Player cur_player
Who is the current player set to move next?
Protected Static Functions
-
struct Index
- #include <Othello.hpp>
Public Functions
-
inline Index()
-
inline Index(size_t _pos)
-
inline Index(size_t x, size_t y)
-
inline operator size_t() const
-
inline size_t x() const
-
inline size_t y() const
-
inline void Set(size_t x, size_t y)
-
inline bool IsValid() const
Public Members
-
size_t pos
-
inline Index()
-
using this_t = Othello_Game<BOARD_SIZE>