|
Eile Mit Weile
|
Data structure for the game board of Eile Mit Weile including operations on it. More...
#include <Board.hpp>
Public Member Functions | |
| Board () | |
| ~Board () | |
| std::vector< std::tuple< unsigned, unsigned, unsigned > > | ComputePlayableFigures () |
| bool | MakeMove (Player *player, unsigned int figure_idx, unsigned target_space) |
| void | MoveHome (Figure *figure, unsigned space_idx) |
| std::optional< Color > | GetWinner () |
| void | WriteIntoJson (rapidjson::Value &json, rapidjson::Document::AllocatorType &allocator) const |
| unsigned int | ThrowDice () |
| const std::vector< Space * > & | GetSpaces () |
| void | ResetSixCounter () |
| unsigned int | GetSixCounter () |
| void | SetupGame (unsigned int player_count, unsigned int starting_player) |
| bool | CheckMove (Player *player, unsigned int start_idx, unsigned int target_idx) |
| void | UpdatePlayerColor (unsigned nof_players) |
| unsigned | GetLadderIdx (unsigned space_idx) |
| Dice * | GetDice () |
| void | ResetCurrentPlayableFigures () |
| std::vector< std::tuple< unsigned, unsigned, unsigned > > | GetCurrentPlayableFigures () |
Static Public Member Functions | |
| static Board * | FromJson (const rapidjson::Value &json) |
Private Member Functions | |
| Board (std::vector< Space * > spaces, Dice *dice, int current_player_color_id, std::vector< std::tuple< unsigned, unsigned, unsigned > > current_playable_figures, std::optional< Color > winner) | |
Private Attributes | |
| std::vector< Space * > | _spaces |
| Dice * | _dice |
| Color | _current_player_color |
| std::vector< std::tuple< unsigned, unsigned, unsigned > > | _current_playable_figures |
| std::optional< Color > | _winner |
Data structure for the game board of Eile Mit Weile including operations on it.
The game logic is implemented in class and it is the main component of the GameState class that gets sent to the clients. Orientation on the board works with space indices that are attributes of Space objects in _spaces. The following convention is used:
| Board::Board | ( | ) |
|
private |
Deserialization constructor. Used by client to update the board from the json sent by server.
return true when a move is valid. Throws an EileMitWeileException otherwise.
Computes all playable figures for the current player, formatted as a vector tuples:
\((\text{inital space index of figure}, \text{space index of figure after move}, \text{index of figure})\).
See Board details for explanation on space indices.
The figure id is in 0 to 3 for valid figures. No playable figures is encoded as a single tuple: \((0, 0, 4)\). The return value is also saved in _current_playable_figures.
|
static |
Deserializes a Board object from a rapidjson::Value object. This is used by the client to update its board from the server
| std::vector< std::tuple< unsigned int, unsigned int, unsigned int > > Board::GetCurrentPlayableFigures | ( | ) |
Returns _current_playable_figures.
< Returns the index of the ladder space for the current player color.
Returns a reference to the vector of Space pointers.
| std::optional< Color > Board::GetWinner | ( | ) |
Returns the Color of the winner if there is one, std::nullopt otherwise.
Moves a figure of the current player to the target space. Returns true if the move was valid, false otherwise.
| void Board::ResetCurrentPlayableFigures | ( | ) |
Resets _current_playable_figures to an empty vector.
| void Board::ResetSixCounter | ( | ) |
Calls _dice->ResetSixCounter.
Sets up the board for a new game. Notably, it allocates the necesary HomeFields in _spaces.
| unsigned Board::ThrowDice | ( | ) |
Throws the dice and returns the result. Calls _dice->RollDice. Also calls Board::ComputePlayableFigures.
Updates the current player color. This happens when a new player starts a turn.
| void Board::WriteIntoJson | ( | rapidjson::Value & | json, |
| rapidjson::Document::AllocatorType & | allocator | ||
| ) | const |
Serializes a Board object into a rapidjson::Value object. This is used by the server to send the board to the client.
vector of tuples of playable figures for the current player.
|
private |
the color of the current player whose turn it is.
|
private |
the color of the winner if there is one, std::nullopt otherwise.