Quaternity
Typedefs | Functions
graph.h File Reference

This file defines the graph type and a creation function header. More...

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

Go to the source code of this file.

Typedefs

typedef std::vector< std::vector< bool > > Graph
 A bipartite graph where true booleans represent edges between a left node denoted as the row and a right node denoted as the column in the grid. More...
 

Functions

bool graph_possible (const Settings &settings, const State &state)
 Check if it is possible to create a graph. More...
 
Graph graph_copy (const Graph graph)
 Create a copy of the given graph. More...
 
Graph graph_create (const Settings &settings, const State &state)
 Create a biparite graph which has a matching if the state is valid. More...
 

Detailed Description

This file defines the graph type and a creation function header.

Definition in file graph.h.

Typedef Documentation

◆ Graph

typedef std::vector<std::vector<bool> > Graph

A bipartite graph where true booleans represent edges between a left node denoted as the row and a right node denoted as the column in the grid.

Definition at line 19 of file graph.h.

Function Documentation

◆ graph_copy()

Graph graph_copy ( const Graph  graph)

Create a copy of the given graph.

Definition at line 19 of file graph.cpp.

20 {
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];
25  return graph_clone;
26 }
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...
Definition: graph.h:19

◆ graph_create()

Graph graph_create ( const Settings settings,
const State state 
)

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.

102 {
103  assert(graph_possible(settings, state)); // make sure we can create a graph
104 
105  // create the graph array and initialize all values to false
106  const int NUM_CARDS = settings.NUM_SETS * settings.SET_SIZE;
107  Graph graph(NUM_CARDS, std::vector<bool>(NUM_CARDS, false));
108 
109  // set the corresponding edges for all players
110  int hand_offset = 0;
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;
114  }
115 
116  return graph;
117 }
bool graph_possible(const Settings &settings, const State &state)
Check if it is possible to create a graph.
Definition: graph.cpp:36
void graph_player(const Settings &settings, const State &state, Graph &graph, int player, int hand_offset)
Add all the edges representing the given player.
Definition: graph.cpp:73
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
std::vector< Player > players
The information on all the players.
Definition: state.h:81

◆ 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.

37 {
38  for (Player player: state.players)
39  if (player.num_cards < accumulate(player.sets.begin(), player.sets.end(), 0))
40  return false;
41  return true;
42 }
The information connected to a player.
Definition: state.h:34
std::vector< int > sets
The number of cards the player at least has from a certain set.
Definition: state.h:48
int num_cards
The number of cards this player has.
Definition: state.h:39