Game of Ur 0.3.3
This is a computer adaptation of Game of Ur, written in C++ mainly using SDL and OpenGL.
Loading...
Searching...
No Matches
GameOfUrModel Class Reference

The data model representing one instance of Game of Ur. More...

#include <model.hpp>

Public Member Functions

 GameOfUrModel ()=default
 Constructs a new game of ur model.
 
 GameOfUrModel (GameOfUrModel &&other)=default
 Constructs a new game of ur model by stealing resources from another instance.
 
GameOfUrModeloperator= (GameOfUrModel &&other)
 Replaces resources owned by this model with those stolen from another instance.
 
 GameOfUrModel (const GameOfUrModel &other)=delete
 
GameOfUrModeloperator= (const GameOfUrModel &other)=delete
 
void reset ()
 Resets the game to its initial state, losing track of its current one.
 
void startPhasePlay ()
 Starts the play phase of the game, where counters are placed into the common pile, roles are assigned to each player, and the turn for the player playing black is begun.
 
void rollDice (PlayerID requester)
 Rolls dice on behalf of the requester.
 
void movePiece (PieceIdentity piece, glm::u8vec2 toLocation, PlayerID requester)
 Moves a piece from its current state or location to the one requested.
 
void advanceOneTurn (PlayerID requester)
 Advances the game by one turn, usually starting the turn of the next player.
 
std::vector< PieceTypeIDgetUnlaunchedPieceTypes (PlayerID player) const
 Gets the types of the pieces that this player hasn't yet launched.
 
std::vector< std::pair< PieceIdentity, glm::u8vec2 > > getAllPossibleMoves () const
 Gets a list of every possible move that can be made given the game's current state.
 
std::vector< glm::u8vec2 > getLaunchPositions (const PieceIdentity &pieceIdentity) const
 Gets a list of positions a particular piece may be launched to.
 
uint8_t getNCounters () const
 Gets the number of counters held in the common pile.
 
GamePhaseData getCurrentPhase () const
 Gets a description of the current phase of the game.
 
GameScoreData getScore () const
 Gets the current scores for the game.
 
HouseData getHouseData (glm::u8vec2 location) const
 Gets the data relating to the house present at a given location.
 
GamePieceData getPieceData (PieceIdentity gamePiece) const
 Gets information about a particular piece.
 
GamePieceData getPieceData (PlayerID player, PieceTypeID pieceType) const
 Gets information about a particular piece.
 
PlayerData getPlayerData (PlayerID player) const
 Gets information about a player.
 
PlayerData getPlayerData (RoleID player) const
 Gets information about a player.
 
PlayerData getCurrentPlayer () const
 Gets information about the player whose turn it currently is.
 
DiceData getDiceData () const
 Gets information about the current state of this game's dice.
 
MoveResultData getBoardMoveData (PieceIdentity piece) const
 Gets data about the results of making a move with the current dice roll with a piece present on the board.
 
MoveResultData getLaunchMoveData (PieceIdentity piece, glm::u8vec2 launchLocation) const
 Gets data about the results of launching a piece that hasn't yet been launched with the current dice roll.
 
bool canRollDice (PlayerID requester) const
 Tests whether the game dice can be rolled now.
 
bool canLaunchPieceTo (PieceIdentity pieceIdentity, glm::u8vec2 toLocation, PlayerID requester) const
 Tests whether a piece can be launched to a particular location.
 
bool canLaunchPiece (PieceIdentity pieceIdentity, PlayerID requester) const
 Tests whether a particular piece can be launched (at all).
 
bool canMoveBoardPiece (PieceIdentity pieceIdentity, PlayerID requester) const
 Tests whether a piece already on the board can be moved to a new location.
 
bool canAdvanceOneTurn (PlayerID requester) const
 Tests whether the end of the current turn has been reached, and that the next one can begin.
 
bool canStartPhasePlay () const
 Tests whether the end of the initiative phase has been reached, and whether the play phase may now begin.
 

Private Member Functions

bool canMovePiece (PieceIdentity pieceIdentity, glm::u8vec2 toLocation, PlayerID requester) const
 The underlying implementation for canLaunchPiece(), canLaunchPieceTo(), and canMoveBoardPiece().
 
