From 332a8262cca7edbc43c702f3c9b055bf044ccb2c Mon Sep 17 00:00:00 2001 From: Tom Harley Date: Mon, 25 Feb 2019 15:42:38 +0000 Subject: 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. --- metasol.cpp | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) (limited to 'metasol.cpp') 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 +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 *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 build_policy_t str_build_policy(char *str) { kv_dict(build_policy_t) dict = { @@ -818,6 +844,16 @@ solve_status run_loop(ms_game_state *gs, ms_rules *r, ms_settings *s, unsigned vote_count = s->max_votes; 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. -- cgit v1.2.1