This file defines functions for updating the state.
More...
#include <cassert>
#include <vector>
#include "graph.h"
#include "match.h"
#include "round.h"
#include "settings.h"
#include "state.h"
#include "update.h"
Go to the source code of this file.
|
void | update_onturn (const Settings &settings, State &state, const Question &question) |
| Update the player onturn such that he has cards for sure. More...
|
|
bool | update_quartet (const Settings &settings, State &state, const Graph &graph, int hand_offset, int player, int set) |
| Update the state such that the given player has the provided set. More...
|
|
void | update_quartets (const Settings &settings, State &state, const Question &question) |
| Find if there are new quartets and update the state accordingly. More...
|
|
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...
|
|
This file defines functions for updating the state.
Definition in file update.cpp.
◆ update_onturn()
Update the player onturn such that he has cards for sure.
If the player onturn does not have any cards left after it got a new quartet, the player who the card was asked from will be onturn. If that player also does not have any cards, we choose the first player in the player list with cards, if there is none we set onturn to -1.
Definition at line 25 of file update.cpp.
35 for (
int player = 0; player < settings.
NUM_PLAYERS; player++)
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...
int player
The player the question is asked to.
const int NUM_PLAYERS
The number of players playing the game.
int onturn
The player who is on turn.
◆ update_quartet()
bool update_quartet |
( |
const Settings & |
settings, |
|
|
State & |
state, |
|
|
const Graph & |
graph, |
|
|
int |
hand_offset, |
|
|
int |
player, |
|
|
int |
set |
|
) |
| |
Update the state such that the given player has the provided set.
First we check if it is already known the player has the provided set. Next we make sure that in every possible matching the player has the set. To do this we execute the code shown below. If this succeeds we update the state such that every card from the provided set can only be assigned to the player and we set the quartets array entry to the player.
for card in quartet:
remove all edges from player's hand to the card
if match exists for graph:
return
- Returns
- if the player and set given is a new quartet
Definition at line 63 of file update.cpp.
70 for (
int card = set * settings.
SET_SIZE; card < (set + 1) * settings.
SET_SIZE; card++) {
72 for (
int hand_entry = 0; hand_entry < state.
players[player].num_cards; hand_entry++)
73 graph_restricted[hand_offset + hand_entry][card] =
false;
79 for (
int card = set * settings.
SET_SIZE; card < (set + 1) * settings.
SET_SIZE; card++) {
81 state.
cards[card].players[player] =
true;
Graph graph_copy(const Graph graph)
Create a copy of the given graph.
std::vector< std::vector< bool > > Graph
A bipartite graph where true booleans represent edges between a left node denoted as the row and a ri...
bool match_exists(const Graph &graph)
Check if there exists a matching for all cards.
const int SET_SIZE
The size of one set, aka the number of cards in one set.
std::vector< Player > players
The information on all the players.
std::vector< Card > cards
The information on all the cards.
std::vector< int > quartets
The information of who has a certain quartet.
◆ update_quartets()
Find if there are new quartets and update the state accordingly.
First we generate a matching. We check for every player if they have all cards from a set (i.e. a quartet) in the found matching, if so we call update_quartet
with the found player and set. If a new quartet is found, we use update_onturn
to make sure that the player onturn has cards.
- See also
- update_quartet
-
update_onturn
Definition at line 98 of file update.cpp.
106 bool newquartet =
false;
108 for (
int player = 0; player < settings.
NUM_PLAYERS; player++) {
111 std::vector<int> sets(settings.
NUM_SETS, 0);
112 for (
int card = 0; card < state.
players[player].num_cards; card++)
113 sets[match[hand_offset + card] / settings.
SET_SIZE]++;
116 for (
int set = 0; set < settings.
NUM_SETS; set++)
118 if (
update_quartet(settings, state, graph, hand_offset, player, set))
121 hand_offset += state.
players[player].num_cards;
bool graph_possible(const Settings &settings, const State &state)
Check if it is possible to create a graph.
Graph graph_create(const Settings &settings, const State &state)
Create a biparite graph which has a matching if the state is valid.
std::vector< int > match_find(const Graph &graph)
Find a match of the given graph.
const int NUM_SETS
The number of sets.
void update_onturn(const Settings &settings, State &state, const Question &question)
Update the player onturn such that he has cards for sure.
bool update_quartet(const Settings &settings, State &state, const Graph &graph, int hand_offset, int player, int set)
Update the state such that the given player has the provided set.
◆ update_state()
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.
161 if (*set == 0) *set = 1;
167 if (*set > 0) *set -= 1;
182 state.
cards[card].players[question.
player] =
false;
int set
The set the card which is asked belongs to.
int card
The card in the set which is asked for.
void update_quartets(const Settings &settings, State &state, const Question &question)
Find if there are new quartets and update the state accordingly.