aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt13
-rw-r--r--src/main/game/global_cache.cpp18
-rw-r--r--src/main/main.cpp38
3 files changed, 37 insertions, 32 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0dace0a..ff12767 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -133,21 +133,16 @@ endif()
add_executable(solvitaire ${main} ${sources})
target_link_libraries(solvitaire LINK_PUBLIC ${Boost_LIBRARIES} -lprofiler)
-# add a separete executable for the 'no card symmetry' version of the solver
-add_executable(solvitaire-no-card-symmetry ${main} ${sources})
-target_link_libraries(solvitaire-no-card-symmetry LINK_PUBLIC ${Boost_LIBRARIES} -lprofiler)
-set_target_properties(solvitaire-no-card-symmetry PROPERTIES COMPILE_FLAGS -DNO_CARD_SYMMETRY)
+# add a separete executable for the 'suit reduction streamliner' version of the solver
+add_executable(solvitaire-suit-reduction-streamliner ${main} ${sources})
+target_link_libraries(solvitaire-suit-reduction-streamliner LINK_PUBLIC ${Boost_LIBRARIES} -lprofiler)
+set_target_properties(solvitaire-suit-reduction-streamliner PROPERTIES COMPILE_FLAGS -DSUIT_REDUCTION_STREAMLINER)
# add a separete executable for the 'no pile symmetry' version of the solver
add_executable(solvitaire-no-pile-symmetry ${main} ${sources})
target_link_libraries(solvitaire-no-pile-symmetry LINK_PUBLIC ${Boost_LIBRARIES} -lprofiler)
set_target_properties(solvitaire-no-pile-symmetry PROPERTIES COMPILE_FLAGS -DNO_PILE_SYMMETRY)
-# add a separete executable for the 'no symmetry' version of the solver
-add_executable(solvitaire-no-symmetry ${main} ${sources})
-target_link_libraries(solvitaire-no-symmetry LINK_PUBLIC ${Boost_LIBRARIES} -lprofiler)
-set_target_properties(solvitaire-no-symmetry PROPERTIES COMPILE_FLAGS "-DNO_CARD_SYMMETRY -DNO_PILE_SYMMETRY")
-
# add a separete executable for the 'no reduced state' version of the solver
add_executable(solvitaire-no-reduced-state ${main} ${sources})
target_link_libraries(solvitaire-no-reduced-state LINK_PUBLIC ${Boost_LIBRARIES} -lprofiler)
diff --git a/src/main/game/global_cache.cpp b/src/main/game/global_cache.cpp
index 5d2fd79..4811853 100644
--- a/src/main/game/global_cache.cpp
+++ b/src/main/game/global_cache.cpp
@@ -82,13 +82,9 @@ void cached_game_state::add_card(card c, const game_state& gs) {
#else
auto& target = data;
#endif
-
+
switch (gs.rules.build_pol) {
-#ifdef NO_CARD_SYMMETRY
- default:
- target.emplace_back(c);
- break;
-#else
+#ifdef SUIT_REDUCTION_STREAMLINER
case pol::SAME_SUIT:
target.emplace_back(c);
break;
@@ -98,6 +94,10 @@ void cached_game_state::add_card(card c, const game_state& gs) {
default:
target.emplace_back(0, c.get_rank());
break;
+#else
+ default:
+ target.emplace_back(c);
+ break;
#endif
}
}
@@ -152,9 +152,7 @@ std::size_t hasher::combine(std::size_t& seed, std::size_t value) const {
size_t hasher::hash_value(card const& c) const {
boost::hash<uint8_t> boost_hasher;
-#ifdef NO_CARD_SYMMETRY
- uint8_t suit_val = c.get_suit();
-#else
+#ifdef SUIT_REDUCTION_STREAMLINER
uint8_t suit_val;
switch (init_gs.rules.build_pol) {
case pol::SAME_SUIT:
@@ -166,6 +164,8 @@ size_t hasher::hash_value(card const& c) const {
default:
suit_val = 0;
}
+#else
+ uint8_t suit_val = c.get_suit();
#endif
auto raw_val = static_cast<uint8_t>(suit_val * 13 + c.get_rank());
diff --git a/src/main/main.cpp b/src/main/main.cpp
index 975e6c8..be03e02 100644
--- a/src/main/main.cpp
+++ b/src/main/main.cpp
@@ -18,9 +18,9 @@ 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&);
-void solve_input_files(vector<string>, const sol_rules&);
-void solve_game(const game_state&);
+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);
int main(int argc, const char* argv[]) {
@@ -40,11 +40,11 @@ int main(int argc, const char* argv[]) {
// If there are no input files, solve a random deal based on the
// supplied seed
if (input_files.empty()) {
- solve_random_game(clh.get_random_deal(), *rules);
+ solve_random_game(clh.get_random_deal(), *rules, clh.get_classify());
}
// Otherwise, solve the input files
else {
- solve_input_files(input_files, *rules);
+ solve_input_files(input_files, *rules, clh.get_classify());
}
return EXIT_SUCCESS;
@@ -65,13 +65,14 @@ const optional<sol_rules> gen_rules(command_line_helper& clh) {
}
}
-void solve_random_game(int seed, const sol_rules& rules) {
+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);
+ solve_game(gs, classify);
}
-void solve_input_files(const vector<string> input_files, const sol_rules& rules) {
+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
@@ -81,7 +82,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);
+ solve_game(gs, classify);
} catch (const runtime_error& error) {
string errmsg = "Error parsing deal file: ";
@@ -91,15 +92,24 @@ void solve_input_files(const vector<string> input_files, const sol_rules& rules)
}
}
-void solve_game(const game_state& gs) {
+void solve_game(const game_state& gs, bool classify) {
solver solv(gs);
bool solution = solv.run();
ProfilerStop();
- if (solution) {
- solv.print_solution();
+ if (classify) {
+ if (solution) {
+ cout << "Solved\n";
+ } else {
+ cout << "No solution\n";
+ }
} else {
- cout << "Deal:\n" << gs << "\nNo Possible Solution\nStates Searched: "
- << solv.get_states_searched() << "\n";
+ if (solution) {
+ solv.print_solution();
+ } else {
+ cout << "Deal:\n" << gs
+ << "\nNo Possible Solution\nStates Searched: "
+ << solv.get_states_searched() << "\n";
+ }
}
}