This file defines the graph creation functions.
More...
#include <algorithm>
#include <cassert>
#include <numeric>
#include <vector>
#include "graph.h"
#include "settings.h"
#include "state.h"
Go to the source code of this file.
|
Graph | graph_copy (const Graph graph) |
| Create a copy of the given graph. More...
|
|
bool | graph_possible (const Settings &settings, const State &state) |
| Check if it is possible to create a graph. More...
|
|
void | graph_set (const Settings &settings, const State &state, Graph &graph, int player, int set, int hand_offset, int hand_entry) |
| Add all the edges representing the set constraints for a player. More...
|
|
void | graph_player (const Settings &settings, const State &state, Graph &graph, int player, int hand_offset) |
| Add all the edges representing the given player. More...
|
|
Graph | graph_create (const Settings &settings, const State &state) |
| Create a biparite graph which has a matching if the state is valid. More...
|
|
This file defines the graph creation functions.
Definition in file graph.cpp.
◆ graph_copy()
Create a copy of the given graph.
Definition at line 19 of file graph.cpp.
21 Graph graph_clone(graph.size(), std::vector<bool>(graph.size()));
22 for (
size_t i = 0; i < graph.size(); i++)
23 for (
size_t j = 0; j < graph[i].size(); j++)
24 graph_clone[i][j] = graph[i][j];
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...
◆ graph_create()
Create a biparite graph which has a matching if the state is valid.
The graph is represented as a 2d array where every cell is an edge between the left node (row number) and the right node (column number). We go through all the players and add the constraints corresponding to that player's possible hands.
- See also
- graph_player
Definition at line 101 of file graph.cpp.
107 Graph graph(NUM_CARDS, std::vector<bool>(NUM_CARDS,
false));
111 for (
int player = 0; player < settings.
NUM_PLAYERS; player++) {
112 graph_player(settings, state, graph, player, hand_offset);
113 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.
void graph_player(const Settings &settings, const State &state, Graph &graph, int player, int hand_offset)
Add all the edges representing the given player.
const int NUM_SETS
The number of sets.
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.
◆ graph_player()
void graph_player |
( |
const Settings & |
settings, |
|
|
const State & |
state, |
|
|
Graph & |
graph, |
|
|
int |
player, |
|
|
int |
hand_offset |
|
) |
| |
Add all the edges representing the given player.
First we add all the edges for our set constraints.
After this we assign edges to the leftover cards the player has going to all possible cards the player could have.
- See also
- graph_set
Definition at line 73 of file graph.cpp.
77 for (
int set = 0; set < settings.
NUM_SETS; set++) {
78 graph_set(settings, state, graph, player, set, hand_offset, hand_entry);
79 hand_entry += state.
players[player].sets[set];
83 while (hand_entry < state.
players[player].num_cards) {
85 if (state.
cards[card].players[player])
86 graph[hand_offset + hand_entry][card] =
true;
void graph_set(const Settings &settings, const State &state, Graph &graph, int player, int set, int hand_offset, int hand_entry)
Add all the edges representing the set constraints for a player.
std::vector< Card > cards
The information on all the cards.
◆ graph_possible()
bool graph_possible |
( |
const Settings & |
settings, |
|
|
const State & |
state |
|
) |
| |
Check if it is possible to create a graph.
More specifically, check that no player's total number of set constraints is bigger than the number of cards that player has.
- Returns
- true if possible
Definition at line 36 of file graph.cpp.
The information connected to a player.
std::vector< int > sets
The number of cards the player at least has from a certain set.
int num_cards
The number of cards this player has.
◆ graph_set()
void graph_set |
( |
const Settings & |
settings, |
|
|
const State & |
state, |
|
|
Graph & |
graph, |
|
|
int |
player, |
|
|
int |
set, |
|
|
int |
hand_offset, |
|
|
int |
hand_entry |
|
) |
| |
Add all the edges representing the set constraints for a player.
For every set constraint corresponding to the given set and player, add edges to the current player card (hand_offset + hand_entry
) to all cards the player can have from the given set.
Definition at line 51 of file graph.cpp.
53 int minimum = state.
players[player].sets[set];
54 while (minimum-- > 0) {
55 int card_start = set * settings.
SET_SIZE;
56 for (
int card = card_start; card < card_start + settings.
SET_SIZE; card++)
57 if (state.
cards[card].players[player])
58 graph[hand_offset + hand_entry][card] =
true;