From 079c72c083a35c5d22a70e2d54bb1567db98321b Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Tue, 26 Dec 2017 12:03:35 +0000 Subject: Rework basic deal-parser outline --- src/main/main.cpp | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'src/main/main.cpp') diff --git a/src/main/main.cpp b/src/main/main.cpp index 2de01d8..ddf8f73 100644 --- a/src/main/main.cpp +++ b/src/main/main.cpp @@ -4,7 +4,6 @@ #include "input-output/command_line_helper.h" #include "input-output/deal_parser.h" -#include "game/game_state.h" #include "solver/solver.h" #include "input-output/log_helper.h" @@ -17,7 +16,7 @@ namespace po = boost::program_options; const optional gen_rules(command_line_helper&); void solve_random_game(int, const sol_rules&); -void solve_input_files(const vector, const sol_rules); +void solve_input_files(const vector, const sol_rules&); void solve_game(const game_state&, const sol_rules&); int main(int argc, const char* argv[]) { @@ -69,17 +68,22 @@ void solve_random_game(int seed, const sol_rules& rules) { solve_game(gs, rules); } -void solve_input_files(const vector input_files, const sol_rules rules) { - for (const auto &input_json : input_files) { - // Attempts to read the user's json into a document - Document doc; - deal_parser::parse(doc, input_json); +void solve_input_files(const vector input_files, const sol_rules& rules) { + deal_parser dp(rules); - // Creates a game state object from the json, plus a solver - game_state gs(doc); + for (const string& input_json : input_files) { + try { + // Attempts to create a game state object from the json + game_state gs = dp.parse(input_json); - LOG_INFO ("Attempting to solve " << input_json << "..."); - solve_game(gs, rules); + LOG_INFO ("Attempting to solve " << input_json << "..."); + solve_game(gs, rules); + + } catch (const runtime_error& error) { + string errmsg = "Error parsing deal file: "; + errmsg += error.what(); + LOG_ERROR(errmsg); + } } } -- cgit v1.2.1 From bf23d041cb9e7d5f1dcad6b26a93c43a69fce8bc Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Tue, 26 Dec 2017 13:00:48 +0000 Subject: Refactor game state to prep for deal parse --- src/main/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main/main.cpp') diff --git a/src/main/main.cpp b/src/main/main.cpp index ddf8f73..54e9404 100644 --- a/src/main/main.cpp +++ b/src/main/main.cpp @@ -64,7 +64,7 @@ const optional gen_rules(command_line_helper& clh) { void solve_random_game(int seed, const sol_rules& rules) { LOG_INFO ("Attempting to solve with seed: " << seed << "..."); - game_state gs(seed, rules); + game_state gs(rules, seed); solve_game(gs, rules); } -- cgit v1.2.1 From b8f4cae869eace06df73ac7c1c390cc42cfe499b Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Tue, 26 Dec 2017 17:29:24 +0000 Subject: Add basic tableau deal parsing --- src/main/main.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/main/main.cpp') diff --git a/src/main/main.cpp b/src/main/main.cpp index 54e9404..158ca07 100644 --- a/src/main/main.cpp +++ b/src/main/main.cpp @@ -3,9 +3,9 @@ #include #include "input-output/command_line_helper.h" -#include "input-output/deal_parser.h" #include "solver/solver.h" #include "input-output/log_helper.h" +#include "util/util.h" using namespace rapidjson; @@ -69,14 +69,15 @@ void solve_random_game(int seed, const sol_rules& rules) { } void solve_input_files(const vector input_files, const sol_rules& rules) { - deal_parser dp(rules); - - for (const string& input_json : input_files) { + for (const string& input_file : input_files) { try { + // Reads in the input file to a json doc + const Document in_doc = util::get_file_json(input_file); + // Attempts to create a game state object from the json - game_state gs = dp.parse(input_json); + game_state gs(rules, in_doc); - LOG_INFO ("Attempting to solve " << input_json << "..."); + LOG_INFO ("Attempting to solve " << input_file << "..."); solve_game(gs, rules); } catch (const runtime_error& error) { -- cgit v1.2.1