Game of Ur 0.3.3
This is a computer adaptation of Game of Ur, written in C++ mainly using SDL and OpenGL.
|
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. | |
GameOfUrModel & | operator= (GameOfUrModel &&other) |
Replaces resources owned by this model with those stolen from another instance. | |
GameOfUrModel (const GameOfUrModel &other)=delete | |
GameOfUrModel & | operator= (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< PieceTypeID > | getUnlaunchedPieceTypes (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 Piece & | getPiece (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< Dice > | mDice { 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. | |
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.
|
default |
Constructs a new game of ur model by stealing resources from another instance.
other | The model being stolen from. |
void GameOfUrModel::advanceOneTurn | ( | PlayerID | requester | ) |
Advances the game by one turn, usually starting the turn of the next player.
requester | The player requesting a move to the next turn. |
bool GameOfUrModel::canAdvanceOneTurn | ( | PlayerID | requester | ) | const |
Tests whether the end of the current turn has been reached, and that the next one can begin.
requester | The player requesting the end of the turn. |
true | The game may be advanced by a turn. |
false | The game cannot move to the next turn. |
bool GameOfUrModel::canLaunchPiece | ( | PieceIdentity | pieceIdentity, |
PlayerID | requester ) const |
Tests whether a particular piece can be launched (at all).
pieceIdentity | The identity of the piece being launched. |
requester | The player requesting the launch. |
true | Launching the piece is possible. |
false | Launching the piece is impossible. |
bool GameOfUrModel::canLaunchPieceTo | ( | PieceIdentity | pieceIdentity, |
glm::u8vec2 | toLocation, | ||
PlayerID | requester ) const |
Tests whether a piece can be launched to a particular location.
pieceIdentity | The identity of the piece being launched. |
toLocation | The location to which the piece should be launched. |
requester | The player requesting the launch of the piece. |
true | Launching the piece is possible. |
false | Launching the piece is not possible. |
bool GameOfUrModel::canMoveBoardPiece | ( | PieceIdentity | pieceIdentity, |
PlayerID | requester ) const |
Tests whether a piece already on the board can be moved to a new location.
pieceIdentity | The identity of the piece being moved. |
requester | The player requesting the move. |
true | The piece may be moved. |
false | The piece can't be moved. |
|
private |
The underlying implementation for canLaunchPiece(), canLaunchPieceTo(), and canMoveBoardPiece().
pieceIdentity | The identity of the piece being moved. |
toLocation | The location to which the player wants the piece to move. |
requester | The player making the request for the move. |
true | The piece can be moved to the house at the indicated location. |
false | The piece can't be moved to the house at the indicated location. |
bool GameOfUrModel::canRollDice | ( | PlayerID | requester | ) | const |
Tests whether the game dice can be rolled now.
requester | The player wanting to roll the dice. |
true | The dice may be rolled. |
false | The dice can't be rolled. |
bool GameOfUrModel::canStartPhasePlay | ( | ) | const |
Tests whether the end of the initiative phase has been reached, and whether the play phase may now begin.
true | The play phase of the game can begin. |
false | The play phase of the game can't begin. |
|
private |
Moves some number of counters from a player into the common pile.
counters | The number of counters to be drawn and placed in the common pile. |
fromPlayer | The player from whom the counters are removed. |
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.
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.
piece | The piece being enquired about. |
GamePhaseData GameOfUrModel::getCurrentPhase | ( | ) | const |
Gets a description of the current phase of the game.
PlayerData GameOfUrModel::getCurrentPlayer | ( | ) | const |
Gets information about the player whose turn it currently is.
DiceData GameOfUrModel::getDiceData | ( | ) | const |
Gets information about the current state of this game's dice.
HouseData GameOfUrModel::getHouseData | ( | glm::u8vec2 | location | ) | const |
Gets the data relating to the house present at a given location.
location | The location of the house. |
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.
piece | The piece we want to launch. |
launchLocation | The location to which we want to launch the piece. |
std::vector< glm::u8vec2 > GameOfUrModel::getLaunchPositions | ( | const PieceIdentity & | pieceIdentity | ) | const |
Gets a list of positions a particular piece may be launched to.
pieceIdentity | The identity of the piece whose launch positions we want. |
|
private |
Gets data about a move which may be made with some piece (including whether a move is even possible).
piece | The piece we want to make a move with. |
moveLocation | The location to which the piece should be moved. |
|
inline |
Gets the number of counters held in the common pile.
|
private |
Gets a reference to (the sole instance of) a particular piece.
pieceIdentity | The identity of the piece whose state we want to know. |
GamePieceData GameOfUrModel::getPieceData | ( | PieceIdentity | gamePiece | ) | const |
Gets information about a particular piece.
gamePiece | The piece whose description we want. |
GamePieceData GameOfUrModel::getPieceData | ( | PlayerID | player, |
PieceTypeID | pieceType ) const |
Gets information about a particular piece.
player | The player owning the piece. |
pieceType | The type of the piece whose description we want. |
Gets the ID of the player to whom a particular role is assigned.
role | The role of the player. |
PlayerData GameOfUrModel::getPlayerData | ( | PlayerID | player | ) | const |
Gets information about a player.
player | The ID corresponding to a player of the game. |
PlayerData GameOfUrModel::getPlayerData | ( | RoleID | player | ) | const |
Gets information about a player.
player | The role assigned to the player whose information we want. |
Gets the role assigned to a particular player.
player | The player whose role is being queried. |
GameScoreData GameOfUrModel::getScore | ( | ) | const |
Gets the current scores for the game.
std::vector< PieceTypeID > GameOfUrModel::getUnlaunchedPieceTypes | ( | PlayerID | player | ) | const |
Gets the types of the pieces that this player hasn't yet launched.
player | The player whose unlaunched piece types we want to know. |
|
private |
Gets the role of the winner of the game, and NA if there isn't one yet.
void GameOfUrModel::movePiece | ( | PieceIdentity | piece, |
glm::u8vec2 | toLocation, | ||
PlayerID | requester ) |
Moves a piece from its current state or location to the one requested.
piece | The identity of the piece being moved. |
toLocation | The location (on the board or at the end of the route) the piece is to be moved to. |
requester | The player requesting to move the piece. |
|
inlinedefault |
Replaces resources owned by this model with those stolen from another instance.
other | The model being stolen from. |
|
private |
Moves some number of counters from the common pile into a player's possession.
counters | The number of counters to be paid to the player. |
toPlayer | The player to whom the counters are paid. |
void GameOfUrModel::rollDice | ( | PlayerID | requester | ) |
Rolls dice on behalf of the requester.
requester | The player attempting to roll the dice. |