Quaternity
Classes | Functions
state.h File Reference

This file defines the structs for a card, player and a game state, plus a state initialize and copy function header. More...

#include <vector>

Go to the source code of this file.

Classes

struct  Card
 The information connected to a card. More...
 
struct  Player
 The information connected to a player. More...
 
struct  State
 The complete game state. More...
 

Functions

State init_state (const Settings &settings)
 Initialize the starting state corresponding to the given settings. More...
 
State copy_state (const State &state)
 Copy the old state to a new state. More...
 
int info_num_quartets (const State &state, int player)
 Get the number of quartets the given player has. More...
 
int info_num_cards (const Settings &settings, const State &state, int player)
 Get the number of cards the player has without counting the cards from quartets, so the actual number of cards the player has in its hands. More...
 

Detailed Description

This file defines the structs for a card, player and a game state, plus a state initialize and copy function header.

Definition in file state.h.

Function Documentation

◆ copy_state()

State copy_state ( const State state)

Copy the old state to a new state.

See also
copy_cards
copy_players

Definition at line 96 of file state.cpp.

97 {
98  return State{state.onturn, copy_cards(state.cards), copy_players(state.players), state.quartets};
99 }
std::vector< Card > copy_cards(const std::vector< Card > cards)
Copy the old cards vector to a new cards vector.
Definition: state.cpp:67
std::vector< Player > copy_players(const std::vector< Player > players)
Copy the old player vector to a new player vector.
Definition: state.cpp:80
The complete game state.
Definition: state.h:57
std::vector< Player > players
The information on all the players.
Definition: state.h:81
std::vector< Card > cards
The information on all the cards.
Definition: state.h:74
int onturn
The player who is on turn.
Definition: state.h:62
std::vector< int > quartets
The information of who has a certain quartet.
Definition: state.h:90

◆ info_num_cards()

int info_num_cards ( const Settings settings,
const State state,
int  player 
)

Get the number of cards the player has without counting the cards from quartets, so the actual number of cards the player has in its hands.

Definition at line 113 of file state.cpp.

114 {
115  return state.players[player].num_cards - settings.SET_SIZE * info_num_quartets(state, player);
116 }
int info_num_quartets(const State &state, int player)
Get the number of quartets the given player has.
Definition: state.cpp:104
const int SET_SIZE
The size of one set, aka the number of cards in one set.
Definition: settings.h:27

◆ info_num_quartets()

int info_num_quartets ( const State state,
int  player 
)

Get the number of quartets the given player has.

Definition at line 104 of file state.cpp.

105 {
106  return std::count(state.quartets.begin(), state.quartets.end(), player);
107 }

◆ init_state()

State init_state ( const Settings settings)

Initialize the starting state corresponding to the given settings.

The cards and players are defined by their respective functions. The zero'th player starts the game (has the first turn).

See also
init_cards
init_players

Definition at line 58 of file state.cpp.

59 {
60  std::vector<int> quartets(settings.NUM_SETS, -1);
61  return State{0, init_cards(settings), init_players(settings), quartets};
62 }
std::vector< Card > init_cards(const Settings &settings)
Initialize the cards corresponding to the given settings.
Definition: state.cpp:20
std::vector< Player > init_players(const Settings &settings)
Initialize the players corresponding to the given settings.
Definition: state.cpp:38
const int NUM_SETS
The number of sets.
Definition: settings.h:32