aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/api.cpp30
-rw-r--r--src/main/api.h16
-rw-r--r--src/main/game/search-state/game_state.cpp30
-rw-r--r--src/main/game/search-state/game_state.h4
-rw-r--r--src/main/solver/solver.cpp2
5 files changed, 74 insertions, 8 deletions
diff --git a/src/main/api.cpp b/src/main/api.cpp
index fc3da3a..1709a49 100644
--- a/src/main/api.cpp
+++ b/src/main/api.cpp
@@ -1,14 +1,21 @@
#include <cstdint>
+
#include <vector>
#include <string>
+#include <stdio.h>
+
#include "game/move.h"
#include "game/search-state/game_state.h"
#include "solver/solver.h"
-bool get_moves(std::vector<move>& moves, game_state& gs,
+enum finished_state {
+ SOLUTION_FOUND, NO_SOLUTION, TIMEOUT, SOLVER_OOM, CANCELLED
+};
+
+finished_state get_moves(std::vector<move>& moves, game_state& gs,
uint64_t cache_capacity, uint64_t timeout);
-bool get_moves(std::vector<move>& moves, game_state& gs,
+finished_state get_moves(std::vector<move>& moves, game_state& gs,
uint64_t cache_capacity, uint64_t timeout) {
moves.clear();
@@ -19,8 +26,21 @@ bool get_moves(std::vector<move>& moves, game_state& gs,
for (auto &it : nodes) {
moves.push_back(it.mv);
}
- return true;
- } else {
- return false;
+ }
+
+ switch (res.sol_type) {
+ case solver::result::type::SOLVED:
+ return SOLUTION_FOUND;
+ case solver::result::type::UNSOLVABLE:
+ return NO_SOLUTION;
+ case solver::result::type::TIMEOUT:
+ return TIMEOUT;
+ case solver::result::type::MEM_LIMIT:
+ return SOLVER_OOM;
+ case solver::result::type::TERMINATED:
+ return CANCELLED;
+ default:
+ assert(false);
+ return NO_SOLUTION;
}
}
diff --git a/src/main/api.h b/src/main/api.h
index 86e3441..e454816 100644
--- a/src/main/api.h
+++ b/src/main/api.h
@@ -5,6 +5,7 @@
#include "game/move.h"
#include "game/sol_rules.h"
+#include "game/card.h"
// just for now, until I construct my own rules stuff:
#include "input-output/input/json-parsing/rules_parser.h"
@@ -12,9 +13,20 @@
typedef std::vector<std::vector<std::string>> piles;
typedef std::vector<move> movelist;
+enum finished_state {
+ SOLUTION_FOUND, NO_SOLUTION, TIMEOUT, SOLVER_OOM, CANCELLED
+};
+
class game_state {
public:
game_state(const sol_rules&, piles);
+ game_state(const sol_rules&,
+ std::vector<std::vector<card::suit_t>>,
+ std::vector<std::vector<card::rank_t>>,
+ std::vector<std::vector<bool>>);
+
+ bool is_solved() const;
+
enum class streamliner_options {NONE, AUTO_FOUNDATIONS, SUIT_SYMMETRY, BOTH};
void make_move(move);
@@ -62,5 +74,5 @@ class game_state {
*
* Returns true if a solution was found; false otherwise.
*/
-bool get_moves(movelist& moves, game_state& gs, uint64_t cache_capacity,
- uint64_t timeout);
+finished_state get_moves(movelist& moves, game_state& gs,
+ uint64_t cache_capacity, uint64_t timeout);
diff --git a/src/main/game/search-state/game_state.cpp b/src/main/game/search-state/game_state.cpp
index a547f7e..6ea550c 100644
--- a/src/main/game/search-state/game_state.cpp
+++ b/src/main/game/search-state/game_state.cpp
@@ -306,6 +306,36 @@ game_state::game_state(const sol_rules& s_rules,
}
}
+game_state::game_state(const sol_rules& s_rules,
+ std::vector<std::vector<card::suit_t>> suits,
+ std::vector<std::vector<card::rank_t>> ranks,
+ std::vector<std::vector<bool>> face_down)
+ : game_state(s_rules, sos::NONE) {pile::ref pr = 0;
+ assert(suits.size() == ranks.size());
+ assert(ranks.size() == face_down.size());
+ for (std::vector<std::vector<card::suit_t>>::size_type i = 0;
+ i < suits.size(); ++i) {
+ assert(suits[i].size() == ranks[i].size());
+ assert(ranks[i].size() == face_down[i].size());
+ for (std::vector<card::suit_t>::size_type j = 0; j < suits[i].size();
+ ++j) {
+ card c(suits[i][j], ranks[i][j], face_down[i][j]);
+ place_card(pr, c);
+ }
+ pr++;
+ }
+
+ // Sets foundations base appropriately
+ if (rules.foundations_present && rules.foundations_base == boost::none) {
+ for (auto f : foundations) {
+ if (!piles[f].empty()) {
+ foundations_base = piles[f].top_card().get_rank();
+ return;
+ }
+ }
+ }
+}
+
// Generates a randomly ordered vector of cards
vector<card> game_state::gen_shuffled_deck(card::rank_t max_rank,
bool two_decks, mt19937 rng) {
diff --git a/src/main/game/search-state/game_state.h b/src/main/game/search-state/game_state.h
index 9f8e3b9..1698122 100644
--- a/src/main/game/search-state/game_state.h
+++ b/src/main/game/search-state/game_state.h
@@ -41,6 +41,10 @@ public:
game_state(const sol_rules&, std::initializer_list<std::initializer_list<std::string>>);
// Does the same but with vectors
game_state(const sol_rules&, std::vector<std::vector<std::string>>);
+ // Does the same but with lots of vectors
+ game_state(const sol_rules&, std::vector<std::vector<card::suit_t>>,
+ std::vector<std::vector<card::rank_t>>,
+ std::vector<std::vector<bool>>);
/* Altering state */
diff --git a/src/main/solver/solver.cpp b/src/main/solver/solver.cpp
index c4e8c84..e10396f 100644
--- a/src/main/solver/solver.cpp
+++ b/src/main/solver/solver.cpp
@@ -61,7 +61,7 @@ solver::node::node(const move m)
solver::result solver::run(boost::optional<millisec> timeout) {
// Set interrupt handler
- signal(SIGINT, sigint_handler);
+ /* signal(SIGINT, sigint_handler); */
// Set timings
const clock::time_point start_time = clock::now();