aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/game/card.cpp4
-rw-r--r--src/main/game/card.h2
-rw-r--r--src/main/input-output/input/command_line_helper.cpp22
-rw-r--r--src/main/input-output/input/command_line_helper.h4
-rw-r--r--src/main/main.cpp73
5 files changed, 27 insertions, 78 deletions
diff --git a/src/main/game/card.cpp b/src/main/game/card.cpp
index a19760b..cfb94a9 100644
--- a/src/main/game/card.cpp
+++ b/src/main/game/card.cpp
@@ -22,9 +22,9 @@ const card::colour_t card::colour::Red = 1;
// A card can either be created using two int values (rank & suit), or
// using a string (e.g. "AS")
-card::card(suit_t s, rank_t r) : card_suit(s), card_rank(r) {}
+card::card(suit_t s, rank_t r) : card_rank(r), card_suit(s) {}
-card::card(const char* c) : card_suit(suit_from_str(c)), card_rank(rank_from_str(c)) {}
+card::card(const char* c) : card_rank(rank_from_str(c)), card_suit(suit_from_str(c)) {}
card::card() : card(0, 0) {}
diff --git a/src/main/game/card.h b/src/main/game/card.h
index 8d88df8..a4c6b1e 100644
--- a/src/main/game/card.h
+++ b/src/main/game/card.h
@@ -45,8 +45,8 @@ private:
static suit_t suit_from_str(const char* c);
static rank_t rank_from_str(const char* c);
- suit_t card_suit : 4;
rank_t card_rank : 4;
+ suit_t card_suit : 4;
};
bool operator==(const card&, const card&);
diff --git a/src/main/input-output/input/command_line_helper.cpp b/src/main/input-output/input/command_line_helper.cpp
index 92fef21..4b0942a 100644
--- a/src/main/input-output/input/command_line_helper.cpp
+++ b/src/main/input-output/input/command_line_helper.cpp
@@ -38,8 +38,6 @@ command_line_helper::command_line_helper()
"'solvability', 'benchmark' or list of deals to be solved.")
("classify", "outputs a simple 'solvable/not solvable' "
"classification")
- ("shortest-sols", "for each instance returns the shortest possible "
- "solution. cannot be supplied alongside '--solvability'")
("solvability", "calculates the solvability "
"percentage of the supplied solitaire game. Must supply "
"either 'random', 'benchmark', 'solvability' or list of deals to be "
@@ -108,8 +106,6 @@ bool command_line_helper::parse(int argc, const char* argv[]) {
benchmark = (vm.count("benchmark") != 0);
- shortest_sols = (vm.count("shortest-sols") != 0);
-
// Handle logic error scenarios
return assess_errors();
}
@@ -141,11 +137,6 @@ bool command_line_helper::assess_errors() {
return false;
}
- if (shortest_sols && solvability) {
- print_shortest_sols_error();
- return false;
- }
-
if (!solitaire_type.empty()) {
return assess_sol_type();
} else {
@@ -188,11 +179,6 @@ void command_line_helper::print_too_many_opts_error() {
print_help();
}
-void command_line_helper::print_shortest_sols_error() {
- LOG_ERROR ("Error: User cannot supply '--shortest-sols' and '--solvability'");
- print_help();
-}
-
const vector<string> command_line_helper::get_input_files() {
return input_files;
}
@@ -209,10 +195,6 @@ int command_line_helper::get_random_deal() {
return random_deal;
}
-bool command_line_helper::get_help() {
- return help;
-}
-
bool command_line_helper::get_classify() {
return classify;
}
@@ -229,10 +211,6 @@ string command_line_helper::get_describe_game_rules() {
return describe_game_rules;
}
-bool command_line_helper::get_short_sols() {
- return shortest_sols;
-}
-
bool command_line_helper::get_benchmark() {
return benchmark;
}
diff --git a/src/main/input-output/input/command_line_helper.h b/src/main/input-output/input/command_line_helper.h
index e436f13..911cd5a 100644
--- a/src/main/input-output/input/command_line_helper.h
+++ b/src/main/input-output/input/command_line_helper.h
@@ -16,10 +16,8 @@ public:
const std::string get_solitaire_type();
const std::string get_rules_file();
int get_random_deal();
- bool get_help();
bool get_classify();
bool get_solvability();
- bool get_short_sols();
bool get_available_game_types();
bool get_benchmark();
std::string get_describe_game_rules();
@@ -31,7 +29,6 @@ private:
void print_sol_type_rules_error();
void print_no_opts_error();
void print_too_many_opts_error();
- void print_shortest_sols_error();
boost::program_options::options_description cmdline_options;
boost::program_options::options_description main_options;
@@ -45,7 +42,6 @@ private:
bool help;
bool classify;
bool solvability;
- bool shortest_sols;
bool available_game_types;
bool benchmark;
};
diff --git a/src/main/main.cpp b/src/main/main.cpp
index 6d06f5d..52c49ee 100644
--- a/src/main/main.cpp
+++ b/src/main/main.cpp
@@ -19,10 +19,11 @@ using namespace boost;
namespace po = boost::program_options;
const optional<sol_rules> gen_rules(command_line_helper&);
-void solve_random_game(int, const sol_rules&, bool, bool);
-void solve_input_files(vector<string>, const sol_rules&, bool, bool);
-void solve_game(const game_state&, bool, bool);
+void solve_random_game(int, const sol_rules&, bool);
+void solve_input_files(vector<string>, const sol_rules&, bool);
+void solve_game(const game_state&, bool);
+// Decides what to do given supplied command-line options
int main(int argc, const char* argv[]) {
// Parses the command-line options
@@ -36,6 +37,7 @@ int main(int argc, const char* argv[]) {
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);
@@ -53,8 +55,7 @@ int main(int argc, const char* argv[]) {
}
// If a random deal seed has been supplied, solves it
else if (clh.get_random_deal() != -1) {
- solve_random_game(clh.get_random_deal(), *rules, clh.get_short_sols(),
- clh.get_classify());
+ solve_random_game(clh.get_random_deal(), *rules, clh.get_classify());
}
// If the benchmark option has been supplied, generates it
else if (clh.get_benchmark()) {
@@ -67,13 +68,13 @@ int main(int argc, const char* argv[]) {
// If there are no input files, solve a random deal based on the
// supplied seed
assert (!input_files.empty());
- solve_input_files(input_files, *rules, clh.get_short_sols(),
- clh.get_classify());
+ solve_input_files(input_files, *rules, clh.get_classify());
}
return EXIT_SUCCESS;
}
+// Generates the game rules given the command line options
const optional<sol_rules> gen_rules(command_line_helper& clh) {
try {
if (!clh.get_solitaire_type().empty()) {
@@ -89,15 +90,13 @@ const optional<sol_rules> gen_rules(command_line_helper& clh) {
}
}
-void solve_random_game(int seed, const sol_rules& rules, bool short_sol,
- bool classify) {
+void solve_random_game(int seed, const sol_rules& rules, bool classify) {
LOG_INFO ("Attempting to solve with seed: " << seed << "...");
game_state gs(rules, seed);
- solve_game(gs, short_sol, classify);
+ solve_game(gs, classify);
}
-void solve_input_files(const vector<string> input_files, const sol_rules& rules,
- bool short_sol, bool classify) {
+void solve_input_files(const vector<string> input_files, const sol_rules& rules, bool classify) {
for (const string& input_file : input_files) {
try {
// Reads in the input file to a json doc
@@ -107,7 +106,7 @@ void solve_input_files(const vector<string> input_files, const sol_rules& rules,
game_state gs(rules, in_doc);
LOG_INFO ("Attempting to solve " << input_file << "...");
- solve_game(gs, short_sol, classify);
+ solve_game(gs, classify);
} catch (const runtime_error& error) {
string errmsg = "Error parsing deal file: ";
@@ -117,44 +116,20 @@ 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;
- 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);
-
- if (!solution) {
- if (!classify) cout << "Deal:\n" << gs << "\n";
- cout << "No Possible Solution\n";
- }
+void solve_game(const game_state& gs, bool classify) {
+ solver solv(gs);
- } else {
- bool solution = solv->run() == solver::sol_state::solved;
+ 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";
- }
+ 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";
- cout << "Backtracks: " << solv->get_backtrack_count() << "\n";
- cout << "Final Depth: " << solv->get_final_depth() << "\n";
+ cout << "States Searched: " << solv.get_states_searched() << "\n";
+ cout << "Backtracks: " << solv.get_backtrack_count() << "\n";
+ cout << "Final Depth: " << solv.get_final_depth() << "\n";
}