Empirical
Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Types | Static Protected Member Functions | Protected Attributes | List of all members
emp::Othello8 Class Reference

Class for size-8 othello games. More...

#include <Othello8.h>

Classes

struct  Board
 
struct  Index
 

Public Types

enum  Player { DARK =0, LIGHT =1, NONE }
 
enum  Facing {
  N, NE, E, SE,
  S, SW, W, NW
}
 
using this_t = Othello8
 

Public Member Functions

 Othello8 ()
 
 ~Othello8 ()
 
void Reset ()
 Reset the board to the starting condition. More...
 
size_t GetNumCells () const
 
Player GetCurPlayer () const
 
size_t GetHash () 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...
 
Index GetNeighbor (Index id, Facing dir)
 
Player GetPosOwner (Index id) const
 Get the value (light, dark, or open) at a position on the board. More...
 
BoardGetBoard ()
 
const BoardGetBoard () const
 
bool IsValidMove (Player player, Index pos)
 Is given move valid? More...
 
bool IsOver () const
 
void SetupCache ()
 
const emp::vector< Index > & GetFlipList (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 ClearPos (Index pos)
 
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 &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 constexpr size_t GetBoardWidth ()
 

Static Public Attributes

static constexpr size_t NUM_DIRECTIONS = 8
 Number of neighbors each board space has. More...
 
static constexpr size_t BOARD_SIZE = 8
 Size of a side of the board. More...
 
static constexpr size_t NUM_CELLS = 64
 Number of cells on total board. More...
 

Protected Types

using flip_list_t = emp::vector< Index >
 

Static Protected Member Functions

static const auto & ALL_DIRECTIONS ()
 All eight cardinal directions. More...
 
static size_t GetNeighborIndex (Index pos, Facing dir)
 Internal function for accessing the neighbors vector. More...
 
static const auto & NEIGHBORS ()
 Precalculated neighbors. More...
 

Protected Attributes

bool over = false
 Is the game over? More...
 
Player cur_player
 Who is the current player set to move next? More...
 
Board game_board
 Game board. More...
 
std::array< flip_list_t, NUM_CELLSlight_flips
 
std::array< flip_list_t, NUM_CELLSdark_flips
 
bool cache_ok
 

Detailed Description

Class for size-8 othello games.

NOTE: This game could be made more black-box.

Member Typedef Documentation

Member Enumeration Documentation

Enumerator
NE 
SE 
SW 
NW 
Enumerator
DARK 
LIGHT 
NONE 

Constructor & Destructor Documentation

emp::Othello8::Othello8 ( )
inline
emp::Othello8::~Othello8 ( )
inline

Member Function Documentation

static const auto& emp::Othello8::ALL_DIRECTIONS ( )
inlinestaticprotected

All eight cardinal directions.

void emp::Othello8::ClearPos ( Index  pos)
inline
size_t emp::Othello8::CountFrontierPos ( Player  player)
inline

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

void emp::Othello8::DoFlips ( Player  player,
Index  pos 
)
inline

NOTE: does not check for move validity.

bool emp::Othello8::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.

bool emp::Othello8::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)

Board& emp::Othello8::GetBoard ( )
inline
const Board& emp::Othello8::GetBoard ( ) const
inline
static constexpr size_t emp::Othello8::GetBoardWidth ( )
inlinestatic
Player emp::Othello8::GetCurPlayer ( ) const
inline
size_t emp::Othello8::GetFlipCount ( Player  player,
Index  pos 
)
inline

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

const emp::vector<Index>& emp::Othello8::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.

size_t emp::Othello8::GetHash ( ) const
inline
static constexpr Index emp::Othello8::GetIndex ( size_t  x,
size_t  y 
)
inlinestatic
emp::vector<Index> emp::Othello8::GetMoveOptions ( Player  player)
inline

Get a list of valid move options for given player.

emp::vector<Index> emp::Othello8::GetMoveOptions ( )
inline

GetMoveOptions() without a specified player used current player.

Index emp::Othello8::GetNeighbor ( Index  id,
Facing  dir 
)
inline

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

static size_t emp::Othello8::GetNeighborIndex ( Index  pos,
Facing  dir 
)
inlinestaticprotected

Internal function for accessing the neighbors vector.

size_t emp::Othello8::GetNumCells ( ) const
inline
Player emp::Othello8::GetOpponent ( Player  player) const
inline

Get opponent ID of give player ID.

Player emp::Othello8::GetPosOwner ( Index  id) const
inline

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

double emp::Othello8::GetScore ( Player  player)
inline

Get the current score for a given player.

bool emp::Othello8::HasMoveOptions ( Player  player)
inline

Determine if there are any move options for given player.

bool emp::Othello8::HasValidFlips ( Player  player,
Index  pos 
)
inline

Are there any valid flips from this position?

bool emp::Othello8::IsAdjacentTo ( Index  pos,
Player  owner 
)
inline

Is position given by ID adjacent to the given owner?

bool emp::Othello8::IsOver ( ) const
inline
bool emp::Othello8::IsValidMove ( Player  player,
Index  pos 
)
inline

Is given move valid?

bool emp::Othello8::IsValidPlayer ( Player  player) const
inline

Is the given player ID a valid player?

static const auto& emp::Othello8::NEIGHBORS ( )
inlinestaticprotected

Precalculated neighbors.

void emp::Othello8::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.

void emp::Othello8::Reset ( )
inline

Reset the board to the starting condition.

void emp::Othello8::SetBoard ( const Board other_board)
inline

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

void emp::Othello8::SetBoard ( const this_t other_othello)
inline

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

void emp::Othello8::SetCurPlayer ( Player  player)
inline

Set the current player.

void emp::Othello8::SetPos ( Index  pos,
Player  player 
)
inline

Set board position (ID) to given space value.

void emp::Othello8::SetPositions ( emp::vector< Index ids,
Player  player 
)
inline

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

void emp::Othello8::SetupCache ( )
inline

Member Data Documentation

constexpr size_t emp::Othello8::BOARD_SIZE = 8
static

Size of a side of the board.

bool emp::Othello8::cache_ok
protected
Player emp::Othello8::cur_player
protected

Who is the current player set to move next?

std::array<flip_list_t, NUM_CELLS> emp::Othello8::dark_flips
protected
Board emp::Othello8::game_board
protected

Game board.

std::array<flip_list_t, NUM_CELLS> emp::Othello8::light_flips
protected
constexpr size_t emp::Othello8::NUM_CELLS = 64
static

Number of cells on total board.

constexpr size_t emp::Othello8::NUM_DIRECTIONS = 8
static

Number of neighbors each board space has.

bool emp::Othello8::over = false
protected

Is the game over?


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