aboutsummaryrefslogtreecommitdiff
path: root/src/libsok/sok-ctx.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libsok/sok-ctx.c')
-rw-r--r--src/libsok/sok-ctx.c80
1 files changed, 79 insertions, 1 deletions
diff --git a/src/libsok/sok-ctx.c b/src/libsok/sok-ctx.c
index d514fe3..26c6239 100644
--- a/src/libsok/sok-ctx.c
+++ b/src/libsok/sok-ctx.c
@@ -201,6 +201,73 @@ sok_ctx_count_goals_left(
return r;
}
+/*
+ * static bool
+ * sok_ctx_has_corner_boxes(
+ * const sok_ctx_t * const ctx
+ * ) {
+ * for (size_t i = 0; i < ctx->level.num_boxes; i++) {
+ * // right
+ * const bool r = ctx_is_wall(ctx, (sok_pos_t) {
+ * .x = ctx->boxes[i].x + 1,
+ * .y = ctx->boxes[i].y,
+ * });
+ *
+ * // top-right
+ * const bool tr = ctx_is_wall(ctx, (sok_pos_t) {
+ * .x = ctx->boxes[i].x + 1,
+ * .y = ctx->boxes[i].y - 1,
+ * });
+ *
+ * // top
+ * const bool t = ctx_is_wall(ctx, (sok_pos_t) {
+ * .x = ctx->boxes[i].x,
+ * .y = ctx->boxes[i].y - 1,
+ * });
+ *
+ * // top-left
+ * const bool tl = ctx_is_wall(ctx, (sok_pos_t) {
+ * .x = ctx->boxes[i].x - 1,
+ * .y = ctx->boxes[i].y - 1,
+ * });
+ *
+ * // left
+ * const bool l = ctx_is_wall(ctx, (sok_pos_t) {
+ * .x = ctx->boxes[i].x - 1,
+ * .y = ctx->boxes[i].y,
+ * });
+ *
+ * // bottom-left
+ * const bool bl = ctx_is_wall(ctx, (sok_pos_t) {
+ * .x = ctx->boxes[i].x - 1,
+ * .y = ctx->boxes[i].y + 1,
+ * });
+ *
+ * // bottom
+ * const bool b = ctx_is_wall(ctx, (sok_pos_t) {
+ * .x = ctx->boxes[i].x,
+ * .y = ctx->boxes[i].y + 1,
+ * });
+ *
+ * const bool br = ctx_is_wall(ctx, (sok_pos_t) {
+ * .x = ctx->boxes[i].x + 1,
+ * .y = ctx->boxes[i].y + 1,
+ * });
+ *
+ * if (
+ * (r && tr && t) || // top-right
+ * (t && tl && l) || // top-left
+ * (l && bl && b) || // bottom-left
+ * (b && br && r) // bottom-right
+ * ) {
+ * // return
+ * return true;
+ * }
+ * }
+ *
+ * return false;
+ * }
+ */
void
sok_ctx_init(sok_ctx_t * const ctx, void *user_data) {
@@ -232,8 +299,9 @@ sok_ctx_set_level(
ctx->home = ctx->level.home;
memcpy(ctx->boxes, ctx->level.boxes, ctx->level.num_boxes * sizeof(sok_pos_t));
- // count number of goals left
+ // count number of goals left and check whether there are
ctx->num_goals_left = sok_ctx_count_goals_left(ctx);
+ // ctx->is_lost = sok_ctx_is_lost(ctx);
// return success
return true;
@@ -322,6 +390,7 @@ sok_ctx_move_box(
// update box and goal count
ctx->boxes[box_ofs] = new_pos;
ctx->num_goals_left = sok_ctx_count_goals_left(ctx);
+ // ctx->is_lost = sok_ctx_has_corner_boxes(ctx);
// return success
return true;
@@ -338,6 +407,15 @@ sok_ctx_is_done(
return ctx->num_goals_left == 0;
}
+/*
+ * bool
+ * sok_ctx_is_lost(
+ * const sok_ctx_t * const ctx
+ * ) {
+ * return ctx->is_lost;
+ * }
+ */
+
bool
sok_ctx_move(
sok_ctx_t * const ctx,