aboutsummaryrefslogtreecommitdiff
path: root/src/main/input-output
diff options
context:
space:
mode:
authorIan Gent2018-06-26 16:43:45 +0100
committerIan Gent2018-06-26 16:43:45 +0100
commit0798cfe1ecb92996ed7959383dcc4b8b0d51a1d9 (patch)
treef6f6dbd927012de317feea6b2bb25d466cff1ac3 /src/main/input-output
parentfirst R file (diff)
parentMerge pull request #71 from thecharlesblake/correct-klondike (diff)
downloadmetasol-0798cfe1ecb92996ed7959383dcc4b8b0d51a1d9.tar.gz
metasol-0798cfe1ecb92996ed7959383dcc4b8b0d51a1d9.zip

Merge branch ‘master’ of github.com:thecharlesblake/Solvitaire into ipg

Diffstat (limited to 'src/main/input-output')
-rw-r--r--src/main/input-output/input/command_line_helper.cpp26
-rw-r--r--src/main/input-output/input/command_line_helper.h4
-rw-r--r--src/main/input-output/input/json-parsing/deal_parser.cpp4
-rw-r--r--src/main/input-output/input/json-parsing/rules_parser.cpp24
-rw-r--r--src/main/input-output/input/sol_preset_types.cpp25
5 files changed, 74 insertions, 9 deletions
diff --git a/src/main/input-output/input/command_line_helper.cpp b/src/main/input-output/input/command_line_helper.cpp
index 2abef54..ec9a375 100644
--- a/src/main/input-output/input/command_line_helper.cpp
+++ b/src/main/input-output/input/command_line_helper.cpp
@@ -41,14 +41,17 @@ command_line_helper::command_line_helper()
("cache-capacity", po::value<uint64_t>(), "sets an upper bound on the number of states allowed in "
"the cache")
("solvability", po::value<int>(), "calculates the solvability "
- "percentage of the supplied solitaire game, given a timeout in milliseconds. Must supply "
- "either 'random', 'benchmark', 'solvability' or list of deals to be "
- "solved.")
+ "percentage of the supplied solitaire game, given a limit for the number of seeds. Must supply "
+ "either 'random', 'benchmark', 'solvability' or list of deals to be solved.")
+ ("timeout", po::value<uint64_t>(), "adds a per-game timeout to the solvability percentage generation")
("resume", po::value<vector<int>>()->multitoken(), "resumes the solvability percentage calculation from a "
"previous run. Must be supplied with the solvability option. "
"Syntax: [sol unsol intract in-progress-1 in-progress-2 ...]")
("cores", po::value<uint>(), "the number of cores for the solvability percentages to be run across. "
- "Must be supplied with the solvability option.")
+ "Must be supplied with the solvability option.")
+ ("streamliners", "applies any relevant streamliners to the search. If the --solvability option is supplied,"
+ " runs the streamliner version of the search first and then if unsuccessful, the full"
+ " search for each seed.")
("benchmark", "outputs performance statistics for the solver on the "
"supplied solitaire game. Must supply "
"either 'random', 'benchmark', 'solvability' or list of deals to be "
@@ -121,6 +124,12 @@ bool command_line_helper::parse(int argc, const char* argv[]) {
solvability = -1;
}
+ if (vm.count("timeout")) {
+ timeout = vm["timeout"].as<uint64_t>();
+ } else {
+ timeout = 604800000; // 1 week in milliseconds
+ }
+
if (vm.count("cores")) {
cores = vm["cores"].as<uint>();
} else {
@@ -134,6 +143,7 @@ bool command_line_helper::parse(int argc, const char* argv[]) {
for (uint i = 0; i < cores; i++) resume.push_back(i);
}
+ streamliners = (vm.count("streamliners") != 0);
benchmark = (vm.count("benchmark") != 0);
@@ -248,6 +258,10 @@ int command_line_helper::get_solvability() {
return solvability;
}
+uint64_t command_line_helper::get_timeout() {
+ return timeout;
+}
+
vector<int> command_line_helper::get_resume() {
return resume;
}
@@ -267,3 +281,7 @@ string command_line_helper::get_describe_game_rules() {
bool command_line_helper::get_benchmark() {
return benchmark;
}
+
+bool command_line_helper::get_streamliners() {
+ return streamliners;
+}
diff --git a/src/main/input-output/input/command_line_helper.h b/src/main/input-output/input/command_line_helper.h
index 3ce239d..c12bb69 100644
--- a/src/main/input-output/input/command_line_helper.h
+++ b/src/main/input-output/input/command_line_helper.h
@@ -21,9 +21,11 @@ public:
uint get_cores();
bool get_available_game_types();
bool get_benchmark();
+ bool get_streamliners();
std::vector<int> get_resume();
uint64_t get_cache_capacity();
std::string get_describe_game_rules();
+ uint64_t get_timeout();
private:
bool assess_errors();
@@ -50,7 +52,9 @@ private:
uint cores;
bool available_game_types;
bool benchmark;
+ bool streamliners;
uint64_t cache_capacity;
+ uint64_t timeout;
};
#endif //SOLVITAIRE_COMMAND_LINE_HELPER_H
diff --git a/src/main/input-output/input/json-parsing/deal_parser.cpp b/src/main/input-output/input/json-parsing/deal_parser.cpp
index 29ac3b1..e776cbd 100644
--- a/src/main/input-output/input/json-parsing/deal_parser.cpp
+++ b/src/main/input-output/input/json-parsing/deal_parser.cpp
@@ -5,11 +5,13 @@
#include "deal_parser.h"
#include "../../../game/search-state/game_state.h"
#include "json_helper.h"
+#include "../../../game/sol_rules.h"
using namespace std;
using namespace rapidjson;
typedef sol_rules::build_policy pol;
+typedef sol_rules::face_up_policy fu;
void deal_parser::parse(game_state &gs, const rapidjson::Document& doc) {
// There are two stages to reading in the supplied deal. It is both put
@@ -100,7 +102,7 @@ void deal_parser::parse_tableau_piles(game_state &gs, const rapidjson::Document&
for (auto& json_card : p.first->GetArray()) {
assert(json_card.IsString());
- gs.place_card(*p.second, card(json_card.GetString()));
+ gs.place_card(*p.second, card(json_card.GetString(), gs.rules.face_up != fu::ALL));
}
}
}
diff --git a/src/main/input-output/input/json-parsing/rules_parser.cpp b/src/main/input-output/input/json-parsing/rules_parser.cpp
index d4879de..29e755b 100644
--- a/src/main/input-output/input/json-parsing/rules_parser.cpp
+++ b/src/main/input-output/input/json-parsing/rules_parser.cpp
@@ -9,6 +9,7 @@
#include "json_helper.h"
#include "../sol_preset_types.h"
#include "../../../game/card.h"
+#include "../../../game/sol_rules.h"
using namespace std;
using namespace rapidjson;
@@ -20,6 +21,7 @@ using namespace rapidjson;
typedef sol_rules::build_policy pol;
typedef sol_rules::spaces_policy s_pol;
typedef sol_rules::stock_deal_type sdt;
+typedef sol_rules::face_up_policy fu;
const sol_rules rules_parser::from_file(const string rules_file) {
sol_rules sr = get_default();
@@ -160,6 +162,25 @@ void rules_parser::modify_sol_rules(sol_rules& sr, Document& d) {
}
}
+ string face_up_str;
+ if (d["tableau piles"].HasMember("face up cards")) {
+ if (d["tableau piles"]["face up cards"].IsString()) {
+ face_up_str = d["tableau piles"]["face up cards"].GetString();
+
+ if (face_up_str == "all") {
+ sr.face_up = fu::ALL;
+ } else if (face_up_str == "top") {
+ sr.face_up = fu::TOP_CARDS;
+ } else {
+ string err = "[tableau piles][face up cards] is invalid: " + face_up_str;
+ json_helper::json_parse_err(err);
+ }
+
+ } else {
+ json_helper::json_parse_err("[tableau piles][face up cards] must be a string");
+ }
+ }
+
} else {
json_helper::json_parse_err("[tableau piles] must be an object");
}
@@ -318,7 +339,8 @@ string rules_parser::rules_schema_json() {
"spaces policy": {"type": "string", "enum": ["any", "no-build", "kings"]},
"diagonal deal": {"type": "boolean"},
"move built group": {"type": "boolean"},
- "move built group policy": {"type": "string", "enum": ["same-as-build", "any-suit", "red-black", "same-suit", "no-build"]}
+ "move built group policy": {"type": "string", "enum": ["same-as-build", "any-suit", "red-black", "same-suit", "no-build"]},
+ "face up cards": {"type": "string", "enum": ["all", "top"]}
}, "additionalProperties": false
},
"max rank": {"type": "integer", "minimum": 1, "maximum": 13},
diff --git a/src/main/input-output/input/sol_preset_types.cpp b/src/main/input-output/input/sol_preset_types.cpp
index 53141a8..a10df54 100644
--- a/src/main/input-output/input/sol_preset_types.cpp
+++ b/src/main/input-output/input/sol_preset_types.cpp
@@ -26,7 +26,8 @@ map<string, string> sol_preset_types::mp = {
"spaces policy": "any",
"diagonal deal": false,
"move built group": false,
- "move built group policy": "same-as-build"
+ "move built group policy": "same-as-build",
+ "face up cards": "all"
},
"max rank": 13,
"two decks": false,
@@ -388,7 +389,8 @@ map<string, string> sol_preset_types::mp = {
"build policy": "red-black",
"spaces policy": "kings",
"move built group": true,
- "diagonal deal": true
+ "diagonal deal": true,
+ "face up cards": "top"
},
"stock size": 24,
"stock deal count": 1,
@@ -408,7 +410,8 @@ map<string, string> sol_preset_types::mp = {
"build policy": "red-black",
"spaces policy": "kings",
"move built group": true,
- "diagonal deal": true
+ "diagonal deal": true,
+ "face up cards": "top"
},
"stock size": 24,
"stock deal count": 3,
@@ -928,6 +931,22 @@ map<string, string> sol_preset_types::mp = {
"max rank": 9
}
)"
+ },
+ {
+ "simple-simon",
+
+ R"(
+{
+ "tableau piles": {
+ "count": 10,
+ "diagonal deal": true,
+ "move built group": true,
+ "move built group policy": "same-suit"
+ },
+ "foundations complete piles": true
+}
+)"
+
}
};