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 class representing the 20-square board for Game of Ur. More...
#include <board.hpp>
Public Member Functions | |
std::weak_ptr< Piece > | move (RoleID role, std::weak_ptr< Piece > gamePiece, glm::u8vec2 toLocation, uint8_t roll) |
Applies a move after validating it. | |
std::weak_ptr< Piece > | getOccupantReference (glm::u8vec2 location) |
Fetches a reference to the piece currently occupying a house pointed to by location . | |
bool | canMove (RoleID role, const Piece &gamePiece, glm::u8vec2 toLocation, uint8_t roll) const |
Tests whether a given move is possible, per the state of the board. | |
bool | movePassesRosette (const Piece &gamePiece, glm::u8vec2 toLocation) const |
Tests whether a move, if made, will pass over a rosette without landing on it. | |
bool | moveDisplacesOpponent (RoleID role, const Piece &gamePiece, glm::u8vec2 toLocation, uint8_t roll) const |
Tests whether a move will cause an opponent piece to be knocked off the board. | |
House::Type | getType (glm::u8vec2 location) const |
Gets the type of the house at a board location. | |
House::Region | getRegion (glm::u8vec2 location) const |
Gets the region of the house at a board location. | |
PieceIdentity | getOccupant (glm::u8vec2 location) const |
Gets the identity of the piece occupying the house at a given board location. | |
glm::i8vec2 | getNextCellDirection (glm::u8vec2 location) const |
Gets the 2-component vector denoting the step to the next house in the game route, relative to the house at location . | |
std::vector< glm::u8vec2 > | getLaunchPositions (PieceIdentity pieceIdentity) const |
Gets a list of launch positions available to different pieces. | |
bool | houseIsOccupied (glm::u8vec2 location) const |
Tests whether the house at a given location is occupied. | |
bool | isValidHouse (glm::u8vec2 location) const |
Tests whether a location corresponds to a real house on the game board. | |
bool | isValidLaunchHouse (glm::u8vec2 location, const Piece &gamePiece) const |
Tests whether the house corresponding to a location is a valid launch house for a given piece. | |
bool | isRosette (glm::u8vec2 location) const |
Tests whether the house at a given location is a Rosette house. | |
bool | isRouteEnd (glm::u8vec2 location) const |
Tests whether this location corresponds with what this board considers the end of the route (i.e., one past the last house in the route). | |
glm::u8vec2 | computeMoveLocation (const Piece &gamePiece, uint8_t roll) const |
Given a game piece present on the board and a dice roll, computes the new board location for that piece when the roll is used to make it move. | |
Private Member Functions | |
glm::u8vec2 | getLaunchPosition (PieceTypeID pieceType) const |
Given a (non-swallow) piece type, gets the location of its launch house. | |
Private Attributes | |
std::array< std::vector< House >, 3 > | mGrid |
A list of vectors, where each element in a vector corresponds to one house on the board. | |
The data model class representing the 20-square board for Game of Ur.
Implements various methods for querying the state of the board, eg., the region a particular tile (house) on the board belongs to, any piece currently occupying a tile, whether a move on the board is possible, and so on.
bool Board::canMove | ( | RoleID | role, |
const Piece & | gamePiece, | ||
glm::u8vec2 | toLocation, | ||
uint8_t | roll ) const |
Tests whether a given move is possible, per the state of the board.
The following conditions are checked in order to determine whether a given move is possible:
role | The role (black or white) initiating the move. |
gamePiece | A reference to the piece being moved. |
toLocation | The destination house to which the piece will be moved. |
roll | The score on the dice being used to make the move. |
true | The move is possible per the current state of the board. |
false | The move is not possible per the current state of the board. |
glm::u8vec2 Board::computeMoveLocation | ( | const Piece & | gamePiece, |
uint8_t | roll ) const |
Given a game piece present on the board and a dice roll, computes the new board location for that piece when the roll is used to make it move.
gamePiece | The piece present on the board potentially being made to move. |
roll | The roll with which to make the piece move. |
|
private |
Given a (non-swallow) piece type, gets the location of its launch house.
pieceType | The type of the piece whose launch position is being retrieved. |
std::vector< glm::u8vec2 > Board::getLaunchPositions | ( | PieceIdentity | pieceIdentity | ) | const |
Gets a list of launch positions available to different pieces.
Most pieces have a launch position corresponding exactly to their launch rolls, i.e., houses V, VI, VII, X relative to each RoleID's start location.
The Swallow may launch in the house just before any house with a Rosette on it.
pieceIdentity | The identity of the piece being launched. |
glm::i8vec2 Board::getNextCellDirection | ( | glm::u8vec2 | location | ) | const |
Gets the 2-component vector denoting the step to the next house in the game route, relative to the house at location
.
location | The location of the house whose "next" vector is being retrieved. |
location
for the location of the next house on the route. PieceIdentity Board::getOccupant | ( | glm::u8vec2 | location | ) | const |
Gets the identity of the piece occupying the house at a given board location.
location | The board location whose house's occupant is being retrieved. |
std::weak_ptr< Piece > Board::getOccupantReference | ( | glm::u8vec2 | location | ) |
Fetches a reference to the piece currently occupying a house pointed to by location
.
location | The location of the house whose occupant we want to get. |
House::Region Board::getRegion | ( | glm::u8vec2 | location | ) | const |
Gets the region of the house at a board location.
location | The location whose house type is being retrieved. |
House::Type Board::getType | ( | glm::u8vec2 | location | ) | const |
Gets the type of the house at a board location.
location | The location whose house type is being retrieved. |
bool Board::houseIsOccupied | ( | glm::u8vec2 | location | ) | const |
Tests whether the house at a given location is occupied.
location | The location of the house being tested. |
true | The house at this location is occupied. |
false | The house at this location is not occupied. |
bool Board::isRosette | ( | glm::u8vec2 | location | ) | const |
Tests whether the house at a given location is a Rosette house.
location | The location of the house. |
true | The house at this location is a rosette house. |
false | The house at this location is not a rosette house. |
bool Board::isRouteEnd | ( | glm::u8vec2 | location | ) | const |
Tests whether this location corresponds with what this board considers the end of the route (i.e., one past the last house in the route).
location | The location being tested. |
true | This location is the end of the route. |
false | This location is not the end of the route. |
bool Board::isValidHouse | ( | glm::u8vec2 | location | ) | const |
Tests whether a location corresponds to a real house on the game board.
location | The location being tested. |
true | The location corresponds to a real house. |
false | The location does not correspond to a real house. |
bool Board::isValidLaunchHouse | ( | glm::u8vec2 | location, |
const Piece & | gamePiece ) const |
Tests whether the house corresponding to a location is a valid launch house for a given piece.
location | The location being tested. |
gamePiece | The game piece to be launched. |
true | This house is a valid launch house for this piece. |
false | This house is not a valid launch house for this piece. |
std::weak_ptr< Piece > Board::move | ( | RoleID | role, |
std::weak_ptr< Piece > | gamePiece, | ||
glm::u8vec2 | toLocation, | ||
uint8_t | roll ) |
Applies a move after validating it.
role | The role (black or white) initiating the move. |
gamePiece | The game piece to be moved. |
toLocation | The target location for the game piece. |
roll | The dice score. |
bool Board::moveDisplacesOpponent | ( | RoleID | role, |
const Piece & | gamePiece, | ||
glm::u8vec2 | toLocation, | ||
uint8_t | roll ) const |
Tests whether a move will cause an opponent piece to be knocked off the board.
This is done by determining:
role | The role (black or white) initiating this move. |
gamePiece | The game piece being moved. |
toLocation | The board location of the destination house. |
roll | The dice roll being used to make the move. |
true | This move is valid and will displace an opponent's piece. |
false | This move is not valid, or won't displace an opponent's piece. |
bool Board::movePassesRosette | ( | const Piece & | gamePiece, |
glm::u8vec2 | toLocation ) const |
Tests whether a move, if made, will pass over a rosette without landing on it.
It determines this by:
gamePiece | The piece being moved. |
toLocation | The location of the destination house. |
true | The move will cause a piece to pass over a rosette house. |
false | The move won't make the piece pass over a rosette. |
|
private |
A list of vectors, where each element in a vector corresponds to one house on the board.