aboutsummaryrefslogtreecommitdiff
path: root/src/solve/main.c
blob: b8b966fb46bd52e29f5dd0f34710e6706cb908a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <string.h> // atoi()
#include <stdlib.h> // EXIT_{FAILURE,SUCCESS}
#include <stdio.h>
#include "../core/sok.h"
#include "../text/util.h"
#include "../levels/levels.h"

static void
solve_on_error(
  const char * const err,
  void *user_data
) {
  UNUSED(user_data);
  die("Error solving level: %s", err);
}

static const sok_solve_cbs_t
SOLVE_CBS = {
  .on_error = solve_on_error,
};

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 %d", (int) level_num);
    }

    // solve level
    if (!sok_solve(&ctx, &SOLVE_CBS, NULL)) {
      die("Couldn't solve level: %d", (int) level_num);
    }
  }

  // return success
  return EXIT_SUCCESS;
}