RoleID getWinner () const
 Gets the role of the winner of the game, and NA if there isn't one yet.
 
RoleID getRole (PlayerID player) const
 Gets the role assigned to a particular player.
 
PlayerID getPlayer (RoleID role) const
 Gets the ID of the player to whom a particular role is assigned.
 
const PiecegetPiece (const PieceIdentity &pieceIdentity) const
 Gets a reference to (the sole instance of) a particular piece.
 
MoveResultData getMoveData (PieceIdentity piece, glm::u8vec2 moveLocation) const
 Gets data about a move which may be made with some piece (including whether a move is even possible).
 
void deductCounters (uint8_t counters, PlayerID fromPlayer)
 Moves some number of counters from a player into the common pile.
 
void payCounters (uint8_t counters, PlayerID toPlayer)
 Moves some number of counters from the common pile into a player's possession.
 
void endTurn ()
 Ends the current turn.
 

Private Attributes

GamePhase mGamePhase { GamePhase::INITIATIVE }
 The current phase of the game as a whole.
 
TurnPhase mTurnPhase { TurnPhase::ROLL_DICE }
 The current phase of the turn the game is in.
 
RoundPhase mRoundPhase { RoundPhase::IN_PROGRESS }
 The current phase of the round (every pair of turns).
 
PlayerID mCurrentPlayer { PLAYER_A }
 The player appointed to take action during this turn.
 
uint8_t mCounters { 0 }
 The number of counters held in the game's common pile.
 
std::unique_ptr< DicemDice { std::make_unique<Dice>() }
 A reference to the data model of the dice used in this game.
 
Board mBoard {}
 The data model for the board used by this game.
 
std::array< Player, 2 > mPlayers {}
 Data models for the two players of the game.
 
uint8_t mPreviousRoll {0}
 The final result of the dice roll in the previous turn of this game.
 

Detailed Description

The data model representing one instance of Game of Ur.

Maintains information and references to the game board, its pieces, its players, the counters possessed by each player and held in common. Provides methods for advancing the game and querying its current state.

An instance of this object should be, at all times, treated as the single source of truth about the game.

Constructor & Destructor Documentation

◆ GameOfUrModel()

GameOfUrModel::GameOfUrModel ( GameOfUrModel && other)
default

Constructs a new game of ur model by stealing resources from another instance.

Parameters
otherThe model being stolen from.

Member Function Documentation

◆ advanceOneTurn()

void GameOfUrModel::advanceOneTurn ( PlayerID requester)

Advances the game by one turn, usually starting the turn of the next player.

Warning
This method assumes that the fact that the turn can be advanced has already been verified, and will throw an error if it can't.
Parameters
requesterThe player requesting a move to the next turn.

◆ canAdvanceOneTurn()

bool GameOfUrModel::canAdvanceOneTurn ( PlayerID requester) const

Tests whether the end of the current turn has been reached, and that the next one can begin.

Parameters
requesterThe player requesting the end of the turn.
Return values
trueThe game may be advanced by a turn.
falseThe game cannot move to the next turn.

◆ canLaunchPiece()

bool GameOfUrModel::canLaunchPiece ( PieceIdentity pieceIdentity,
PlayerID requester ) const

Tests whether a particular piece can be launched (at all).

Parameters
pieceIdentityThe identity of the piece being launched.
requesterThe player requesting the launch.
Return values
trueLaunching the piece is possible.
falseLaunching the piece is impossible.

◆ canLaunchPieceTo()

bool GameOfUrModel::canLaunchPieceTo ( PieceIdentity pieceIdentity,
glm::u8vec2 toLocation,
PlayerID requester ) const

Tests whether a piece can be launched to a particular location.

Parameters
pieceIdentityThe identity of the piece being launched.
toLocationThe location to which the piece should be launched.
requesterThe player requesting the launch of the piece.
Return values
trueLaunching the piece is possible.
falseLaunching the piece is not possible.

◆ canMoveBoardPiece()

bool GameOfUrModel::canMoveBoardPiece ( PieceIdentity pieceIdentity,
PlayerID requester ) const

Tests whether a piece already on the board can be moved to a new location.

Parameters
pieceIdentityThe identity of the piece being moved.
requesterThe player requesting the move.
Return values
trueThe piece may be moved.
falseThe piece can't be moved.

