aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorthecharlesblake2017-10-28 12:19:20 +0100
committerthecharlesblake2017-10-28 13:30:18 +0100
commit81fdc3f73a5d89e613c8e19f385c2144b35f6204 (patch)
tree9ef7f1243167e9a4e0f83e2fda6cfa977def8839 /src/main
parentmake boost link statically (diff)
downloadmetasol-81fdc3f73a5d89e613c8e19f385c2144b35f6204.tar.gz
metasol-81fdc3f73a5d89e613c8e19f385c2144b35f6204.zip

Add Spanish Paitence to cmd parse and refactor

Diffstat (limited to 'src/main')
-rw-r--r--src/main/command_line_helper.cpp20
-rw-r--r--src/main/command_line_helper.h4
-rw-r--r--src/main/main.cpp1
3 files changed, 15 insertions, 10 deletions
diff --git a/src/main/command_line_helper.cpp b/src/main/command_line_helper.cpp
index fdf6c9c..22678af 100644
--- a/src/main/command_line_helper.cpp
+++ b/src/main/command_line_helper.cpp
@@ -14,6 +14,9 @@ using namespace std;
namespace po = boost::program_options;
+vector<string> command_line_helper::valid_sol_types =
+ {"black-hole", "simple-black-hole", "spanish-patience"};
+
command_line_helper::command_line_helper()
: main_options("options"), random_deal(-1) {
@@ -78,12 +81,12 @@ bool command_line_helper::assess_errors() {
bool valid_sol_type = assess_sol_type();
if (!valid_sol_type) return false;
- if (random_deal >= 0 && !input_files.empty()) {
+ if (random_deal != -1 && !input_files.empty()) {
print_rand_plus_input_err();
return false;
}
- if (input_files.empty() && random_deal >= 0) {
+ if (input_files.empty() && random_deal == -1) {
print_no_input_error();
return false;
}
@@ -91,21 +94,22 @@ bool command_line_helper::assess_errors() {
}
bool command_line_helper::assess_sol_type() {
- if (solitaire_type == "black-hole") {
- return true;
- } else if (solitaire_type == "simple-black-hole") {
+ if (find(valid_sol_types.begin(), valid_sol_types.end(), solitaire_type) !=
+ valid_sol_types.end()) {
return true;
} else {
cerr << "Error: Solitaire type is not valid: " << solitaire_type
- << "\nValid solitaire types are: 'black-hole' and "
- "'simple-black-hole'";
+ << "\nValid solitaire types are: ";
+ copy(begin(valid_sol_types), end(valid_sol_types),
+ ostream_iterator<string>(cerr, ", "));
+ cerr << "\n";
print_help();
return false;
}
}
void command_line_helper::print_help() {
- cout << "Usage: solvitaire [options] input-file1 input-file2 ...\n"
+ cerr << "Usage: solvitaire [options] input-file1 input-file2 ...\n"
<< main_options << "\n";
}
diff --git a/src/main/command_line_helper.h b/src/main/command_line_helper.h
index 5694830..47eef4c 100644
--- a/src/main/command_line_helper.h
+++ b/src/main/command_line_helper.h
@@ -16,13 +16,15 @@ public:
int get_random_deal();
bool get_help();
private:
+ static std::vector<std::string> valid_sol_types;
+
bool assess_errors();
bool assess_sol_type();
void print_help();
void print_no_input_error();
void print_no_sol_type_error();
void print_rand_plus_input_err();
-
+
boost::program_options::options_description cmdline_options;
boost::program_options::options_description main_options;
boost::program_options::positional_options_description p;
diff --git a/src/main/main.cpp b/src/main/main.cpp
index cc1df9f..245b737 100644
--- a/src/main/main.cpp
+++ b/src/main/main.cpp
@@ -4,7 +4,6 @@
#include <rapidjson/document.h>
#include "command_line_helper.h"
-#include "card.h"
#include "deal_parser.h"
#include "game_state.h"
#include "solver.h"