aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCharlie Blake2018-04-05 15:54:20 +0100
committerGitHub2018-04-05 15:54:20 +0100
commit4c4bf8a2e153b0ead77931285704aa7a0d2b7475 (patch)
tree716b8cc644945daaa1d9665f7ffc98a25d4a36d4 /src
parentMerge pull request #48 from thecharlesblake/wider-testing (diff)
parentAdd cmd line opts to list games and describe rules (diff)
downloadmetasol-4c4bf8a2e153b0ead77931285704aa7a0d2b7475.tar.gz
metasol-4c4bf8a2e153b0ead77931285704aa7a0d2b7475.zip

Merge pull request #49 from thecharlesblake/add-more-games

Add more games

Diffstat (limited to 'src')
-rw-r--r--src/main/game/game_state.cpp71
-rw-r--r--src/main/game/game_state.legal_moves.cpp50
-rw-r--r--src/main/game/sol_rules.cpp1
-rw-r--r--src/main/game/sol_rules.h3
-rw-r--r--src/main/input-output/input/command_line_helper.cpp34
-rw-r--r--src/main/input-output/input/command_line_helper.h4
-rw-r--r--src/main/input-output/input/json-parsing/rules_parser.cpp22
-rw-r--r--src/main/input-output/input/sol_preset_types.cpp577
-rw-r--r--src/main/input-output/input/sol_preset_types.h3
-rw-r--r--src/main/main.cpp12
-rw-r--r--src/main/solvability/solvability_calc.cpp2
-rw-r--r--src/test/unit_tests/legal_move_gen_test.cpp19
12 files changed, 753 insertions, 45 deletions
diff --git a/src/main/game/game_state.cpp b/src/main/game/game_state.cpp
index 23ba50d..897adf1 100644
--- a/src/main/game/game_state.cpp
+++ b/src/main/game/game_state.cpp
@@ -228,17 +228,35 @@ bool game_state::move::is_dominance() const {
/////////////////////////
void game_state::make_move(const move m) {
- // Handles special stock-to-tableau-piles move
- if (rules.stock_deal_t == sdt::TABLEAU_PILES && m.from == stock) {
- assert(m.from == stock);
- assert(m.to == 255 );
-
- for (pile_ref tab_pr = original_tableau_piles.front();
- tab_pr < pile_ref(original_tableau_piles.front() + m.count);
- tab_pr++) {
- place_card(tab_pr, take_card(stock));
+ // Handles stock moves
+ if (m.from == stock) {
+ // Handles special stock-to-tableau-piles move
+ if (rules.stock_deal_t == sdt::TABLEAU_PILES) {
+ assert(m.from == stock);
+ assert(m.to == 255);
+
+ for (pile_ref tab_pr = original_tableau_piles.front();
+ tab_pr < pile_ref(original_tableau_piles.front() + m.count);
+ tab_pr++) {
+ place_card(tab_pr, take_card(stock));
+ }
+ }
+ // Handles stock-to-waste moves
+ else {
+ if (piles[stock].empty()) {
+ // Re-deal waste back to stock
+ while (!piles[waste].empty()) {
+ place_card(stock, take_card(waste));
+ }
+ } else {
+ assert(m.to == waste);
+ for (int i = 0; i < m.count; i++) {
+ place_card(waste, take_card(stock));
+ }
+ }
}
}
+
// If this is not a built-pile move
else if (m.count == 1 || m.is_dominance()) {
assert(m.from < piles.size());
@@ -249,6 +267,7 @@ void game_state::make_move(const move m) {
update_auto_foundation_moves(m.to);
#endif
}
+
// If this is a built-pile move
else {
assert(m.from < piles.size() );
@@ -270,14 +289,31 @@ void game_state::make_move(const move m) {
void game_state::undo_move(const move m) {
assert(m.from < piles.size());
- // Handles special stock-to-tableau-piles move
- if (rules.stock_deal_t == sdt::TABLEAU_PILES && m.from == stock) {
- for (pile_ref tab_pr = original_tableau_piles.front() + m.count;
- tab_pr-- > original_tableau_piles.front();
- ) {
- place_card(stock, take_card(tab_pr));
+ // Handles stock moves
+ if (m.from == stock) {
+ // Handles special stock-to-tableau-piles move
+ if (rules.stock_deal_t == sdt::TABLEAU_PILES) {
+ for (pile_ref tab_pr = original_tableau_piles.front() + m.count;
+ tab_pr-- > original_tableau_piles.front();
+ ) {
+ place_card(stock, take_card(tab_pr));
+ }
+ }
+ // Handles stock-to-waste moves
+ else {
+ if (piles[waste].empty()) {
+ // Re-deal waste back to stock
+ while (!piles[stock].empty()) {
+ place_card(waste, take_card(stock));
+ }
+ } else {
+ for (int i = 0; i < m.count; i++) {
+ place_card(stock, take_card(waste));
+ }
+ }
}
}
+
// If this is not a built-pile move
else if (m.count == 1 || m.is_dominance()) {
assert(m.to < piles.size());
@@ -285,7 +321,10 @@ void game_state::undo_move(const move m) {
#ifndef NO_AUTO_FOUNDATIONS
update_auto_foundation_moves(m.from);
#endif
- } else {
+ }
+
+ // If this is a built-pile move
+ else {
assert(m.to < piles.size());
assert(m.count <= rules.max_rank);
// Adds the cards to the 'from' pile
diff --git a/src/main/game/game_state.legal_moves.cpp b/src/main/game/game_state.legal_moves.cpp
index c137b07..24304a1 100644
--- a/src/main/game/game_state.legal_moves.cpp
+++ b/src/main/game/game_state.legal_moves.cpp
@@ -25,17 +25,18 @@ vector<game_state::move> game_state::get_legal_moves(
if (rules.stock_size > 0
&& rules.stock_deal_t == sdt::TABLEAU_PILES
&& !piles[stock].empty()) {
- // Only does this if none of the tableau piles are empty
- bool no_tableau_empty = true;
- for (auto tab_ref : tableau_piles) {
- if (piles[tab_ref].empty()) {
- no_tableau_empty = false;
- break;
- }
- }
- if (no_tableau_empty) {
- moves.emplace_back(get_stock_tableau_move());
- }
+
+ moves.emplace_back(get_stock_tableau_move());
+ }
+
+ // If the stock is empty and we are allowed to re-deal, move the waste
+ // back onto the stock
+ if (rules.stock_size > 0
+ && rules.stock_redeal
+ && rules.stock_deal_t == sdt::WASTE
+ && piles[stock].empty()
+ && !piles[waste].empty()) {
+ moves.emplace_back(stock, waste);
}
// Cycles through each pile which we may be able to remove a card from
@@ -70,7 +71,9 @@ vector<game_state::move> game_state::get_legal_moves(
// Stock cards can only be moved to the waste (assuming there is a waste)
if (rules.stock_size > 0 && rem_ref == stock) {
if (rules.stock_deal_t == sdt::WASTE) {
- moves.emplace_back(stock, waste);
+ uint8_t cards_to_move =
+ min(rules.stock_deal_count, piles[stock].size());
+ moves.emplace_back(stock, waste, cards_to_move);
}
continue;
}
@@ -148,12 +151,19 @@ game_state::move game_state::get_stock_tableau_move() const {
// suit/rank can be moved to a tableau
bool game_state::is_valid_tableau_move(const pile_ref rem_ref,
const pile_ref add_ref) const {
- if (rem_ref == add_ref) return false;
-
- else if (rules.build_pol == pol::NO_BUILD) return false;
-
- else if (piles[add_ref].empty()) {
- return rules.spaces_pol == s_pol::ANY;
+ if (rem_ref == add_ref) {
+ return false;
+ } else if (rules.build_pol == pol::NO_BUILD) {
+ return false;
+ } else if (piles[add_ref].empty()) {
+ switch(rules.spaces_pol) {
+ case sol_rules::spaces_policy::NO_BUILD:
+ return false;
+ case sol_rules::spaces_policy::KINGS:
+ return piles[rem_ref].top_card().get_rank() == 13;
+ case sol_rules::spaces_policy::ANY:
+ return true;
+ }
}
card rem_c = piles[rem_ref].top_card();
@@ -235,7 +245,9 @@ void game_state::get_built_group_moves(vector<move>& moves) const {
// If the pile is empty, and we can move to empty piles, does so
if (piles[add_ref].empty()) {
- if (rules.spaces_pol == s_pol::ANY) {
+ if (rules.spaces_pol == s_pol::ANY ||
+ (rules.spaces_pol == s_pol::KINGS
+ && bg_high.get_rank() == 13)) {
add_empty_built_group_moves(moves, rem_ref, add_ref, bg_high);
}
}
diff --git a/src/main/game/sol_rules.cpp b/src/main/game/sol_rules.cpp
index 592437d..4cef7c1 100644
--- a/src/main/game/sol_rules.cpp
+++ b/src/main/game/sol_rules.cpp
@@ -26,6 +26,7 @@ sol_rules::sol_rules() :
cells(0),
stock_size(0),
stock_deal_t(sdt::TABLEAU_PILES),
+ stock_deal_count(1),
reserve_size(0),
reserve_stacked(false) {
}
diff --git a/src/main/game/sol_rules.h b/src/main/game/sol_rules.h
index 98474fc..0314af5 100644
--- a/src/main/game/sol_rules.h
+++ b/src/main/game/sol_rules.h
@@ -21,6 +21,7 @@ struct sol_rules {
};
enum class spaces_policy {
NO_BUILD,
+ KINGS,
ANY
};
enum class stock_deal_type {
@@ -44,6 +45,8 @@ struct sol_rules {
uint8_t cells;
uint8_t stock_size;
stock_deal_type stock_deal_t;
+ uint8_t stock_deal_count;
+ bool stock_redeal;
uint8_t reserve_size;
bool reserve_stacked;
};
diff --git a/src/main/input-output/input/command_line_helper.cpp b/src/main/input-output/input/command_line_helper.cpp
index 7853b55..5518f1f 100644
--- a/src/main/input-output/input/command_line_helper.cpp
+++ b/src/main/input-output/input/command_line_helper.cpp
@@ -22,11 +22,17 @@ command_line_helper::command_line_helper()
main_options.add_options()
("help", "produce help message")
("type", po::value<string>(),
- "specify the type of the solitaire game to be solved. Must supply "
- "either 'type' or 'rules' file")
- ("rules", po::value<string>(),
+ "specify the type of the solitaire game to be solved from the list "
+ "of preset games. Must supply either this 'type' option, "
+ "or the 'custom-rules' option")
+ ("available-game-types", "outputs a list of the different preset "
+ "game types that can be solved")
+ ("describe-game-rules", po::value<string>(),
+ "outputs the JSON that describes the rules of the supplied "
+ "preset game type")
+ ("custom-rules", po::value<string>(),
"the path to a JSON file describing the rules of the solitaire "
- "to be solved. Must supply either 'type' or 'rules' file")
+ "to be solved. Must supply either 'type' or 'custom-rules' option")
("random", po::value<int>(), "create and solve a random solitaire "
"deal based on a seed. Must supply either 'random',"
"'solvability' or list of deals to be solved.")
@@ -68,6 +74,12 @@ bool command_line_helper::parse(int argc, const char* argv[]) {
help = (vm.count("help") != 0);
+ available_game_types = (vm.count("available-game-types") != 0);
+
+ if (vm.count("describe-game-rules")) {
+ describe_game_rules = vm["describe-game-rules"].as<string>();
+ }
+
classify = (vm.count("classify") != 0);
if (vm.count("input-files")) {
@@ -102,6 +114,8 @@ bool command_line_helper::assess_errors() {
return false;
}
+ if (available_game_types || !describe_game_rules.empty()) return true;
+
// The user must either supply input files, a random seed, or ask for the
// solvability percentage
int opt_count = (random_deal != -1) + !input_files.empty() + solvability;
@@ -146,8 +160,8 @@ bool command_line_helper::assess_sol_type() {
}
void command_line_helper::print_help() {
- LOG_ERROR ("Usage: solvitaire [options] input-file1 input-file2 ...\n"
- << main_options);
+ cerr << "Usage: solvitaire [options] input-file1 input-file2 ...\n"
+ << main_options << "\n";
}
void command_line_helper::print_no_opts_error() {
@@ -201,6 +215,14 @@ bool command_line_helper::get_solvability() {
return solvability;
}
+bool command_line_helper::get_available_game_types() {
+ return available_game_types;
+}
+
+string command_line_helper::get_describe_game_rules() {
+ return describe_game_rules;
+}
+
bool command_line_helper::get_short_sols() {
return shortest_sols;
}
diff --git a/src/main/input-output/input/command_line_helper.h b/src/main/input-output/input/command_line_helper.h
index f3ed443..8773fd8 100644
--- a/src/main/input-output/input/command_line_helper.h
+++ b/src/main/input-output/input/command_line_helper.h
@@ -20,6 +20,8 @@ public:
bool get_classify();
bool get_solvability();
bool get_short_sols();
+ bool get_available_game_types();
+ std::string get_describe_game_rules();
private:
bool assess_errors();
@@ -37,11 +39,13 @@ private:
std::vector<std::string> input_files;
std::string solitaire_type;
std::string rules_file;
+ std::string describe_game_rules;
int random_deal;
bool help;
bool classify;
bool solvability;
bool shortest_sols;
+ bool available_game_types;
};
#endif //SOLVITAIRE_COMMAND_LINE_HELPER_H
diff --git a/src/main/input-output/input/json-parsing/rules_parser.cpp b/src/main/input-output/input/json-parsing/rules_parser.cpp
index 3c4bee3..02b2583 100644
--- a/src/main/input-output/input/json-parsing/rules_parser.cpp
+++ b/src/main/input-output/input/json-parsing/rules_parser.cpp
@@ -109,6 +109,8 @@ void rules_parser::modify_sol_rules(sol_rules& sr, Document& d) {
sr.spaces_pol = s_pol::ANY;
} else if (sp_str == "no-build") {
sr.spaces_pol = s_pol::NO_BUILD;
+ } else if (sp_str == "kings") {
+ sr.spaces_pol = s_pol::KINGS;
} else {
json_helper::json_parse_err("[tableau piles][spaces policy] is invalid");
}
@@ -248,6 +250,22 @@ void rules_parser::modify_sol_rules(sol_rules& sr, Document& d) {
}
}
+ if (d.HasMember("stock deal count")) {
+ if (d["stock deal count"].IsInt()) {
+ sr.stock_deal_count = static_cast<uint8_t>(d["stock deal count"].GetInt());
+ } else {
+ json_helper::json_parse_err("[stock deal count] must be an integer");
+ }
+ }
+
+ if (d.HasMember("stock redeal")) {
+ if (d["stock redeal"].IsBool()) {
+ sr.stock_redeal = static_cast<uint8_t>(d["stock redeal"].GetBool());
+ } else {
+ json_helper::json_parse_err("[stock redeal] must be a boolean");
+ }
+ }
+
if (d.HasMember("reserve size")) {
if (d["reserve size"].IsInt()) {
sr.reserve_size = static_cast<uint8_t>(d["reserve size"].GetInt());
@@ -295,7 +313,7 @@ string rules_parser::rules_schema_json() {
"type": "object", "properties": {
"count": {"type": "integer", "minimum": 0},
"build policy": {"type": "string", "enum": ["any-suit", "red-black", "same-suit", "no-build"]},
- "spaces policy": {"type": "string", "enum": ["any", "no-build"]},
+ "spaces policy": {"type": "string", "enum": ["any", "no-build", "kings"]},
"diagonal deal": {"type": "boolean"},
"move built group": {"type": "boolean"},
"move built group policy": {"type": "string", "enum": ["same-as-build", "any-suit", "red-black", "same-suit", "no-build"]}
@@ -311,6 +329,8 @@ string rules_parser::rules_schema_json() {
"cells": {"type": "integer", "minimum": 0},
"stock size": {"type": "integer", "minimum": 0},
"stock deal type": {"type": "string", "enum": ["waste", "tableau piles"]},
+ "stock deal count": {"type": "integer", "minimum": 1},
+ "stock redeal": {"type": "boolean"},
"reserve size": {"type": "integer", "minimum": 0},
"reserve stacked": {"type": "boolean"}
diff --git a/src/main/input-output/input/sol_preset_types.cpp b/src/main/input-output/input/sol_preset_types.cpp
index 7519243..406be94 100644
--- a/src/main/input-output/input/sol_preset_types.cpp
+++ b/src/main/input-output/input/sol_preset_types.cpp
@@ -2,6 +2,7 @@
// Created by thecharlesblake on 11/14/17.
//
+#include <iostream>
#include "sol_preset_types.h"
using namespace std;
@@ -13,7 +14,7 @@ bool sol_preset_types::is_valid_preset(const string& s) {
return mp.count(s) > 0;
}
-std::map<string, string> sol_preset_types::mp = {
+map<string, string> sol_preset_types::mp = {
{
"default",
@@ -37,6 +38,8 @@ std::map<string, string> sol_preset_types::mp = {
"cells": 0,
"stock size": 0,
"stock deal type": "waste",
+ "stock deal count": 1,
+ "stock redeal": false,
"reserve size": 0,
"reserve stacked": false
}
@@ -351,5 +354,575 @@ std::map<string, string> sol_preset_types::mp = {
}
)"
+ },
+
+ // --- END OF 'CANONICAL' GAMES ---
+
+ {
+ "raglan",
+
+ R"(
+{
+ "tableau piles": {
+ "count": 9,
+ "build policy": "red-black",
+ "diagonal deal": true
+ },
+ "reserve size": 6,
+ "foundations removable": true,
+ "foundations initial card": true
+}
+)"
+
+ },
+
+ {
+ "klondike",
+
+ R"(
+{
+ "tableau piles": {
+ "count": 7,
+ "build policy": "red-black",
+ "spaces policy": "kings",
+ "diagonal deal": true
+ },
+ "stock size": 24,
+ "stock deal count": 1,
+ "stock redeal": false
+}
+)"
+
+ },
+
+ {
+ "klondike-built-group",
+
+ R"(
+{
+ "tableau piles": {
+ "count": 7,
+ "build policy": "red-black",
+ "spaces policy": "kings",
+ "move built group": true,
+ "diagonal deal": true
+ },
+ "stock size": 24,
+ "stock deal count": 1,
+ "stock redeal": false
+}
+)"
+
+ },
+
+ {
+ "klondike-deal-3",
+
+ R"(
+{
+ "tableau piles": {
+ "count": 7,
+ "build policy": "red-black",
+ "spaces policy": "kings",
+ "diagonal deal": true
+ },
+ "stock size": 24,
+ "stock deal count": 3,
+ "stock redeal": true
+}
+)"
+
+ },
+
+ {
+ "klondike-deal-3-built-group",
+
+ R"(
+{
+ "tableau piles": {
+ "count": 7,
+ "build policy": "red-black",
+ "spaces policy": "kings",
+ "move built group": true,
+ "diagonal deal": true
+ },
+ "stock size": 24,
+ "stock deal count": 3,
+ "stock redeal": true
+}
+)"
+
+ },
+ {
+ "alina",
+
+ R"(
+{
+ "tableau piles": {
+ "count": 13,
+ "build policy": "any-suit",
+ "spaces policy": "no-build"
+ },
+ "foundations removable": true,
+ "cells": 1
+}
+)"
+
+ },
+ {
+ "castles-of-spain",
+
+ R"(
+{
+ "tableau piles": {
+ "count": 13,
+ "build policy": "red-black"
+ },
+ "foundations removable": true
+}
+)"
+
+ },
+ {
+ "delta-star",
+
+ R"(
+{
+ "tableau piles": {
+ "count": 12,
+ "build policy": "same-suit"
+ },
+ "foundations initial card": true
+}
+)"
+
+ },
+ {
+ "martha",
+
+ R"(
+{
+ "tableau piles": {
+ "count": 12,
+ "build policy": "red-black"
+ },
+ "foundations removable": true,
+ "foundations initial card": true
+}
+)"
+
+ },
+ {
+ "one-cell",
+
+ R"(
+{
+ "tableau piles": {
+ "count": 13,
+ "build policy": "red-black"
+ },
+ "foundations removable": true,
+ "foundations initial card": true,
+ "cells": 1
+}
+)"
+
+ },
+ {
+ "two-cell",
+
+ R"(
+{
+ "tableau piles": {
+ "count": 13,
+ "build policy": "red-black"
+ },
+ "foundations removable": true,
+ "foundations initial card": true,
+ "cells": 2
+}
+)"
+
+ },
+ {
+ "free-cell-3-cell",
+
+ R"(
+{
+ "tableau piles": {
+ "build policy": "red-black"
+ },
+ "cells": 3
+}
+)"
+
+ },
+ {
+ "free-cell-2-cell",
+
+ R"(
+{
+ "tableau piles": {
+ "build policy": "red-black"
+ },
+ "cells": 2
+}
+)"
+
+ },
+ {
+ "free-cell-1-cell",
+
+ R"(
+{
+ "tableau piles": {
+ "build policy": "red-black"
+ },
+ "cells": 1
+}
+)"
+
+ },
+ {
+ "free-cell-0-cell",
+
+ R"(
+{
+ "tableau piles": {
+ "build policy": "red-black"
+ },
+ "cells": 1
+}
+)"
+
+ },
+ {
+ "free-cell-7-pile",
+
+ R"(
+{
+ "tableau piles": {
+ "count": 7,
+ "build policy": "red-black"
+ },
+ "cells": 4
+}
+)"
+
+ },
+ {
+ "free-cell-6-pile",
+
+ R"(
+{
+ "tableau piles": {
+ "count": 6,
+ "build policy": "red-black"
+ },
+ "cells": 4
+}
+)"
+
+ },
+ {
+ "free-cell-5-pile",
+
+ R"(
+{
+ "tableau piles": {
+ "count": 5,
+ "build policy": "red-black"
+ },
+ "cells": 4
+}
+)"
+
+ },
+ {
+ "bakers-game",
+
+ R"(
+{
+ "tableau piles": {
+ "build policy": "same-suit",
+ "move built group": true,
+ "spaces policy": "kings"
+ },
+ "cells": 4
+}
+)"
+
+ },
+ {
+ "eight-off",
+
+ R"(
+{
+ "tableau piles": {
+ "build policy": "same-suit"
+ },
+ "cells": 8
+}
+)"
+
+ },
+ {
+ "fore-cell",
+
+ R"(
+{
+ "tableau piles": {
+ "build policy": "red-black",
+ "spaces policy": "kings"
+ },
+ "cells": 4
+}
+)"
+
+ },
+ {
+ "penguin",
+ R"(
+
+{
+ "tableau piles": {
+ "count": 7,
+ "build policy": "same-suit",
+ "move built group": true,
+ "spaces policy": "kings"
+ },
+ "cells": 7,
+ "foundations initial card": true
+}
+)"
+
+ },
+ {
+ "sea-towers",
+ R"(
+
+{
+ "tableau piles": {
+ "count": 10,
+ "build policy": "same-suit",
+ "move built group": true,
+ "spaces policy": "kings"
+ },
+ "cells": 4,
+}
+)"
+
+ },
+ {
+ "duchess",
+ R"(
+
+{
+ "tableau piles": {
+ "count": 4,
+ "build policy": "red-black",
+ "move built group": true
+ },
+ "reserve size": 12,
+ "foundations initial card": true,
+ "stock size": 36
+}
+)"
+
+ },
+ {
+ "chamelion",
+ R"(
+
+{
+ "tableau piles": {
+ "count": 3,
+ "build policy": "any-suit",
+ "move built group": true
+ },
+ "reserve size": 13,
+ "reserve stacked": true,
+ "stock size": 36
+}
+)"
+
+ },
+ {
+ "fan",
+ R"(
+
+{
+ "tableau piles": {
+ "count": 18,
+ "build policy": "same-suit",
+ "spaces policy": "kings"
+ },
+ "foundations removable": true
+}
+)"
+
+ },
+ {
+ "scotch-patience",
+ R"(
+
+{
+ "tableau piles": {
+ "count": 18,
+ "build policy": "red-black",
+ "spaces policy": "no-build"
+ },
+ "foundations removable": true
+}
+)"
+
+ },
+ {
+ "blind-alleys",
+ R"(
+
+{
+ "tableau piles": {
+ "count": 6,
+ "build policy": "red-black",
+ "move built group": true
+ },
+ "stock size": 30,
+ "foundations initial card": true,
+ "foundations removable": true
+}
+)"
+
+ },
+ {
+ "east-haven",
+ R"(
+
+{
+ "tableau piles": {
+ "count": 7,
+ "build policy": "red-black",
+ "move built group": true
+ },
+ "foundations removable": true,
+ "stock size": 31,
+ "stock deal type": "tableau piles"
+}
+)"
+
+ },
+ {
+ "northwest-territory",
+ R"(
+
+{
+ "tableau piles": {
+ "build policy": "red-black",
+ "move built group": true,
+ "spaces policy": "kings",
+ "diagonal deal": true
+ },
+ "foundations removable": true,
+ "reserve size": 16
+}
+)"
+
+ },
+ {
+ "king-albert",
+ R"(
+
+{
+ "tableau piles": {
+ "count": 9,
+ "build policy": "red-black",
+ "diagonal deal": true
+ },
+ "foundations removable": true,
+ "reserve size": 7
+}
+)"
+
+ },
+ {
+ "king-albert-kings-in-spaces",
+ R"(
+
+{
+ "tableau piles": {
+ "count": 9,
+ "build policy": "red-black",
+ "spaces policy": "kings",
+ "diagonal deal": true
+ },
+ "foundations removable": true,
+ "reserve size": 7
+}
+)"
+
+ },
+ {
+ "spiderette",
+
+ R"(
+{
+ "tableau piles": {
+ "count": 7,
+ "build policy": "any-suit",
+ "move built group": true,
+ "move built group policy": "same-suit",
+ "diagonal deal": true
+ },
+ "foundations complete piles": true,
+ "stock size": 24,
+ "stock deal type": "tableau piles"
+}
+)"
+
+ },
+ {
+ "will-o-the-wisp",
+
+ R"(
+{
+ "tableau piles": {
+ "count": 7,
+ "build policy": "any-suit",
+ "move built group": true,
+ "move built group policy": "same-suit"
+ },
+ "foundations complete piles": true,
+ "stock size": 31,
+ "stock deal type": "tableau piles"
+}
+)"
+
+ }
+};
+
+void sol_preset_types::print_available_games() {
+ cout << "The following game types can be supplied to solvitaire using the "
+ "'--type [name of game]' option:\n\n";
+ for (auto const& x : mp) {
+ cout << x.first << "\n";
+ }
+ cout << "\nUse the '--describe-game-rules [name of game]' option for an "
+ "overview of the rules of each game:\n";
+}
+
+void sol_preset_types::describe_game_rules(string game) {
+ auto rules_it = mp.find(game);
+ if (rules_it == end(mp)) {
+ cout << "'" << game << "' is not a valid game type. "
+ "Enter '--available-game-types' for a "
+ "list of the games presets that can be solved\n";
+ } else {
+ cout << "The rules of '" << game << "' are as follows:"
+ << rules_it->second;
+
+ if (game != "default") {
+ cout << "\nTo see the default values of the JSON fields not covered "
+ "here, enter '--describe-game-rules default'\n";
}
-}; \ No newline at end of file
+ }
+}
diff --git a/src/main/input-output/input/sol_preset_types.h b/src/main/input-output/input/sol_preset_types.h
index 02f602d..c5b27d3 100644
--- a/src/main/input-output/input/sol_preset_types.h
+++ b/src/main/input-output/input/sol_preset_types.h
@@ -12,6 +12,9 @@ class sol_preset_types {
public:
static std::string get(const std::string& s);
static bool is_valid_preset(const std::string& s);
+ static void print_available_games();
+ static void describe_game_rules(std::string);
+
private:
static std::map<std::string, std::string> mp;
};
diff --git a/src/main/main.cpp b/src/main/main.cpp
index a1d1037..16a5ba1 100644
--- a/src/main/main.cpp
+++ b/src/main/main.cpp
@@ -4,6 +4,7 @@
#include <gperftools/profiler.h>
#include "input-output/input/command_line_helper.h"
+#include "input-output/input/sol_preset_types.h"
#include "input-output/input/json-parsing/json_helper.h"
#include "input-output/input/json-parsing/rules_parser.h"
#include "input-output/output/log_helper.h"
@@ -30,6 +31,17 @@ int main(int argc, const char* argv[]) {
return EXIT_FAILURE;
}
+ // If the user has asked for the list of preset game types, prints it
+ if (clh.get_available_game_types()) {
+ sol_preset_types::print_available_games();
+ return EXIT_SUCCESS;
+ }
+ string game_rule_str = clh.get_describe_game_rules();
+ if (!game_rule_str.empty()) {
+ sol_preset_types::describe_game_rules(game_rule_str);
+ return EXIT_SUCCESS;
+ }
+
// Generates the rules of the solitaire from the game type
const optional<sol_rules> rules = gen_rules(clh);
if (!rules) return EXIT_FAILURE;
diff --git a/src/main/solvability/solvability_calc.cpp b/src/main/solvability/solvability_calc.cpp
index 2f90710..dbfb3a4 100644
--- a/src/main/solvability/solvability_calc.cpp
+++ b/src/main/solvability/solvability_calc.cpp
@@ -81,7 +81,7 @@ void solvability_calc::print_end_re_eval_msg() const {
/////////////////////
void solvability_calc::calculate_solvability_percentage() {
- int current_seed = 0;
+ int current_seed = 10; // TODO:change
millisec timeout(10);
inc_t_coeffs coeffs(0.4, 0.0, 1.0);
diff --git a/src/test/unit_tests/legal_move_gen_test.cpp b/src/test/unit_tests/legal_move_gen_test.cpp
index 23955c2..4f4b7ef 100644
--- a/src/test/unit_tests/legal_move_gen_test.cpp
+++ b/src/test/unit_tests/legal_move_gen_test.cpp
@@ -124,6 +124,25 @@ TEST(LegalMoveGen, SpacesPolAny) {
ASSERT_TRUE(moves_eq(exp_moves, actual_moves)) << actual_moves;
}
+TEST(LegalMoveGen, SpacesPolKings) {
+ sol_rules sr;
+ sr.spaces_pol = s_pol::KINGS;
+ sr.tableau_pile_count = 3;
+
+ game_state gs(sr, initializer_list<pile>{
+ {},
+ {"AC"},
+ {"KD"}
+ });
+ vector<mv> actual_moves = gs.get_legal_moves();
+
+ vector<mv> exp_moves = {
+ mv(2, 0)
+ };
+
+ ASSERT_TRUE(moves_eq(exp_moves, actual_moves)) << actual_moves;
+}
+
TEST(LegalMoveGen, SpacesPolNoBuild) {
sol_rules sr;
sr.spaces_pol = s_pol::NO_BUILD;