This file defines functions which can check if a question, optionally plus answer, or state is valid.
More...
#include <algorithm>
#include <iostream>
#include <vector>
#include "debug.h"
#include "graph.h"
#include "match.h"
#include "round.h"
#include "settings.h"
#include "state.h"
#include "update.h"
#include "validate.h"
Go to the source code of this file.
This file defines functions which can check if a question, optionally plus answer, or state is valid.
Definition in file validate.cpp.
◆ valid_answer()
Check if the question asked and the answer given are valid.
- If answer is yes we need to check the player does not already have the card which is being asked for.
- If the asked player cannot have the card, return false.
- Update the state according to question.
- The player onturn has at least one card from asked set.
- Only the asked player could have the asked card.
- If there exists no matching, return false.
- Update state according to question and answer.
- Return if matching exists.
Definition at line 50 of file validate.cpp.
55 if (!state.
cards[card].players[question.
player])
return false;
61 if (*set == 0) *set = 1;
64 state_copy.
cards[card].players = std::vector<bool>(settings.
NUM_PLAYERS,
false);
65 state_copy.
cards[card].players[question.
player] =
true;
67 if (!
valid_state(settings, state_copy))
return false;
State copy_state(const State &state)
Copy the old state to a new state.
int set
The set the card which is asked belongs to.
int player
The player the question is asked to.
int card
The card in the set which is asked for.
const int SET_SIZE
The size of one set, aka the number of cards in one set.
const int NUM_PLAYERS
The number of players playing the game.
std::vector< Player > players
The information on all the players.
std::vector< Card > cards
The information on all the cards.
int onturn
The player who is on turn.
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.
bool valid_state(const Settings &settings, const State &state)
Check if there exists a matching for the given state.
◆ valid_question()
Check if the question asked is valid.
Check if the values (player, set, card) are all within the bounds they can be. Additionally check if the player whom a question is asked has at least one card, check that the question is not pointed towards oneself and check that we do not ask for a card from a quartet. We also make sure that there is at least one valid answer possible.
- Returns
- array with two boolean values, the first one indicates if 0/false is a valid answer to the question, the second one indicates if 1/true is valid, if there is no valid answer possible NULL is returned
Definition at line 89 of file validate.cpp.
92 std::cerr <<
"Player is out of bounds." << std::endl;
97 std::cerr <<
"Set is out of bounds." << std::endl;
102 std::cerr <<
"Card is out of bounds." << std::endl;
107 std::cerr <<
"You cannot ask yourself a question." << std::endl;
112 std::cerr <<
"You cannot ask a card from a quartet." << std::endl;
117 std::cerr <<
"Player " << question.
player <<
" does not have any cards." << std::endl;
121 bool *valid_answers =
new bool[2];
123 valid_answers[0] =
valid_answer(settings, state, question,
false);
124 valid_answers[1] =
valid_answer(settings, state, question,
true);
126 return !valid_answers[0] && !valid_answers[1] ? NULL : valid_answers;
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...
const int NUM_SETS
The number of sets.
std::vector< int > quartets
The information of who has a certain quartet.
bool valid_answer(const Settings &settings, const State &state, const Question &question, const Answer &answer)
Check if the question asked and the answer given are valid.
◆ valid_state()
bool valid_state |
( |
const Settings & |
settings, |
|
|
const State & |
state |
|
) |
| |
Check if there exists a matching for the given state.
- See also
- graph_possible
-
graph_create
-
match_exists
Definition at line 28 of file validate.cpp.
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< 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.