Cluedo Solver v1.0
Cluedo game solver making deductions.
Loading...
Searching...
No Matches
Cluedo::Solver Class Reference

The solver of a Cluedo game. More...

#include <Solver.hpp>

Classes

struct  Suggestion
 A struct that contains the data of a suggestion. More...
 

Public Types

using SolutionProbabilityPair = std::pair<std::tuple<Card, Card, Card>, float>
 A pair that contains a solution (a suspect, a weapon and a room) and its probability.
 

Public Member Functions

std::size_t player_count () const
 
Player const & player (std::size_t player_index) const
 
Playerplayer (std::size_t player_index)
 
void learn_player_card_state (std::size_t player_index, Card card, bool has_card, bool infer_new_info=true)
 
void learn_player_has_any_of_cards (std::size_t player_index, CardSet const &card_set, bool infer_new_info=true)
 
void learn_from_suggestion (Suggestion const &suggestion, bool infer_new_info=true)
 
bool are_constraints_satisfied () const
 Checks if the constraints of the game are satisfied.
 
std::vector< SolutionProbabilityPairfind_most_likely_solutions () const
 

Static Public Member Functions

static Result< Solver, Errorcreate (std::vector< PlayerData > const &players_data)
 

Static Public Attributes

static constexpr std::size_t MIN_PLAYER_COUNT = 2
 The minimum number of players that can play a game.
 
static constexpr std::size_t MAX_PLAYER_COUNT = 6
 The maximum number of players that can play a game.
 
static constexpr std::size_t SOLUTION_CARD_COUNT = 3
 The number of cards that make a solution (a suspect, a weapon and a room).
 

Detailed Description

The solver of a Cluedo game.

This class is the heart of the application. It contains the data of the game and takes information to learn new things about the game. It can also find the most likely solutions for the game.

Member Function Documentation

◆ create()

Result< Solver, Error > Cluedo::Solver::create ( std::vector< PlayerData > const & players_data)
static

Creates a new Solver object given the data of the players.

See also
Cluedo::PlayerData
Parameters
players_dataThe data of the players.
Returns
A Result object that contains the Solver object if the creation was successful or a Cluedo::Error otherwise.

◆ find_most_likely_solutions()

std::vector< Solver::SolutionProbabilityPair > Cluedo::Solver::find_most_likely_solutions ( ) const

Finds the most likely solutions for the game.

Returns
The list of solutions ordered by their probability.

◆ learn_from_suggestion()

void Cluedo::Solver::learn_from_suggestion ( Suggestion const & suggestion,
bool infer_new_info = true )

Learns from a suggestion.

Note
This method will infer new information by default.
Parameters
suggestionThe suggestion made in the game.
infer_new_infotrue if new information should be inferred, false otherwise.

◆ learn_player_card_state()

void Cluedo::Solver::learn_player_card_state ( std::size_t player_index,
Card card,
bool has_card,
bool infer_new_info = true )

Learns that a player has a card or not.

Note
This method will infer new information by default.
Parameters
player_indexThe index of the player.
cardThe card in question.
has_cardtrue if the player has the card, false otherwise.
infer_new_infotrue if new information should be inferred, false otherwise.

◆ learn_player_has_any_of_cards()

void Cluedo::Solver::learn_player_has_any_of_cards ( std::size_t player_index,
CardSet const & card_set,
bool infer_new_info = true )

Learns that a player has any of the cards in the given set.

Note
This method will infer new information by default.
Parameters
player_indexThe index of the player.
card_setThe set of cards in question.
infer_new_infotrue if new information should be inferred, false otherwise.

◆ player() [1/2]

Player & Cluedo::Solver::player ( std::size_t player_index)
inline

Returns the player at the given index.

Parameters
player_indexThe index of the player.
Returns
The player at the given index.

◆ player() [2/2]

Player const & Cluedo::Solver::player ( std::size_t player_index) const
inline

Returns the player at the given index.

Parameters
player_indexThe index of the player.
Returns
The player at the given index.

◆ player_count()

std::size_t Cluedo::Solver::player_count ( ) const
inline

Returns the number of players in the game.

Returns
The number of players in the game.

The documentation for this class was generated from the following files: