Quaternity
Functions
update.h File Reference

This file defines the state update function headers. More...

#include <vector>
#include "round.h"
#include "state.h"

Go to the source code of this file.

Functions

void update_state (const Settings &settings, State &state, const Question &question, const Answer &answer)
 Update the state of the game according to the question asked and the answer which is given. More...
 

Detailed Description

This file defines the state update function headers.

Definition in file update.h.

Function Documentation

◆ update_state()

void update_state ( const Settings settings,
State state,
const Question question,
const Answer answer 
)

Update the state of the game according to the question asked and the answer which is given.

  • If the player onturn does not have have a set restriction for the asked set yet, give it a set restriction of one.
  • If the answer is true.
    • Update the set restrictions.
      • Increase the player onturn's set restriction by one.
      • Decrease the player asked set restriction by one (not lower than 0).
    • Update who has the card which is asked.
      • Set the card's player status only to true for the onturn player.
    • Update the number of cards the players have.
      • Increase the player onturn's card count by one.
      • Decrease the player asked card count by one.
    • Update the quartets.
      • Call function update_quartets.
  • If the answer is false.
    • Update who has the card which is asked.
      • Set the card's player status false for the onturn player.
      • Set the card's player status false for the asked player.
    • Change onturn.
      • Switch onturn to the player asked.
See also
update_quartets

Definition at line 155 of file update.cpp.

156 {
157  const int card = question.set * settings.SET_SIZE + question.card;
158 
159  // update the set restriction of the player onturn
160  int *set = &state.players[state.onturn].sets[question.set];
161  if (*set == 0) *set = 1;
162 
163  if (answer) {
164  // update the set restrictions
165  state.players[state.onturn].sets[question.set] += 1;
166  int *set = &state.players[question.player].sets[question.set];
167  if (*set > 0) *set -= 1;
168 
169  // update who has the card which is asked
170  state.cards[card].players = std::vector<bool>(settings.NUM_PLAYERS, false);
171  state.cards[card].players[state.onturn] = true;
172 
173  // update the number of cards the players have
174  state.players[state.onturn].num_cards += 1;
175  state.players[question.player].num_cards -= 1;
176 
177  // update the quartets
178  update_quartets(settings, state, question);
179  } else {
180  // update who could have the card which is asked
181  state.cards[card].players[state.onturn] = false;
182  state.cards[card].players[question.player] = false;
183 
184  // update the turn
185  state.onturn = question.player;
186  }
187 }
int set
The set the card which is asked belongs to.
Definition: round.h:27
int player
The player the question is asked to.
Definition: round.h:22
int card
The card in the set which is asked for.
Definition: round.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
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
void update_quartets(const Settings &settings, State &state, const Question &question)
Find if there are new quartets and update the state accordingly.
Definition: update.cpp:98