aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/input-output/input/command_line_helper.cpp34
-rw-r--r--src/main/input-output/input/command_line_helper.h4
-rw-r--r--src/main/input-output/input/sol_preset_types.cpp32
-rw-r--r--src/main/input-output/input/sol_preset_types.h3
-rw-r--r--src/main/main.cpp12
5 files changed, 77 insertions, 8 deletions
diff --git a/src/main/input-output/input/command_line_helper.cpp b/src/main/input-output/input/command_line_helper.cpp
index 7853b55..5518f1f 100644
--- a/src/main/input-output/input/command_line_helper.cpp
+++ b/src/main/input-output/input/command_line_helper.cpp
@@ -22,11 +22,17 @@ command_line_helper::command_line_helper()
main_options.add_options()
("help", "produce help message")
("type", po::value<string>(),
- "specify the type of the solitaire game to be solved. Must supply "
- "either 'type' or 'rules' file")
- ("rules", po::value<string>(),
+ "specify the type of the solitaire game to be solved from the list "
+ "of preset games. Must supply either this 'type' option, "
+ "or the 'custom-rules' option")
+ ("available-game-types", "outputs a list of the different preset "
+ "game types that can be solved")
+ ("describe-game-rules", po::value<string>(),
+ "outputs the JSON that describes the rules of the supplied "
+ "preset game type")
+ ("custom-rules", po::value<string>(),
"the path to a JSON file describing the rules of the solitaire "
- "to be solved. Must supply either 'type' or 'rules' file")
+ "to be solved. Must supply either 'type' or 'custom-rules' option")
("random", po::value<int>(), "create and solve a random solitaire "
"deal based on a seed. Must supply either 'random',"
"'solvability' or list of deals to be solved.")
@@ -68,6 +74,12 @@ bool command_line_helper::parse(int argc, const char* argv[]) {
help = (vm.count("help") != 0);
+ available_game_types = (vm.count("available-game-types") != 0);
+
+ if (vm.count("describe-game-rules")) {
+ describe_game_rules = vm["describe-game-rules"].as<string>();
+ }
+
classify = (vm.count("classify") != 0);
if (vm.count("input-files")) {
@@ -102,6 +114,8 @@ bool command_line_helper::assess_errors() {
return false;
}
+ if (available_game_types || !describe_game_rules.empty()) return true;
+
// The user must either supply input files, a random seed, or ask for the
// solvability percentage
int opt_count = (random_deal != -1) + !input_files.empty() + solvability;
@@ -146,8 +160,8 @@ bool command_line_helper::assess_sol_type() {
}
void command_line_helper::print_help() {
- LOG_ERROR ("Usage: solvitaire [options] input-file1 input-file2 ...\n"
- << main_options);
+ cerr << "Usage: solvitaire [options] input-file1 input-file2 ...\n"
+ << main_options << "\n";
}
void command_line_helper::print_no_opts_error() {
@@ -201,6 +215,14 @@ bool command_line_helper::get_solvability() {
return solvability;
}
+bool command_line_helper::get_available_game_types() {
+ return available_game_types;
+}
+
+string command_line_helper::get_describe_game_rules() {
+ return describe_game_rules;
+}
+
bool command_line_helper::get_short_sols() {
return shortest_sols;
}
diff --git a/src/main/input-output/input/command_line_helper.h b/src/main/input-output/input/command_line_helper.h
index f3ed443..8773fd8 100644
--- a/src/main/input-output/input/command_line_helper.h
+++ b/src/main/input-output/input/command_line_helper.h
@@ -20,6 +20,8 @@ public:
bool get_classify();
bool get_solvability();
bool get_short_sols();
+ bool get_available_game_types();
+ std::string get_describe_game_rules();
private:
bool assess_errors();
@@ -37,11 +39,13 @@ private:
std::vector<std::string> input_files;
std::string solitaire_type;
std::string rules_file;
+ std::string describe_game_rules;
int random_deal;
bool help;
bool classify;
bool solvability;
bool shortest_sols;
+ bool available_game_types;
};
#endif //SOLVITAIRE_COMMAND_LINE_HELPER_H
diff --git a/src/main/input-output/input/sol_preset_types.cpp b/src/main/input-output/input/sol_preset_types.cpp
index b3bf7f8..406be94 100644
--- a/src/main/input-output/input/sol_preset_types.cpp
+++ b/src/main/input-output/input/sol_preset_types.cpp
@@ -2,6 +2,7 @@
// Created by thecharlesblake on 11/14/17.
//
+#include <iostream>
#include "sol_preset_types.h"
using namespace std;
@@ -13,7 +14,7 @@ bool sol_preset_types::is_valid_preset(const string& s) {
return mp.count(s) > 0;
}
-std::map<string, string> sol_preset_types::mp = {
+map<string, string> sol_preset_types::mp = {
{
"default",
@@ -897,4 +898,31 @@ std::map<string, string> sol_preset_types::mp = {
)"
}
-}; \ No newline at end of file
+};
+
+void sol_preset_types::print_available_games() {
+ cout << "The following game types can be supplied to solvitaire using the "
+ "'--type [name of game]' option:\n\n";
+ for (auto const& x : mp) {
+ cout << x.first << "\n";
+ }
+ cout << "\nUse the '--describe-game-rules [name of game]' option for an "
+ "overview of the rules of each game:\n";
+}
+
+void sol_preset_types::describe_game_rules(string game) {
+ auto rules_it = mp.find(game);
+ if (rules_it == end(mp)) {
+ cout << "'" << game << "' is not a valid game type. "
+ "Enter '--available-game-types' for a "
+ "list of the games presets that can be solved\n";
+ } else {
+ cout << "The rules of '" << game << "' are as follows:"
+ << rules_it->second;
+
+ if (game != "default") {
+ cout << "\nTo see the default values of the JSON fields not covered "
+ "here, enter '--describe-game-rules default'\n";
+ }
+ }
+}
diff --git a/src/main/input-output/input/sol_preset_types.h b/src/main/input-output/input/sol_preset_types.h
index 02f602d..c5b27d3 100644
--- a/src/main/input-output/input/sol_preset_types.h
+++ b/src/main/input-output/input/sol_preset_types.h
@@ -12,6 +12,9 @@ class sol_preset_types {
public:
static std::string get(const std::string& s);
static bool is_valid_preset(const std::string& s);
+ static void print_available_games();
+ static void describe_game_rules(std::string);
+
private:
static std::map<std::string, std::string> mp;
};
diff --git a/src/main/main.cpp b/src/main/main.cpp
index a1d1037..16a5ba1 100644
--- a/src/main/main.cpp
+++ b/src/main/main.cpp
@@ -4,6 +4,7 @@
#include <gperftools/profiler.h>
#include "input-output/input/command_line_helper.h"
+#include "input-output/input/sol_preset_types.h"
#include "input-output/input/json-parsing/json_helper.h"
#include "input-output/input/json-parsing/rules_parser.h"
#include "input-output/output/log_helper.h"
@@ -30,6 +31,17 @@ int main(int argc, const char* argv[]) {
return EXIT_FAILURE;
}
+ // If the user has asked for the list of preset game types, prints it
+ if (clh.get_available_game_types()) {
+ sol_preset_types::print_available_games();
+ return EXIT_SUCCESS;
+ }
+ string game_rule_str = clh.get_describe_game_rules();
+ if (!game_rule_str.empty()) {
+ sol_preset_types::describe_game_rules(game_rule_str);
+ return EXIT_SUCCESS;
+ }
+
// Generates the rules of the solitaire from the game type
const optional<sol_rules> rules = gen_rules(clh);
if (!rules) return EXIT_FAILURE;