Empirical
Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Static Protected Member Functions | Protected Attributes | List of all members
emp::Othello_Game< BOARD_SIZE > Class Template Reference

Class for othello games of a specific size. More...

#include <Othello.h>

Inheritance diagram for emp::Othello_Game< BOARD_SIZE >:
emp::Othello_Base

Classes

struct  Index
 

Public Types

using this_t = Othello_Game< BOARD_SIZE >
 
using board_t = std::array< Player, NUM_CELLS >
 
enum  Player { NONE =0, DARK, LIGHT }
 
enum  Facing {
  N, NE, E, SE,
  S, SW, W, NW
}
 

Public Member Functions

 Othello_Game ()
 
 ~Othello_Game ()
 
void Reset ()
 Reset the board to the starting condition. More...
 
constexpr size_t GetBoardWidth () const
 
size_t GetNumCells () const
 
Player GetCurPlayer () const
 
Player GetOpponent (Player player) const
 Get opponent ID of give player ID. More...
 
bool IsValidPlayer (Player player) const
 Is the given player ID a valid player? More...
 
auto BuildNeighbors ()
 
Index GetNeighbor (Index id, Facing dir) const
 
Player GetPosOwner (Index id) const
 Get the value (light, dark, or open) at a position on the board. More...
 
board_tGetBoard ()
 
const board_tGetBoard () const
 
bool IsValidMove (Player player, Index pos)
 Is given move valid? More...
 
bool IsOver () const
 
emp::vector< IndexGetFlipList (Player player, Index pos)
 
size_t GetFlipCount (Player player, Index pos)
 Count the number of positions that would flip if we placed a piece at a specific location. More...
 
bool HasValidFlips (Player player, Index pos)
 Are there any valid flips from this position? More...
 
emp::vector< IndexGetMoveOptions (Player player)
 Get a list of valid move options for given player. More...
 
emp::vector< IndexGetMoveOptions ()
 GetMoveOptions() without a specified player used current player. More...
 
bool HasMoveOptions (Player player)
 Determine if there are any move options for given player. More...
 
double GetScore (Player player)
 Get the current score for a given player. More...
 
size_t CountFrontierPos (Player player)
 Count the number of empty squares adjacent to a player's pieces (frontier size) More...
 
bool IsAdjacentTo (Index pos, Player owner)
 Is position given by ID adjacent to the given owner? More...
 
void SetPos (Index pos, Player player)
 Set board position (ID) to given space value. More...
 
void SetPositions (emp::vector< Index > ids, Player player)
 Set positions given by ids to be owned by the given player. More...
 
void SetBoard (const board_t &other_board)
 
void SetBoard (const this_t &other_othello)
 Set current board to be the same as board from other othello game. More...
 
void SetCurPlayer (Player player)
 Set the current player. More...
 
bool DoNextMove (Index pos)
 
bool DoMove (Player player, Index pos)
 
void DoFlips (Player player, Index pos)
 NOTE: does not check for move validity. More...
 
void Print (std::ostream &os=std::cout, std::string dark_token="D", std::string light_token="L", std::string open_space="O")
 Print board state to given ostream. More...
 

Static Public Member Functions

static constexpr Index GetIndex (size_t x, size_t y)
 

Static Public Attributes

static constexpr size_t NUM_CELLS = BOARD_SIZE * BOARD_SIZE
 
static constexpr size_t NUM_DIRECTIONS = 8
 Number of neighbors each board space has. More...
 

Static Protected Member Functions

static size_t GetNeighborIndex (Index pos, Facing dir)
 Internal function for accessing the neighbors vector. More...
 

Protected Attributes

std::array< Facing, NUM_DIRECTIONSALL_DIRECTIONS
 
emp::vector< Indexneighbors
 
bool over = false
 Is the game over? More...
 
Player cur_player
 Who is the current player set to move next? More...
 
board_t game_board
 Game board. More...
 

Detailed Description

template<size_t BOARD_SIZE>
class emp::Othello_Game< BOARD_SIZE >

Class for othello games of a specific size.

Member Typedef Documentation

