diff options
author | Paul Duncan <pabs@pablotron.org> | 2019-01-09 11:52:03 -0500 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2019-01-09 11:52:03 -0500 |
commit | 3d0b7418b2c1a87d44144749f5f055cfa0995f6c (patch) | |
tree | b7acd681e6c31c68dbcc733f6f35b1e86a8134a5 /src/test-solve | |
parent | 400e3421b123c0092988df3422f96cc210d33f7b (diff) | |
download | sok-3d0b7418b2c1a87d44144749f5f055cfa0995f6c.tar.bz2 sok-3d0b7418b2c1a87d44144749f5f055cfa0995f6c.zip |
add test-solve
Diffstat (limited to 'src/test-solve')
-rw-r--r-- | src/test-solve/main.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/test-solve/main.c b/src/test-solve/main.c new file mode 100644 index 0000000..0e6efe0 --- /dev/null +++ b/src/test-solve/main.c @@ -0,0 +1,41 @@ +#include <stdbool.h> // bool +#include <string.h> // atoi() +#include <stdlib.h> // EXIT_{FAILURE,SUCCESS} +#include <stdio.h> +#include "../libsok/sok.h" +#include "../text/util.h" +#include "../text/levels.h" + +static void +solve_on_error( + const char * const err +) { + die("Error solving level: %s", err); +} + +int main(int argc, char *argv[]) { + // init context + sok_ctx_t ctx; + sok_ctx_init(&ctx, NULL); + + // walk levels + for (int i = 1; i < argc; i++) { + const size_t level_num = atoi(argv[i]); + + // get level + const level_t *level = levels_get_level(level_num); + + // load level + if (!sok_ctx_set_level(&ctx, level->data)) { + die("Couldn't load level %zu", level_num); + } + + // solve level + if (!sok_solve(&ctx, solve_on_error)) { + die("Couldn't solve level"); + } + } + + // return success + return EXIT_SUCCESS; +} |