diff options
| author | Charlie Blake | 2018-04-09 19:15:42 +0100 |
|---|---|---|
| committer | GitHub | 2018-04-09 19:15:42 +0100 |
| commit | bbb11b14df8bda5c9aee5394cacd3856a54e9ef8 (patch) | |
| tree | 68dbb8ceafadeaefa3be7d897c6b3d4d018ea3ca | |
| parent | Merge pull request #57 from thecharlesblake/local-results (diff) | |
| parent | fin (diff) | |
| download | metasol-bbb11b14df8bda5c9aee5394cacd3856a54e9ef8.tar.gz metasol-bbb11b14df8bda5c9aee5394cacd3856a54e9ef8.zip | |
Merge pull request #58 from thecharlesblake/fin
fin
| -rw-r--r-- | README.md | 99 | ||||
| -rw-r--r-- | build-notes.md (renamed from build-instructions.md) | 0 | ||||
| -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 |
6 files changed, 47 insertions, 164 deletions
diff --git a/README.md b/README.md deleted file mode 100644 index 3655ce6..0000000 --- a/README.md +++ /dev/null @@ -1,99 +0,0 @@ -# Solvitaire -A solver for a variety of single-player, perfect -information solitaire card games. - -## Project Overview - -The solver should be able to correctly provide -solutions for some instances of solitaire games, and -be able to report other instances as unsolvable, -minimising the number of instances that are deemed -'intractable' (cannot be classified as solvable or -unsolvable within a reasonable time period). A key -study for this project will be how to do this -efficiently for a _variety_ of solitaire games. - -Perfect information games are an especially -important domain in artificial intelligence, and -some of the most high-profile successes in the field -of AI have been creating good players for games like -Chess, Checkers and Go, all of which are perfect -information games. However, relatively little work -has been done on creating programs to play -single-player perfect information games, and good -solvers do not yet exist for most solitaire games. - -Hence, this project will focus on creating a solver -which is general enough to be able to play a wide -range of solitaire games, whilst also maintaining a -high level of efficiency. This efficiency will be -achieved through a combination of language-level -optimisation, and through exploring different AI -search techniques. A specialised solver will be -written to accomplish this, in code rather than -using an existing constraint solving or planning -programs. - -## Objectives - -### Primary Objectives -- An application for solving single-player, perfect -information solitaire instances (software artefact). -- Some kind of schema or language for describing a -_wide_ range of solitaire games. -- The application must be able to solve valid games -expressed using the schema/language. -- Automated testing to demonstrate the correctness -of my classifications. -- An implementation of search techniques such as -'meta-moves'/'super moves' and eliminating -symmetrical states. -- An implementation of language-level/design -optimisations to improve the efficiency of my -search. -- An analysis in my report of the effects of the -above search techniques and implementation choices -on the performance of the solver. - -### Secondary Objectives - -- Optimise the search algorithm to eliminate -searching states in which certain moves/states -'dominate' others. -- Implement and evaluate more than one different -type of search (e.g. best first, iterative -deepening). **Objective adjusted:** This is no -longer deemed essential, as the focus in on -exhaustive search, but it may be interesting -to explore how iterative deepening performs. -- Experiment with and evaluate different designs -for the general heuristic for best-first search, -that works across a variety of games. -**Objective adjusted:** This is no longer relevant. - -### Tertiary Objectives - -Other tertiary objectives that satisfy the core -aims of the project would be reasonable -additions. Below are two particular instances of -interesting routes down which this project could -be taken: - -- An extension of the algorithm that aims to -provide shortened solutions (i.e. ones that -minimise the number of moves taken). -**Objective adjusted:** This may be done in -tandem with the iterative deepening objective. -- Calculating the solvability ratio for some the -games my application can solve. -**Objective adjusted:** Because of good progress -made, this is now very much a target for the -project. - -## Supervisor - -Ian Gent - -## Background - -["Search in the Patience Game Black Hole"](https://pn.host.cs.st-andrews.ac.uk/blackhole-revised-final.pdf) diff --git a/build-instructions.md b/build-notes.md index ae6d386..ae6d386 100644 --- a/build-instructions.md +++ b/build-notes.md 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"; |