template<size_t BOARD_SIZE>
using emp::Othello_Game< BOARD_SIZE >::board_t = std::array<Player, NUM_CELLS>
template<size_t BOARD_SIZE>
using emp::Othello_Game< BOARD_SIZE >::this_t = Othello_Game<BOARD_SIZE>

Member Enumeration Documentation

enum emp::Othello_Base::Facing
inherited
Enumerator
NE 
SE 
SW 
NW 
enum emp::Othello_Base::Player
inherited
Enumerator
NONE 
DARK 
LIGHT 

Constructor & Destructor Documentation

template<size_t BOARD_SIZE>
emp::Othello_Game< BOARD_SIZE >::Othello_Game ( )
inline
template<size_t BOARD_SIZE>
emp::Othello_Game< BOARD_SIZE >::~Othello_Game ( )
inline

Member Function Documentation

template<size_t BOARD_SIZE>
auto emp::Othello_Game< BOARD_SIZE >::BuildNeighbors ( )
inline
template<size_t BOARD_SIZE>
size_t emp::Othello_Game< BOARD_SIZE >::CountFrontierPos ( Player  player)
inline

Count the number of empty squares adjacent to a player's pieces (frontier size)

template<size_t BOARD_SIZE>
void emp::Othello_Game< BOARD_SIZE >::DoFlips ( Player  player,
Index  pos 
)
inline

NOTE: does not check for move validity.

template<size_t BOARD_SIZE>
bool emp::Othello_Game< BOARD_SIZE >::DoMove ( Player  player,
Index  pos 
)
inline

Do move (at pos) for specified player. Return bool whether player can go again. After making move, update current player. NOTE: Does not verify validity. Will switch cur_player from player to Opp(player) if opponent has a move to make.

template<size_t BOARD_SIZE>
bool emp::Othello_Game< BOARD_SIZE >::DoNextMove ( Index  pos)
inline

Do current player's move (moveID). Return bool indicating whether current player goes again. (false=new cur player or game over)

template<size_t BOARD_SIZE>
board_t& emp::Othello_Game< BOARD_SIZE >::GetBoard ( )
inline
template<size_t BOARD_SIZE>
const board_t& emp::Othello_Game< BOARD_SIZE >::GetBoard ( ) const
inline
template<size_t BOARD_SIZE>
constexpr size_t emp::Othello_Game< BOARD_SIZE >::GetBoardWidth ( ) const
inline
template<size_t BOARD_SIZE>
Player emp::Othello_Game< BOARD_SIZE >::GetCurPlayer ( ) const
inline
template<size_t BOARD_SIZE>
size_t emp::Othello_Game< BOARD_SIZE >::GetFlipCount ( Player  player,
Index  pos 
)
inline

Count the number of positions that would flip if we placed a piece at a specific location.

template<size_t BOARD_SIZE>
emp::vector<Index> emp::Othello_Game< BOARD_SIZE >::GetFlipList ( Player  player,
Index  pos 
)
inline

Get positions that would flip if a player (player) made a particular move (pos). Note: May be called before or after piece is placed.

template<size_t BOARD_SIZE>
static constexpr Index emp::Othello_Game< BOARD_SIZE >::GetIndex ( size_t  x,
size_t  y 
)
inlinestatic
template<size_t BOARD_SIZE>
emp::vector<Index> emp::Othello_Game< BOARD_SIZE >::GetMoveOptions ( Player  player)
inline

Get a list of valid move options for given player.

template<size_t BOARD_SIZE>
emp::vector<Index> emp::Othello_Game< BOARD_SIZE >::GetMoveOptions ( )
inline

GetMoveOptions() without a specified player used current player.

template<size_t BOARD_SIZE>
Index emp::Othello_Game< BOARD_SIZE >::GetNeighbor ( Index  id,
Facing  dir 
) const
inline

Get location adjacent to ID in direction dir. GetNeighbor function is save with garbage ID values.

template<size_t BOARD_SIZE>
static size_t emp::Othello_Game< BOARD_SIZE >::GetNeighborIndex ( Index  pos,
Facing  dir 
)
inlinestaticprotected

Internal function for accessing the neighbors vector.

