aboutsummaryrefslogtreecommitdiff
path: root/src/main/api.cpp
diff options
context:
space:
mode:
authorTom Harley2019-01-24 12:10:15 +0000
committerTom Harley2019-01-24 12:10:15 +0000
commit1ef39e9ba6ce1a622c53f38929d1e77b4f2518fc (patch)
tree7734126b8b4c2bd9f97d45137cf73c83fdf8c829 /src/main/api.cpp
parentwow a thing that works (diff)
downloadmetasol-1ef39e9ba6ce1a622c53f38929d1e77b4f2518fc.tar.gz
metasol-1ef39e9ba6ce1a622c53f38929d1e77b4f2518fc.zip

It works with fortune’s favor

It seems to be consistently running to completion successfully! It’s been renamed to metasol for now, since that’s a better name than test. Next step will probably be eliminating the namespace pollution in metasol.cpp.

Diffstat (limited to 'src/main/api.cpp')
-rw-r--r--src/main/api.cpp30
1 files changed, 25 insertions, 5 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;
}
}