◆ canMovePiece()

bool GameOfUrModel::canMovePiece ( PieceIdentity pieceIdentity,
glm::u8vec2 toLocation,
PlayerID requester ) const
private

The underlying implementation for canLaunchPiece(), canLaunchPieceTo(), and canMoveBoardPiece().

Parameters
pieceIdentityThe identity of the piece being moved.
toLocationThe location to which the player wants the piece to move.
requesterThe player making the request for the move.
Return values
trueThe piece can be moved to the house at the indicated location.
falseThe piece can't be moved to the house at the indicated location.

◆ canRollDice()

bool GameOfUrModel::canRollDice ( PlayerID requester) const

Tests whether the game dice can be rolled now.

Parameters
requesterThe player wanting to roll the dice.
Return values
trueThe dice may be rolled.
falseThe dice can't be rolled.

◆ canStartPhasePlay()

bool GameOfUrModel::canStartPhasePlay ( ) const

Tests whether the end of the initiative phase has been reached, and whether the play phase may now begin.

Return values
trueThe play phase of the game can begin.
falseThe play phase of the game can't begin.

◆ deductCounters()

void GameOfUrModel::deductCounters ( uint8_t counters,
PlayerID fromPlayer )
private

Moves some number of counters from a player into the common pile.

Parameters
countersThe number of counters to be drawn and placed in the common pile.
fromPlayerThe player from whom the counters are removed.

◆ getAllPossibleMoves()

std::vector< std::pair< PieceIdentity, glm::u8vec2 > > GameOfUrModel::getAllPossibleMoves ( ) const

Gets a list of every possible move that can be made given the game's current state.

Returns
std::vector<std::pair<PieceIdentity, glm::u8vec2>> A list of pieces that may be moved along with the locations they may be moved to.

◆ getBoardMoveData()

MoveResultData GameOfUrModel::getBoardMoveData ( PieceIdentity piece) const

Gets data about the results of making a move with the current dice roll with a piece present on the board.

Parameters
pieceThe piece being enquired about.
Returns
MoveResultData The result of moving the piece (including whether such a move is even possible with the current roll).

◆ getCurrentPhase()

GamePhaseData GameOfUrModel::getCurrentPhase ( ) const

Gets a description of the current phase of the game.

Returns
GamePhaseData Data describing the current phase of the game.

◆ getCurrentPlayer()

PlayerData GameOfUrModel::getCurrentPlayer ( ) const

Gets information about the player whose turn it currently is.

Returns
PlayerData Information about this turn's player.

◆ getDiceData()

DiceData GameOfUrModel::getDiceData ( ) const

Gets information about the current state of this game's dice.

Returns
DiceData Data describing the state of this game's dice.

◆ getHouseData()

HouseData GameOfUrModel::getHouseData ( glm::u8vec2 location) const

Gets the data relating to the house present at a given location.

Parameters
locationThe location of the house.
Returns
HouseData Data describing the house.

◆ getLaunchMoveData()

MoveResultData GameOfUrModel::getLaunchMoveData ( PieceIdentity piece,
glm::u8vec2 launchLocation ) const

Gets data about the results of launching a piece that hasn't yet been launched with the current dice roll.

Parameters
pieceThe piece we want to launch.
launchLocationThe location to which we want to launch the piece.
Returns
MoveResultData The result of launching the piece (including whether such a move is even possible presently).

◆ getLaunchPositions()

std::vector< glm::u8vec2 > GameOfUrModel::getLaunchPositions ( const PieceIdentity & pieceIdentity) const

Gets a list of positions a particular piece may be launched to.

Warning
Throws an exception if PieceIdentity::mOwner is RoleID::NA.
Parameters
pieceIdentityThe identity of the piece whose launch positions we want.
Returns
std::vector<glm::u8vec2> A list of board positions this piece may be launched to.

◆ getMoveData()

MoveResultData GameOfUrModel::getMoveData ( PieceIdentity piece,
glm::u8vec2 moveLocation ) const
private

Gets data about a move which may be made with some piece (including whether a move is even possible).

Parameters
pieceThe piece we want to make a move with.
moveLocationThe location to which the piece should be moved.
Returns
MoveResultData The result of moving the piece to the specified location.

◆ getNCounters()

