aboutsummaryrefslogtreecommitdiff
path: root/src/libsok/sok-solve.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libsok/sok-solve.c')
-rw-r--r--src/libsok/sok-solve.c50
1 files changed, 27 insertions, 23 deletions
diff --git a/src/libsok/sok-solve.c b/src/libsok/sok-solve.c
index 6637feb..225ce9b 100644
--- a/src/libsok/sok-solve.c
+++ b/src/libsok/sok-solve.c
@@ -9,36 +9,40 @@ sok_solve_step(
sok_cache_t * const cache,
void (*on_error)(const char * const)
) {
+ // check for success
+ if (sok_ctx_is_done(ctx)) {
+ // return success
+ return true;
+ }
+
+ if (sok_cache_has(cache, ctx)) {
+ // return failure
+ return false;
+ }
+
+ // add to cache
+ if (!sok_cache_add(cache, ctx)) {
+ if (on_error) {
+ // log error
+ on_error("sok_cache_add() failed");
+ }
+
+ // return failure
+ return false;
+ }
+
for (size_t dir = 0; dir < SOK_DIR_LAST; dir++) {
if (!sok_ctx_move(ctx, dir)) {
continue;
}
- if (!sok_cache_has(cache, ctx)) {
- // check for success
- if (sok_ctx_is_done(ctx)) {
- // return success
- return true;
- }
-
- // add to cache
- if (!sok_cache_add(cache, ctx)) {
- if (on_error) {
- // log error
- on_error("sok_cache_add() failed");
- }
-
- // return failure
- return false;
- }
-
- // recurse, check for success
- if (sok_solve_step(ctx, cache, on_error)) {
- // return success
- return true;
- }
+ // recurse, check for success
+ if (sok_solve_step(ctx, cache, on_error)) {
+ // return success
+ return true;
}
+ // undo move
if (!sok_ctx_undo(ctx)) {
if (on_error) {
// log error