Quaternity
state.cpp
Go to the documentation of this file.
1 
7 #include <algorithm>
8 #include <vector>
9 
10 #include "settings.h"
11 #include "state.h"
12 
20 std::vector<Card> init_cards(const Settings &settings)
21 {
22  std::vector<Card> cards;
23  for (int i = 0; i < settings.SET_SIZE * settings.NUM_SETS; i++) {
24  Card card = {std::vector<bool>(settings.NUM_PLAYERS, true)};
25  cards.push_back(card);
26  }
27  return cards;
28 }
29 
38 std::vector<Player> init_players(const Settings &settings)
39 {
40  const int NUM_CARDS = (settings.NUM_SETS * settings.SET_SIZE) / settings.NUM_PLAYERS;
41  std::vector<Player> players;
42  for (int i = 0; i < settings.NUM_PLAYERS; i++) {
43  Player player = {NUM_CARDS, std::vector<int>(settings.NUM_SETS, 0)};
44  players.push_back(player);
45  }
46  return players;
47 }
48 
58 State init_state(const Settings &settings)
59 {
60  std::vector<int> quartets(settings.NUM_SETS, -1);
61  return State{0, init_cards(settings), init_players(settings), quartets};
62 }
63 
67 std::vector<Card> copy_cards(const std::vector<Card> cards)
68 {
69  std::vector<Card> cards_copy;
70  for (Card card: cards) {
71  Card card_copy = {card.players};
72  cards_copy.push_back(card_copy);
73  }
74  return cards_copy;
75 }
76 
80 std::vector<Player> copy_players(const std::vector<Player> players)
81 {
82  std::vector<Player> players_copy;
83  for (Player player: players) {
84  Player player_copy = {player.num_cards, player.sets};
85  players_copy.push_back(player_copy);
86  }
87  return players;
88 }
89 
96 State copy_state(const State &state)
97 {
98  return State{state.onturn, copy_cards(state.cards), copy_players(state.players), state.quartets};
99 }
100 
104 int info_num_quartets(const State &state, int player)
105 {
106  return std::count(state.quartets.begin(), state.quartets.end(), player);
107 }
108 
113 int info_num_cards(const Settings &settings, const State &state, int player)
114 {
115  return state.players[player].num_cards - settings.SET_SIZE * info_num_quartets(state, player);
116 }
This file defines the settings struct.
State copy_state(const State &state)
Copy the old state to a new state.
Definition: state.cpp:96
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< Card > init_cards(const Settings &settings)
Initialize the cards corresponding to the given settings.
Definition: state.cpp:20
int info_num_quartets(const State &state, int player)
Get the number of quartets the given player has.
Definition: state.cpp:104
std::vector< Player > copy_players(const std::vector< Player > players)
Copy the old player vector to a new player vector.
Definition: state.cpp:80
State init_state(const Settings &settings)
Initialize the starting state corresponding to the given settings.
Definition: state.cpp:58
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...
Definition: state.cpp:113
std::vector< Player > init_players(const Settings &settings)
Initialize the players corresponding to the given settings.
Definition: state.cpp:38
This file defines the structs for a card, player and a game state, plus a state initialize and copy f...
The information connected to a card.
Definition: state.h:19
std::vector< bool > players
The players which could have this card.
Definition: state.h:28
The information connected to a player.
Definition: state.h:34
int num_cards
The number of cards this player has.
Definition: state.h:39
The settings which characterize a game.
Definition: settings.h:22
const int NUM_SETS
The number of sets.
Definition: settings.h:32
const int SET_SIZE
The size of one set, aka the number of cards in one set.
Definition: settings.h:27
const int NUM_PLAYERS
The number of players playing the game.
Definition: settings.h:37
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