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
Board Class Reference

The data model class representing the 20-square board for Game of Ur. More...

#include <board.hpp>

Public Member Functions

std::weak_ptr< Piecemove (RoleID role, std::weak_ptr< Piece > gamePiece, glm::u8vec2 toLocation, uint8_t roll)
 Applies a move after validating it.
 
std::weak_ptr< PiecegetOccupantReference (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.
 

Detailed Description

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.

Member Function Documentation

◆ canMove()

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:

  • Whether the destination house is unoccupied, or if it is occupied, if it is a non-rosette house occupied by the opponent's piece.
  • Whether the game piece belongs to the role responsible for initiating the move, and whether the game piece is in a valid state to make a move (i.e., not a piece that has already completed the route).
  • Whether the move matches the dice score provided (for unlaunched pieces, launch score; for board pieces, number of steps forward to destination house from current house).
Parameters
roleThe role (black or white) initiating the move.
gamePieceA reference to the piece being moved.
toLocationThe destination house to which the piece will be moved.
rollThe score on the dice being used to make the move.
Return values
trueThe move is possible per the current state of the board.
falseThe move is not possible per the current state of the board.

◆ computeMoveLocation()

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.

Parameters
gamePieceThe piece present on the board potentially being made to move.
rollThe roll with which to make the piece move.
Returns
glm::u8vec2 The destination location corresponding to the roll.

◆ getLaunchPosition()

glm::u8vec2 Board::getLaunchPosition ( PieceTypeID pieceType) const
private

Given a (non-swallow) piece type, gets the location of its launch house.

Parameters
pieceTypeThe type of the piece whose launch position is being retrieved.
Returns
glm::u8vec2 The piece's launch position.

◆ getLaunchPositions()

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.

Parameters
pieceIdentityThe identity of the piece being launched.
Returns
std::vector<glm::u8vec2> A list of valid launch locations for the piece.

◆ getNextCellDirection()

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.

Parameters
locationThe location of the house whose "next" vector is being retrieved.
Returns
glm::i8vec2 The value added to location for the location of the next house on the route.

◆ getOccupant()

PieceIdentity Board::getOccupant ( glm::u8vec2 location) const

Gets the identity of the piece occupying the house at a given board location.

Parameters
locationThe board location whose house's occupant is being retrieved.
Returns
PieceIdentity The identity of the occupant.

◆ getOccupantReference()

std::weak_ptr< Piece > Board::getOccupantReference ( glm::u8vec2 location)

Fetches a reference to the piece currently occupying a house pointed to by location.

Parameters
locationThe location of the house whose occupant we want to get.
Returns
std::weak_ptr<Piece> A reference to the occupying game piece, if any.

◆ getRegion()

House::Region Board::getRegion ( glm::u8vec2 location) const

Gets the region of the house at a board location.

Parameters
locationThe location whose house type is being retrieved.
Returns
House::Region The region of the house at the queried board location.

◆ getType()

House::Type Board::getType ( glm::u8vec2 location) const

Gets the type of the house at a board location.

Parameters
locationThe location whose house type is being retrieved.
Returns
House::Type The type of house at the board location queried.

◆ houseIsOccupied()

bool Board::houseIsOccupied ( glm::u8vec2 location) const

Tests whether the house at a given location is occupied.

Parameters
locationThe location of the house being tested.
Return values
trueThe house at this location is occupied.
falseThe house at this location is not occupied.

◆ isRosette()

bool Board::isRosette ( glm::u8vec2 location) const

Tests whether the house at a given location is a Rosette house.

Parameters
locationThe location of the house.
Return values
trueThe house at this location is a rosette house.
falseThe house at this location is not a rosette house.

◆ isRouteEnd()

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).

Parameters
locationThe location being tested.
Return values
trueThis location is the end of the route.
falseThis location is not the end of the route.

◆ isValidHouse()

bool Board::isValidHouse ( glm::u8vec2 location) const

Tests whether a location corresponds to a real house on the game board.

Parameters
locationThe location being tested.
Return values
trueThe location corresponds to a real house.
falseThe location does not correspond to a real house.

◆ isValidLaunchHouse()

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.

Parameters
locationThe location being tested.
gamePieceThe game piece to be launched.
Return values
trueThis house is a valid launch house for this piece.
falseThis house is not a valid launch house for this piece.

◆ move()

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.

Parameters
roleThe role (black or white) initiating the move.
gamePieceThe game piece to be moved.
toLocationThe target location for the game piece.
rollThe dice score.
Returns
std::weak_ptr<Piece> A reference to the piece moved.
See also
canMove()

◆ moveDisplacesOpponent()

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:

  • Whether the move is a valid one.
  • Whether the destination is valid, but occupied.
Parameters
roleThe role (black or white) initiating this move.
gamePieceThe game piece being moved.
toLocationThe board location of the destination house.
rollThe dice roll being used to make the move.
Return values
trueThis move is valid and will displace an opponent's piece.
falseThis move is not valid, or won't displace an opponent's piece.

◆ movePassesRosette()

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:

  • Checking the status of the piece. Pieces not on the board fail the test.
  • Stepping through the houses the piece will pass over. If one is a rosette house and NOT the destination house, the condition succeeds.
Parameters
gamePieceThe piece being moved.
toLocationThe location of the destination house.
Return values
trueThe move will cause a piece to pass over a rosette house.
falseThe move won't make the piece pass over a rosette.

Member Data Documentation

◆ mGrid

std::array<std::vector<House>, 3> Board::mGrid
private
Initial value:
{{
{
House{{1, 0}, House::ROSETTE, House::BLACK},
House{{0, -1}, House::REGULAR, House::BLACK},
House{{0, -1}, House::REGULAR, House::BLACK},
House{{0, -1}, House::REGULAR, House::BLACK},
},
{
House{{0, 1}, House::REGULAR, House::BATTLEFIELD},
House{{0, 1}, House::REGULAR, House::BATTLEFIELD},
House{{0, 1}, House::REGULAR, House::BATTLEFIELD},
House{{0, 1}, House::ROSETTE, House::BATTLEFIELD},
House{{0, 1}, House::REGULAR, House::BATTLEFIELD},
House{{0, 1}, House::REGULAR, House::BATTLEFIELD},
House{{0, 1}, House::REGULAR, House::BATTLEFIELD},
House{{0, 1}, House::ROSETTE, House::BATTLEFIELD},
House{{0, 1}, House::REGULAR, House::BATTLEFIELD},
House{{0, 1}, House::REGULAR, House::BATTLEFIELD},
House{{0, 1}, House::REGULAR, House::BATTLEFIELD},
House{{0, 1}, House::ROSETTE, House::BATTLEFIELD},
},
{
House{{-1, 0}, House::ROSETTE, House::WHITE},
House{{0, -1}, House::REGULAR, House::WHITE},
House{{0, -1}, House::REGULAR, House::WHITE},
House{{0, -1}, House::REGULAR, House::WHITE},
},
}}
The representation of a single house on the Game of Ur Board, in other words a tile.
Definition house.hpp:29

A list of vectors, where each element in a vector corresponds to one house on the board.


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