From bca053ac856431e594cf01dc6fda5e13bf1ecc28 Mon Sep 17 00:00:00 2001 From: thecharlesblake Date: Thu, 22 Feb 2018 23:05:00 +0000 Subject: Add reduce suit streamliner: replace card symmetry --- src/main/game/global_cache.cpp | 18 +++++++++--------- src/main/main.cpp | 38 ++++++++++++++++++++++++-------------- 2 files changed, 33 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/main/game/global_cache.cpp b/src/main/game/global_cache.cpp index 5d2fd79..4811853 100644 --- a/src/main/game/global_cache.cpp +++ b/src/main/game/global_cache.cpp @@ -82,13 +82,9 @@ void cached_game_state::add_card(card c, const game_state& gs) { #else auto& target = data; #endif - + switch (gs.rules.build_pol) { -#ifdef NO_CARD_SYMMETRY - default: - target.emplace_back(c); - break; -#else +#ifdef SUIT_REDUCTION_STREAMLINER case pol::SAME_SUIT: target.emplace_back(c); break; @@ -98,6 +94,10 @@ void cached_game_state::add_card(card c, const game_state& gs) { default: target.emplace_back(0, c.get_rank()); break; +#else + default: + target.emplace_back(c); + break; #endif } } @@ -152,9 +152,7 @@ std::size_t hasher::combine(std::size_t& seed, std::size_t value) const { size_t hasher::hash_value(card const& c) const { boost::hash boost_hasher; -#ifdef NO_CARD_SYMMETRY - uint8_t suit_val = c.get_suit(); -#else +#ifdef SUIT_REDUCTION_STREAMLINER uint8_t suit_val; switch (init_gs.rules.build_pol) { case pol::SAME_SUIT: @@ -166,6 +164,8 @@ size_t hasher::hash_value(card const& c) const { default: suit_val = 0; } +#else + uint8_t suit_val = c.get_suit(); #endif auto raw_val = static_cast(suit_val * 13 + c.get_rank()); diff --git a/src/main/main.cpp b/src/main/main.cpp index 975e6c8..be03e02 100644 --- a/src/main/main.cpp +++ b/src/main/main.cpp @@ -18,9 +18,9 @@ using namespace boost; namespace po = boost::program_options; const optional gen_rules(command_line_helper&); -void solve_random_game(int, const sol_rules&); -void solve_input_files(vector, const sol_rules&); -void solve_game(const game_state&); +void solve_random_game(int, const sol_rules&, bool); +void solve_input_files(vector, const sol_rules&, bool); +void solve_game(const game_state&, bool); int main(int argc, const char* argv[]) { @@ -40,11 +40,11 @@ int main(int argc, const char* argv[]) { // If there are no input files, solve a random deal based on the // supplied seed if (input_files.empty()) { - solve_random_game(clh.get_random_deal(), *rules); + solve_random_game(clh.get_random_deal(), *rules, clh.get_classify()); } // Otherwise, solve the input files else { - solve_input_files(input_files, *rules); + solve_input_files(input_files, *rules, clh.get_classify()); } return EXIT_SUCCESS; @@ -65,13 +65,14 @@ const optional gen_rules(command_line_helper& clh) { } } -void solve_random_game(int seed, const sol_rules& rules) { +void solve_random_game(int seed, const sol_rules& rules, bool classify) { LOG_INFO ("Attempting to solve with seed: " << seed << "..."); game_state gs(rules, seed); - solve_game(gs); + solve_game(gs, classify); } -void solve_input_files(const vector input_files, const sol_rules& rules) { +void solve_input_files(const vector input_files, const sol_rules& rules, + bool classify) { for (const string& input_file : input_files) { try { // Reads in the input file to a json doc @@ -81,7 +82,7 @@ void solve_input_files(const vector input_files, const sol_rules& rules) game_state gs(rules, in_doc); LOG_INFO ("Attempting to solve " << input_file << "..."); - solve_game(gs); + solve_game(gs, classify); } catch (const runtime_error& error) { string errmsg = "Error parsing deal file: "; @@ -91,15 +92,24 @@ void solve_input_files(const vector input_files, const sol_rules& rules) } } -void solve_game(const game_state& gs) { +void solve_game(const game_state& gs, bool classify) { solver solv(gs); bool solution = solv.run(); ProfilerStop(); - if (solution) { - solv.print_solution(); + if (classify) { + if (solution) { + cout << "Solved\n"; + } else { + cout << "No solution\n"; + } } else { - cout << "Deal:\n" << gs << "\nNo Possible Solution\nStates Searched: " - << solv.get_states_searched() << "\n"; + if (solution) { + solv.print_solution(); + } else { + cout << "Deal:\n" << gs + << "\nNo Possible Solution\nStates Searched: " + << solv.get_states_searched() << "\n"; + } } } -- cgit v1.2.1