diff options
Diffstat (limited to 'src/main')
| -rw-r--r-- | src/main/evaluation/benchmark.cpp | 21 | ||||
| -rw-r--r-- | src/main/game/game_state.cpp | 22 | ||||
| -rw-r--r-- | src/main/input-output/input/sol_preset_types.cpp | 38 | ||||
| -rw-r--r-- | src/main/main.cpp | 31 |
4 files changed, 47 insertions, 65 deletions
diff --git a/src/main/evaluation/benchmark.cpp b/src/main/evaluation/benchmark.cpp index f25e491..b8866ff 100644 --- a/src/main/evaluation/benchmark.cpp +++ b/src/main/evaluation/benchmark.cpp @@ -4,6 +4,7 @@ #include <climits> #include <iostream> +#include <numeric> #include "benchmark.h" #include "../game/game_state.h" @@ -14,16 +15,14 @@ typedef chrono::microseconds microsec; void benchmark::run(const sol_rules &rules) { cout << "Seed " - "| Median Solution Time(μs) " - "| Median States Searched " - "| Median Backtracks " - "| Median (Non-Zero) Solution Depth " - "| Solvable/Unsolvable "; + "| Median/Mean Solution Time(μs)" + "| Median/Mean States Searched " + "| Solvable/Unsolvable "; multiset<int> sol_times; multiset<int> states_searched; - multiset<int> sol_depths; - multiset<int> backtracks; + int total_time = 0; + int total_states = 0; int total_solvable = 0; int total_unsolvable = 0; @@ -38,9 +37,9 @@ void benchmark::run(const sol_rules &rules) { chrono::duration_cast<chrono::microseconds>(end - start); sol_times.insert(static_cast<int>(elapsed_micros.count())); + total_time += static_cast<int>(elapsed_micros.count()); states_searched.insert(sol.get_states_searched()); - if (sol.get_final_depth() != 0) sol_depths.insert(sol.get_final_depth()); - backtracks.insert(sol.get_backtrack_count()); + total_states += sol.get_states_searched(); switch (result) { case solver::sol_state::solved: total_solvable++; @@ -55,9 +54,9 @@ void benchmark::run(const sol_rules &rules) { cout << "\n" << seed << " | " << *next(begin(sol_times), (sol_times.size())/2) + << "/" << total_time/sol_times.size() << " | " << *next(begin(states_searched), (states_searched.size())/2) - << " | " << *next(begin(backtracks), (backtracks.size())/2) - << " | " << *next(begin(sol_depths), (sol_depths.size())/2) + << "/" << total_states/sol_times.size() << " | " << total_solvable << "/" << total_unsolvable; } diff --git a/src/main/game/game_state.cpp b/src/main/game/game_state.cpp index 58f5f68..2e79f41 100644 --- a/src/main/game/game_state.cpp +++ b/src/main/game/game_state.cpp @@ -464,8 +464,8 @@ bool game_state::is_valid_auto_foundation_move(pile_ref target_pile) const { // The max difference between the 'move up' card and the foundations of the // same colour and the other colour - int same_col_rank_diff = 0; - int other_col_rank_diff = 0; + int same_rank_diff = 0; + int other_rank_diff = 0; for (pile_ref pr : foundations) { if (pr == target_pile) continue; @@ -475,22 +475,24 @@ bool game_state::is_valid_auto_foundation_move(pile_ref target_pile) const { card c(s, r); auto rank_diff = int(move_up_card.get_rank() - r); - if (move_up_card.get_colour() == c.get_colour()) { - same_col_rank_diff = rank_diff; + if (move_up_card.get_suit() == c.get_suit() + || (rules.build_pol == pol::RED_BLACK + && move_up_card.get_colour() == c.get_colour())) { + same_rank_diff = rank_diff; } else { - other_col_rank_diff = max(other_col_rank_diff, rank_diff); + other_rank_diff = max(other_rank_diff, rank_diff); } } - bool other_col_within_1 = other_col_rank_diff <= 1; - bool other_col_within_2 = other_col_rank_diff <= 2; - bool same_col_within_3 = same_col_rank_diff <= 3; + bool other_within_1 = other_rank_diff <= 1; + bool other_within_2 = other_rank_diff <= 2; + bool same_within_3 = same_rank_diff <= 3; if (rules.build_pol == pol::RED_BLACK) { - return other_col_within_1 || (other_col_within_2 && same_col_within_3); + return other_within_1 || (other_within_2 && same_within_3); } else { assert(rules.build_pol == pol::ANY_SUIT); - return other_col_within_2; + return other_within_2; } } diff --git a/src/main/input-output/input/sol_preset_types.cpp b/src/main/input-output/input/sol_preset_types.cpp index 0f2dd67..07c824b 100644 --- a/src/main/input-output/input/sol_preset_types.cpp +++ b/src/main/input-output/input/sol_preset_types.cpp @@ -894,10 +894,10 @@ map<string, string> sol_preset_types::mp = { { "tableau piles": { - "count": 5, + "count": 4, "build policy": "any-suit" }, - "max rank": 6 + "max rank": 5 } )" }, @@ -908,10 +908,10 @@ map<string, string> sol_preset_types::mp = { { "tableau piles": { - "count": 7, + "count": 6, "build policy": "red-black" }, - "max rank": 8 + "max rank": 7 } )" }, @@ -928,36 +928,6 @@ map<string, string> sol_preset_types::mp = { "max rank": 9 } )" - }, - { - "test-game-founds-removable", - - R"( - -{ - "tableau piles": { - "count": 7, - "build policy": "red-black" - }, - "max rank": 8, - "foundations removable": true -} -)" - }, - { - "test-game-diagonal-deal", - - R"( - -{ - "tableau piles": { - "count": 7, - "build policy": "red-black", - "diagonal deal": true - }, - "max rank": 8 -} -)" } }; diff --git a/src/main/main.cpp b/src/main/main.cpp index a8080d5..6d06f5d 100644 --- a/src/main/main.cpp +++ b/src/main/main.cpp @@ -120,27 +120,38 @@ void solve_input_files(const vector<string> input_files, const sol_rules& rules, void solve_game(const game_state& gs, bool short_sol, bool classify) { solver s(gs); solver* solv = &s; - bool solution; if (short_sol) { uint bound = 1; solver::sol_state ss; + bool solution = false; do { LOG_INFO("Depth: " << bound); solver s_(gs); solv = &s_; ss = s_.run_with_cutoff(none, bound++); + + if (ss == solver::sol_state::solved) { + if (!classify) solv->print_solution(); + cout << "Solved\n"; + solution = true; + } } while (ss == solver::sol_state::cutoff); - solution = ss == solver::sol_state::solved; - } else { - solution = solv->run() == solver::sol_state::solved; - } - if (solution) { - if (!classify) solv->print_solution(); - cout << "Solved\n"; + if (!solution) { + if (!classify) cout << "Deal:\n" << gs << "\n"; + cout << "No Possible Solution\n"; + } + } else { - if (!classify) cout << "Deal:\n" << gs << "\n"; - cout << "No Possible Solution\n"; + bool solution = solv->run() == solver::sol_state::solved; + + if (solution) { + if (!classify) solv->print_solution(); + cout << "Solved\n"; + } else { + if (!classify) cout << "Deal:\n" << gs << "\n"; + cout << "No Possible Solution\n"; + } } cout << "States Searched: " << solv->get_states_searched() << "\n"; |
