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
model.hpp
Go to the documentation of this file.
1
10
15
21
22#ifndef ZOAPPGAMEOFURMODEL_H
23#define ZOAPPGAMEOFURMODEL_H
24
25#include <cstdint>
26#include <array>
27#include <memory>
28
29
30#include "phase.hpp"
31#include "board.hpp"
32#include "player.hpp"
33#include "dice.hpp"
34
40enum PlayerID: uint8_t {
41 PLAYER_A=0, //< Player one, usually a real human player.
42 PLAYER_B, // Player two, either a computer or a human depending on the game mode.
43};
44
81
106
145
186
192struct DiceData {
198
204
210
216
222};
223
235
241
247
252 uint8_t mCounters;
253
259
265
271};
272
283 using flags=uint8_t;
284
289 enum Flags: flags {
290 IS_POSSIBLE=0x1, //< Whether this move can even happen.
291 PASSES_ROSETTE=0x2, //< Whether, on making this move, a rosette is passed.
292 LANDS_ON_ROSETTE=0x4, //< Whether at the end of the move, the moved piece is on a rosette.
293 COMPLETES_ROUTE=0x8, //< Whether this move results in the piece completing the route.
294 ENDS_GAME=0x10, //< Whether this move will end the game (will co-occur with Flags::COMPLETES_ROUTE).
295 };
296
302
308
314
320
326};
327
338public:
343 GameOfUrModel()=default;
344
350 GameOfUrModel(GameOfUrModel&& other)=default;
351
359
360 GameOfUrModel(const GameOfUrModel& other)=delete;
361 GameOfUrModel& operator=(const GameOfUrModel& other)=delete;
362
367 void reset();
368
373 void startPhasePlay();
374
382 void rollDice(PlayerID requester);
383
393 void movePiece(PieceIdentity piece, glm::u8vec2 toLocation, PlayerID requester);
394
402 void advanceOneTurn(PlayerID requester);
403
412 std::vector<PieceTypeID> getUnlaunchedPieceTypes(PlayerID player) const;
413
419 std::vector<std::pair<PieceIdentity, glm::u8vec2>> getAllPossibleMoves() const;
420
429 std::vector<glm::u8vec2> getLaunchPositions(const PieceIdentity& pieceIdentity) const;
430
436 uint8_t getNCounters() const { return mCounters; }
437
444
450 GameScoreData getScore() const;
451
458 HouseData getHouseData(glm::u8vec2 location) const;
459
467
475 GamePieceData getPieceData(PlayerID player, PieceTypeID pieceType) const;
476
483 PlayerData getPlayerData(PlayerID player) const;
484
493 PlayerData getPlayerData(RoleID player) const;
494
501
507 DiceData getDiceData() const;
508
516
524 MoveResultData getLaunchMoveData(PieceIdentity piece, glm::u8vec2 launchLocation) const;
525
533 bool canRollDice(PlayerID requester) const;
534
544 bool canLaunchPieceTo(PieceIdentity pieceIdentity, glm::u8vec2 toLocation, PlayerID requester) const;
545
554 bool canLaunchPiece(PieceIdentity pieceIdentity, PlayerID requester) const;
555
564 bool canMoveBoardPiece(PieceIdentity pieceIdentity, PlayerID requester) const;
565
573 bool canAdvanceOneTurn(PlayerID requester) const;
574
581 bool canStartPhasePlay() const;
582
583private:
594 bool canMovePiece(PieceIdentity pieceIdentity, glm::u8vec2 toLocation, PlayerID requester) const;
595
601 RoleID getWinner() const;
602
609 RoleID getRole(PlayerID player) const;
610
617 PlayerID getPlayer(RoleID role) const;
618
625 const Piece& getPiece(const PieceIdentity& pieceIdentity) const;
626
634 MoveResultData getMoveData(PieceIdentity piece, glm::u8vec2 moveLocation) const;
635
642 void deductCounters(uint8_t counters, PlayerID fromPlayer);
643
650 void payCounters(uint8_t counters, PlayerID toPlayer);
651
656 void endTurn();
657
662 GamePhase mGamePhase { GamePhase::INITIATIVE };
663
668 TurnPhase mTurnPhase { TurnPhase::ROLL_DICE };
669
674 RoundPhase mRoundPhase { RoundPhase::IN_PROGRESS };
675
681
686 uint8_t mCounters { 0 };
687
692 std::unique_ptr<Dice> mDice { std::make_unique<Dice>() };
693
699
704 std::array<Player, 2> mPlayers {};
705
710 uint8_t mPreviousRoll {0};
711};
712
714#endif
Contains the data model class representing the 20-square board for Game of Ur.
The data model class representing the 20-square board for Game of Ur.
Definition board.hpp:29
State
Values representing all possible states for this pair of dice.
Definition dice.hpp:33
The data model representing one instance of Game of Ur.
Definition model.hpp:337
void deductCounters(uint8_t counters, PlayerID fromPlayer)
Moves some number of counters from a player into the common pile.
Definition model.cpp:164
std::array< Player, 2 > mPlayers
Data models for the two players of the game.
Definition model.hpp:704
const Piece & getPiece(const PieceIdentity &pieceIdentity) const
Gets a reference to (the sole instance of) a particular piece.
Definition model.cpp:186
TurnPhase mTurnPhase
The current phase of the turn the game is in.
Definition model.hpp:668
bool canLaunchPiece(PieceIdentity pieceIdentity, PlayerID requester) const
Tests whether a particular piece can be launched (at all).
Definition model.cpp:268
bool canLaunchPieceTo(PieceIdentity pieceIdentity, glm::u8vec2 toLocation, PlayerID requester) const
Tests whether a piece can be launched to a particular location.
Definition model.cpp:257
void advanceOneTurn(PlayerID requester)
Advances the game by one turn, usually starting the turn of the next player.
Definition model.cpp:134
PlayerData getPlayerData(PlayerID player) const
Gets information about a player.
Definition model.cpp:367
GameOfUrModel(GameOfUrModel &&other)=default
Constructs a new game of ur model by stealing resources from another instance.
bool canMovePiece(PieceIdentity pieceIdentity, glm::u8vec2 toLocation, PlayerID requester) const
The underlying implementation for canLaunchPiece(), canLaunchPieceTo(), and canMoveBoardPiece().
Definition model.cpp:234
void startPhasePlay()
Starts the play phase of the game, where counters are placed into the common pile,...
Definition model.cpp:27
void movePiece(PieceIdentity piece, glm::u8vec2 toLocation, PlayerID requester)
Moves a piece from its current state or location to the one requested.
Definition model.cpp:90
uint8_t getNCounters() const
Gets the number of counters held in the common pile.
Definition model.hpp:436
PlayerID getPlayer(RoleID role) const
Gets the ID of the player to whom a particular role is assigned.
Definition model.cpp:222
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 ...
Definition model.cpp:412
GamePhaseData getCurrentPhase() const
Gets a description of the current phase of the game.
Definition model.cpp:321
Board mBoard
The data model for the board used by this game.
Definition model.hpp:698
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 b...
Definition model.cpp:397
RoleID getRole(PlayerID player) const
Gets the role assigned to a particular player.
Definition model.cpp:218
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).
Definition model.cpp:425
void rollDice(PlayerID requester)
Rolls dice on behalf of the requester.
Definition model.cpp:58
std::unique_ptr< Dice > mDice
A reference to the data model of the dice used in this game.
Definition model.hpp:692
HouseData getHouseData(glm::u8vec2 location) const
Gets the data relating to the house present at a given location.
Definition model.cpp:341
std::vector< glm::u8vec2 > getLaunchPositions(const PieceIdentity &pieceIdentity) const
Gets a list of positions a particular piece may be launched to.
Definition model.cpp:520
std::vector< PieceTypeID > getUnlaunchedPieceTypes(PlayerID player) const
Gets the types of the pieces that this player hasn't yet launched.
Definition model.cpp:524
RoundPhase mRoundPhase
The current phase of the round (every pair of turns).
Definition model.hpp:674
void reset()
Resets the game to its initial state, losing track of its current one.
Definition model.cpp:6
bool canRollDice(PlayerID requester) const
Tests whether the game dice can be rolled now.
Definition model.cpp:175
PlayerData getCurrentPlayer() const
Gets information about the player whose turn it currently is.
Definition model.cpp:379
GameOfUrModel & operator=(GameOfUrModel &&other)
Replaces resources owned by this model with those stolen from another instance.
bool canStartPhasePlay() const
Tests whether the end of the initiative phase has been reached, and whether the play phase may now be...
Definition model.cpp:309
GameScoreData getScore() const
Gets the current scores for the game.
Definition model.cpp:331
bool canMoveBoardPiece(PieceIdentity pieceIdentity, PlayerID requester) const
Tests whether a piece already on the board can be moved to a new location.
Definition model.cpp:246
void payCounters(uint8_t counters, PlayerID toPlayer)
Moves some number of counters from the common pile into a player's possession.
Definition model.cpp:152
PlayerID mCurrentPlayer
The player appointed to take action during this turn.
Definition model.hpp:680
RoleID getWinner() const
Gets the role of the winner of the game, and NA if there isn't one yet.
Definition model.cpp:204
GameOfUrModel()=default
Constructs a new game of ur model.
uint8_t mCounters
The number of counters held in the game's common pile.
Definition model.hpp:686
uint8_t mPreviousRoll
The final result of the dice roll in the previous turn of this game.
Definition model.hpp:710
GamePhase mGamePhase
The current phase of the game as a whole.
Definition model.hpp:662
bool canAdvanceOneTurn(PlayerID requester) const
Tests whether the end of the current turn has been reached, and that the next one can begin.
Definition model.cpp:286
GamePieceData getPieceData(PieceIdentity gamePiece) const
Gets information about a particular piece.
Definition model.cpp:352
void endTurn()
Ends the current turn.
Definition model.cpp:10
DiceData getDiceData() const
Gets information about the current state of this game's dice.
Definition model.cpp:387
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.
Definition model.cpp:479
Type
The type of a house.
Definition house.hpp:35
Region
The region this house belongs to.
Definition house.hpp:44
The state of a single piece of the game.
Definition piece.hpp:52
State
A value representing the (high level) state of this piece.
Definition piece.hpp:58
Contains the data model class representing the pair of dice used to play Game of Ur.
PieceTypeID
Enum listing the different types of pieces present in the game.
Definition piece_type_id.hpp:22
TurnPhase
A value representing the phases possible in a single turn of the game.
Definition phase.hpp:31
PlayerID
The two players playing the game, as known to GameOfUrModel.
Definition model.hpp:40
GamePhase
A value representing the high level phase of an entire game.
Definition phase.hpp:20
RoleID
A value representing the various roles (or sets, if preferred) possible in this game.
Definition role_id.hpp:20
RoundPhase
A value representing the phase of a single round, where in a round all players take a turn once.
Definition phase.hpp:43
Enums whose values represent the different phases a game can be in.
Contains structs and classes representing a single player of the game and their current state.
Data returned by GameOfUrModel when queried for dice related information.
Definition model.hpp:192
bool mSecondaryRoll
The value shown by the secondary die.
Definition model.hpp:209
Dice::State mState
The state of the dice.
Definition model.hpp:197
uint8_t mPrimaryRoll
The value shown by the primary die.
Definition model.hpp:203
uint8_t mPreviousResult
The result dice score from the previous turn.
Definition model.hpp:221
uint8_t mResultScore
The result score the two die together produce in the current game phase.
Definition model.hpp:215
Data returned by GameOfUrModel when queried about the current phase of the game.
Definition model.hpp:112
GamePhase mGamePhase
The current high level phase of the game.
Definition model.hpp:117
RoundPhase mRoundPhase
The part of the round the game is currently in.
Definition model.hpp:125
RoleID mWinner
The role, black or white, of the winner of the game (when the game has ended).
Definition model.hpp:143
PlayerID mTurn
The player whose turn it is, presently.
Definition model.hpp:137
TurnPhase mTurnPhase
The part of the turn the game is currently in.
Definition model.hpp:131
Data returned by GameOfUrModel when queried about the state of a single game piece.
Definition model.hpp:87
Piece::State mState
The state of this piece.
Definition model.hpp:98
glm::u8vec2 mLocation
The location of this piece on the board (if it is on the board).
Definition model.hpp:104
PieceIdentity mIdentity
The identity of this piece, its owner and type.
Definition model.hpp:92
Data returned by GameOfUrModel when queried for scores.
Definition model.hpp:151
uint8_t mPlayerTwoVictoryPieces
The number of Player B's pieces that have reached the end of the route.
Definition model.hpp:184
uint8_t mPlayerTwoCounters
The number of counters currently held by player B.
Definition model.hpp:172
uint8_t mPlayerOneCounters
The number of counters held by player A.
Definition model.hpp:164
uint8_t mCommonPoolCounters
The number of counters available to be won by the player claiming victory.
Definition model.hpp:156
uint8_t mPlayerOneVictoryPieces
The number of Player A's pieces that have reached the end of the route.
Definition model.hpp:178
Data returned by GameOfUrModel when queried about the state of a House.
Definition model.hpp:50
glm::u8vec2 mLocation
The location of this house as per the game board.
Definition model.hpp:73
House::Type mType
The house's type.
Definition model.hpp:55
glm::i8vec2 mNextCellDirection
The direction from this house to the next house (or to the end of the route, if this house is the las...
Definition model.hpp:79
PieceIdentity mOccupant
The identity of the piece occupying this house, if any.
Definition model.hpp:67
House::Region mRegion
The region the house is in.
Definition model.hpp:61
Data returned by the GameOfUrModel when making a move, or querying possible moves.
Definition model.hpp:278
Flags
Enum values corresponding to masks used on flags to answer questions about the move represented by Mo...
Definition model.hpp:289
GamePieceData mMovedPiece
Data relating to the piece being moved.
Definition model.hpp:313
flags mFlags
Flags answering certain questions about the effects of making this move.
Definition model.hpp:301
GamePieceData mDisplacedPiece
Data relating to the piece knocked out of the board, if any.
Definition model.hpp:307
uint8_t mCountersWon
The number of counters the maker of the move will gain when it is performed.
Definition model.hpp:319
uint8_t mCountersLost
The number of counters the maker of the move will lose when it is performed.
Definition model.hpp:325
uint8_t flags
The underlying type of the variable in which move related flags will be stored.
Definition model.hpp:283
Data uniquely identifying a piece used in the game.
Definition piece.hpp:29
Data returned by GameOfUrModel when queried about a player.
Definition model.hpp:229
uint8_t mCounters
The number of counters currently held by this player.
Definition model.hpp:252
uint8_t mNUnlaunchedPieces
The number of pieces this player hasn't yet launched.
Definition model.hpp:258
RoleID mRole
The piece set this player is using this game (black or white).
Definition model.hpp:240
PlayerID mPlayer
The player (A or B) this data is about.
Definition model.hpp:234
bool mIsWinner
Whether this player is the winner of the game.
Definition model.hpp:246
uint8_t mNBoardPieces
The number of this player's pieces on the board.
Definition model.hpp:264
uint8_t mNVictoryPieces
The number of this player's pieces which have completed the route.
Definition model.hpp:270