diff options
| author | Tom Harley | 2019-02-25 15:42:38 +0000 |
|---|---|---|
| committer | Tom Harley | 2019-02-25 15:42:38 +0000 |
| commit | 332a8262cca7edbc43c702f3c9b055bf044ccb2c (patch) | |
| tree | 6930dce53e90414fbe4f4777503c8d1381080b52 | |
| parent | Check for majority moves after regular move (diff) | |
| download | metasol-332a8262cca7edbc43c702f3c9b055bf044ccb2c.tar.gz metasol-332a8262cca7edbc43c702f3c9b055bf044ccb2c.zip | |
Skip to ‘solved’ when there are no hidden cards
If a game-state can be solved by a voter from a position where there are no hidden cards, the game can be solved by metasol also. The rest of the game can be skipped, which saves time.
If the sequence of moves taken is required, the remaining moves can be taken from a successful voter.
| -rw-r--r-- | metasol.cpp | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/metasol.cpp b/metasol.cpp index 4b96f97..6331033 100644 --- a/metasol.cpp +++ b/metasol.cpp @@ -22,9 +22,35 @@ struct dictcmp { } }; -#define kv_dict(t) std::map<const char *, t, dictcmp> +unsigned face_down_count_pile(ms_card_pile *p) { + unsigned result = 0u; + for (auto &c : *p) { + result += c.hidden ? 1u : 0u; + } + return result; +} -#define C(x) #x, +unsigned face_down_count_piles(std::vector<ms_card_pile> *ps) { + unsigned result = 0u; + for (auto &p : *ps) { + result += face_down_count_pile(&p); + } + return result; +} + +unsigned face_down_count(ms_game_state *gs) { + unsigned result = 0u; + result += face_down_count_piles(&gs->foundations); + result += face_down_count_pile(&gs->stock); + result += face_down_count_pile(&gs->waste); + result += face_down_count_piles(&gs->tableau); + result += face_down_count_pile(&gs->hole); + result += face_down_count_piles(&gs->cells); + result += face_down_count_pile(&gs->reserve); + return result; +} + +#define kv_dict(t) std::map<const char *, t, dictcmp> build_policy_t str_build_policy(char *str) { kv_dict(build_policy_t) dict = { @@ -819,6 +845,16 @@ solve_status run_loop(ms_game_state *gs, ms_rules *r, ms_settings *s, ms_move m; /* + * If there are no face-down cards, then any voter run should tell us if the + * deal is solvable. This function is only entered if a voter found a + * solution, so it can be inferred that a solution is found. + */ + if (face_down_count(gs) == 0) { + debug("solution found!\n"); + return SOLVED; + } + + /* * Set up the thread_info structs and add a job to the threadpool for each * one. */ |