uint8_t GameOfUrModel::getNCounters ( ) const
inline

Gets the number of counters held in the common pile.

Returns
uint8_t The number of counters in the common pile.

◆ getPiece()

const Piece & GameOfUrModel::getPiece ( const PieceIdentity & pieceIdentity) const
private

Gets a reference to (the sole instance of) a particular piece.

Parameters
pieceIdentityThe identity of the piece whose state we want to know.
Returns
const Piece& The reference to the piece.

◆ getPieceData() [1/2]

GamePieceData GameOfUrModel::getPieceData ( PieceIdentity gamePiece) const

Gets information about a particular piece.

Parameters
gamePieceThe piece whose description we want.
Returns
GamePieceData The data describing the piece.

◆ getPieceData() [2/2]

GamePieceData GameOfUrModel::getPieceData ( PlayerID player,
PieceTypeID pieceType ) const

Gets information about a particular piece.

Parameters
playerThe player owning the piece.
pieceTypeThe type of the piece whose description we want.
Returns
GamePieceData The data describing the piece.

◆ getPlayer()

PlayerID GameOfUrModel::getPlayer ( RoleID role) const
private

Gets the ID of the player to whom a particular role is assigned.

Parameters
roleThe role of the player.
Returns
PlayerID The ID of the player to whom the role was assigned.

◆ getPlayerData() [1/2]

PlayerData GameOfUrModel::getPlayerData ( PlayerID player) const

Gets information about a player.

Parameters
playerThe ID corresponding to a player of the game.
Returns
PlayerData Information about the player.

◆ getPlayerData() [2/2]

PlayerData GameOfUrModel::getPlayerData ( RoleID player) const

Gets information about a player.

Warning
Will throw an error if RoleID::NA is passed.
Parameters
playerThe role assigned to the player whose information we want.
Returns
PlayerData Information about the player.

◆ getRole()

RoleID GameOfUrModel::getRole ( PlayerID player) const
private

Gets the role assigned to a particular player.

Parameters
playerThe player whose role is being queried.
Returns
RoleID The role assigned to this player.

◆ getScore()

GameScoreData GameOfUrModel::getScore ( ) const

Gets the current scores for the game.

Returns
GameScoreData The current scores for the game.

◆ getUnlaunchedPieceTypes()

std::vector< PieceTypeID > GameOfUrModel::getUnlaunchedPieceTypes ( PlayerID player) const

Gets the types of the pieces that this player hasn't yet launched.

Warning
This method assumes that roles have already been assigned and that the game is no longer in the initiative phase, and will throw an exception if it isn't.
Parameters
playerThe player whose unlaunched piece types we want to know.
Returns
std::vector<PieceTypeID> The list of this player's unlaunched pieces.

◆ getWinner()

RoleID GameOfUrModel::getWinner ( ) const
private

Gets the role of the winner of the game, and NA if there isn't one yet.

Returns
RoleID The role (black or white) of the winner of the game.

◆ movePiece()

void GameOfUrModel::movePiece ( PieceIdentity piece,
glm::u8vec2 toLocation,
PlayerID requester )

Moves a piece from its current state or location to the one requested.

Warning
This method assumes the move was already validated, and will throw an error if it is invalid.
Parameters
pieceThe identity of the piece being moved.
toLocationThe location (on the board or at the end of the route) the piece is to be moved to.
requesterThe player requesting to move the piece.

◆ operator=()

GameOfUrModel & GameOfUrModel::operator= ( GameOfUrModel && other)
inlinedefault

Replaces resources owned by this model with those stolen from another instance.

Parameters
otherThe model being stolen from.
Returns
GameOfUrModel& An instance to this object, after it has taken possession of other's resources.

◆ payCounters()

void GameOfUrModel::payCounters ( uint8_t counters,
PlayerID toPlayer )
private

Moves some number of counters from the common pile into a player's possession.

Parameters
countersThe number of counters to be paid to the player.
toPlayerThe player to whom the counters are paid.

◆ rollDice()

void GameOfUrModel::rollDice ( PlayerID requester)

Rolls dice on behalf of the requester.

Warning
This method assumes that the dice roll has already been validated before it was called. It will throw an error if rolling dice is not possible currently.
Parameters
requesterThe player attempting to roll the dice.

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