template<size_t BOARD_SIZE>
size_t emp::Othello_Game< BOARD_SIZE >::GetNumCells ( ) const
inline
template<size_t BOARD_SIZE>
Player emp::Othello_Game< BOARD_SIZE >::GetOpponent ( Player  player) const
inline

Get opponent ID of give player ID.

template<size_t BOARD_SIZE>
Player emp::Othello_Game< BOARD_SIZE >::GetPosOwner ( Index  id) const
inline

Get the value (light, dark, or open) at a position on the board.

template<size_t BOARD_SIZE>
double emp::Othello_Game< BOARD_SIZE >::GetScore ( Player  player)
inline

Get the current score for a given player.

template<size_t BOARD_SIZE>
bool emp::Othello_Game< BOARD_SIZE >::HasMoveOptions ( Player  player)
inline

Determine if there are any move options for given player.

template<size_t BOARD_SIZE>
bool emp::Othello_Game< BOARD_SIZE >::HasValidFlips ( Player  player,
Index  pos 
)
inline

Are there any valid flips from this position?

template<size_t BOARD_SIZE>
bool emp::Othello_Game< BOARD_SIZE >::IsAdjacentTo ( Index  pos,
Player  owner 
)
inline

Is position given by ID adjacent to the given owner?

template<size_t BOARD_SIZE>
bool emp::Othello_Game< BOARD_SIZE >::IsOver ( ) const
inline
template<size_t BOARD_SIZE>
bool emp::Othello_Game< BOARD_SIZE >::IsValidMove ( Player  player,
Index  pos 
)
inline

Is given move valid?

template<size_t BOARD_SIZE>
bool emp::Othello_Game< BOARD_SIZE >::IsValidPlayer ( Player  player) const
inline

Is the given player ID a valid player?

template<size_t BOARD_SIZE>
void emp::Othello_Game< BOARD_SIZE >::Print ( std::ostream &  os = std::cout,
std::string  dark_token = "D",
std::string  light_token = "L",
std::string  open_space = "O" 
)
inline

Print board state to given ostream.

template<size_t BOARD_SIZE>
void emp::Othello_Game< BOARD_SIZE >::Reset ( )
inline

Reset the board to the starting condition.

template<size_t BOARD_SIZE>
void emp::Othello_Game< BOARD_SIZE >::SetBoard ( const board_t other_board)
inline

Configure board as given by copy_board input. copy_board size must match game_board's size.

template<size_t BOARD_SIZE>
void emp::Othello_Game< BOARD_SIZE >::SetBoard ( const this_t other_othello)
inline

Set current board to be the same as board from other othello game.

template<size_t BOARD_SIZE>
void emp::Othello_Game< BOARD_SIZE >::SetCurPlayer ( Player  player)
inline

Set the current player.

template<size_t BOARD_SIZE>
void emp::Othello_Game< BOARD_SIZE >::SetPos ( Index  pos,
Player  player 
)
inline

Set board position (ID) to given space value.

template<size_t BOARD_SIZE>
void emp::Othello_Game< BOARD_SIZE >::SetPositions ( emp::vector< Index ids,
Player  player 
)
inline

Set positions given by ids to be owned by the given player.

Member Data Documentation

template<size_t BOARD_SIZE>
std::array<Facing, NUM_DIRECTIONS> emp::Othello_Game< BOARD_SIZE >::ALL_DIRECTIONS
protected
template<size_t BOARD_SIZE>
Player emp::Othello_Game< BOARD_SIZE >::cur_player
protected

Who is the current player set to move next?

template<size_t BOARD_SIZE>
board_t emp::Othello_Game< BOARD_SIZE >::game_board
protected

Game board.

template<size_t BOARD_SIZE>
emp::vector<Index> emp::Othello_Game< BOARD_SIZE >::neighbors
protected
template<size_t BOARD_SIZE>
constexpr size_t emp::Othello_Game< BOARD_SIZE >::NUM_CELLS = BOARD_SIZE * BOARD_SIZE
static
constexpr size_t emp::Othello_Base::NUM_DIRECTIONS = 8
staticinherited

Number of neighbors each board space has.

template<size_t BOARD_SIZE>
bool emp::Othello_Game< BOARD_SIZE >::over = false
protected

Is the game over?


The documentation for this class was generated from the following file: