Skip to content

Free games for graphing calculators: NumWorks, TI-Nspire CX, Casio fx-CG50 and soon TI-84 Plus CE. Balatro, Celeste, Hollow Knight, Minecraft and more.

Level Devil: fixes, and keys for 59 rooms

Mason36370dd901f691b
diff --git a/games/leveldevil/src/main.c b/games/leveldevil/src/main.c
index b49e5cf1..54659191 100644
--- a/games/leveldevil/src/main.c
+++ b/games/leveldevil/src/main.c
@@ -775,7 +775,8 @@ static void hub_scene(void *ctx) {
fg = gfx_rgb(colors[i][1]);
if (!(i & 7)) gfx_fill(0, y + 40, SCREEN_W, 8, gfx_rgb(colors[0][1]));
if (!open) fg = gfx_mix(fg, bg, 20);
- draw_door(x, y, x + 22, y + 40, sv.done >> i & 1 ? 12 : 0);
+ draw_door(x, y, x + 22, y + 40, open ? 0 : 12); /* (a world cleared: its colour in the window) */
+ if (sv.done >> i & 1) gfx_fill(x + 3, y + 3, 16, 34, gfx_rgb(colors[i][0]));
num(s, (uint32_t)i + 1);
gfx_text_center(&np_font_small, x + 11, y - 6, s, fg, 256);
if (i == sel_) picture(hero_px[0], 14, x - 22, y + 8, x - 2, y + 40, 0, 0, 0, BLACK);
diff --git a/games/leveldevil/tests/play.c b/games/leveldevil/tests/play.c
index 2484be9a..1d98bb75 100644
--- a/games/leveldevil/tests/play.c
+++ b/games/leveldevil/tests/play.c
@@ -158,14 +158,16 @@ static int by_score(const void *a, const void *b) {
return x != y ? (x > y) - (x < y) : *(const int *)a - *(const int *)b;
}
-#define BEAM 600
+#define BEAM 1000
#define DEPTH 900
+#define CELL_MAX 4
static int search(int i, int nmoves, const uint8_t *moves, int chunk, char *out, int depth_max) {
size_t sz = snap_size();
uint8_t *cur = malloc(sz * BEAM), *nxt = malloc(sz * BEAM * 9), *path = malloc((size_t)BEAM * DEPTH),
*npath = malloc((size_t)BEAM * DEPTH * 9);
int *sc = malloc(sizeof(int) * BEAM * 9), *ord = malloc(sizeof(int) * BEAM * 9);
uint64_t *keyv = malloc(8 * BEAM * 9);
+ uint16_t *cellv = malloc(2 * BEAM * 9);
int ncur = 1, found = 0;
setup(i);
take(cur);
@@ -198,30 +200,40 @@ static int search(int i, int nmoves, const uint8_t *moves, int chunk, char *out,
(uint64_t)((vy >> 6) + 512) * 7u ^ (uint64_t)ground << 40 ^ (uint64_t)(gy < 0) << 41;
for (int e = 0; e < EVENTS; e++) key = key * 31 + cnt[e];
keyv[nn] = key;
+ uint32_t ev = 0;
+ for (int e = 1; e < EVENTS; e++) ev = ev * 3 + cnt[e];
+ uint32_t cell = (uint32_t)(((hx >> 12) & 63) | ((hy >> 12) & 31) << 6 | (vx > 0 ? 1 : vx < 0 ? 2 : 0) << 11 |
+ (vy > 0 ? 1 : vy < 0 ? 2 : 0) << 13) * 2654435761u + ev * 40503u;
+ cellv[nn] = (uint16_t)(cell >> 16);
sc[nn] = score() * 4;
ord[nn] = nn;
nn++;
}
- if (found || !nn) break;
+ if (found || !nn) {
+ if (!found) fprintf(stderr, "(all dead after %d steps)\n", d * chunk);
+ break;
+ }
/* the best, one of each state */
sort_sc = sc;
qsort(ord, (size_t)nn, sizeof *ord, by_score);
ncur = 0;
static uint64_t seen[1 << 15];
- memset(seen, 0, sizeof seen);
+ static uint8_t per_cell[1 << 16];
+ memset(seen, 0, sizeof seen), memset(per_cell, 0, sizeof per_cell);
for (int a = 0; a < nn && ncur < BEAM; a++) {
int q = ord[a];
uint64_t k = keyv[q] | 1;
uint32_t h = (uint32_t)(k * 0x9E3779B97F4A7C15u >> 49);
while (seen[h] && seen[h] != k) h = (h + 1) & ((1 << 15) - 1);
- if (seen[h]) continue;
- seen[h] = k;
+ if (seen[h] || per_cell[cellv[q]] >= CELL_MAX) continue; /* (a few states a place, for variety) */
+ seen[h] = k, per_cell[cellv[q]]++;
memcpy(cur + sz * ncur, nxt + sz * q, sz);
memcpy(path + (size_t)ncur * DEPTH, npath + (size_t)q * DEPTH, (size_t)d + 1);
ncur++;
}
+ if (getenv("LD_DEBUG")) fprintf(stderr, "depth %d: %d states, %d kept, best %d\n", d, nn, ncur, sc[ord[0]]);
}
- free(cur), free(nxt), free(path), free(npath), free(sc), free(ord), free(keyv);
+ free(cur), free(nxt), free(path), free(npath), free(sc), free(ord), free(keyv), free(cellv);
return found;
}
diff --git a/games/leveldevil/tests/solutions.txt b/games/leveldevil/tests/solutions.txt
index 97e98338..28a59821 100644
--- a/games/leveldevil/tests/solutions.txt
+++ b/games/leveldevil/tests/solutions.txt
@@ -5,11 +5,11 @@
1-3: R80 RJ4 R52
1-4: R20 RJ4 R160
1-5: R176 RJ4 R52
-2-1:
+2-1: R16 N4 R8 N4 R12 N4 R4 L4 N4 L4 R4 LJ4 L60 LJ4 L56
2-2: R52 RJ4 R56 RJ4 R92 RJ4 R44
2-3: R20 RJ4 R64 RJ4 R20
2-4: R24 RJ4 R36 RJ4 R52 RJ4 R24 RJ4 R16 RJ4 R20 RJ4 R16 RJ4 R20 RJ4 R20
-2-5:
+2-5: R16 L80 R8 N8 R72 RJ4 R8 L4 N80 J4 N4 L16 J4 N16 L4 N4 L4 R4 L4 R4 L4 R4 L4 R4 L4 R4 L4 R4 L4 R4 L20 J4 N4 L4 N24 L4 R4 L4 R4 L4 R4 L4 R4 L4 R4 L4 R4 L4 R4 L4 R4 L4 R4 L4 R4 L4 R4 L4 R4 L4 R4 L4 R4 L4 R4 L4 R4 L4 R4 L8 N4 J4 N88 L4 J4 N320 L4 R4 L4 R4 L4 R4 L4 R4 L4 R4 L8 N4 J4 N4 L4 N4 L4 N20 L4 N4 L4 R4 L4 R4 L4 R4 L4 R4 L4 R4 L4 R4 L4 R4 L4 R4 L164
3-1: R80 RJ4 R28 N4 R4 N4 L4 N28 L8 RJ4 R12 L4 N4 L4 N4 RJ4 R4 N4 R76
3-2: R128 RJ4 R52
3-3: R24 RJ4 R84 L4 R4 L4 RJ4 R24
@@ -23,46 +23,46 @@
5-1: R16 L48
5-2: R36 RJ4 R56 RJ4 R44 RJ4 R44 RJ4 R56
5-3: R16 L52 LJ4 L56 LJ4 L56 LJ4 L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16-2:
+16-2: R20 RJ4 R24 RJ4 R80 N4 R4 N8 R16 LJ4 R32 RJ4 R12 L4 N8 LJ4 N4 R100 N4 R4 N8 J4 N4 R64 N8 L4 N4 R4 L4 R4 L4 R4 L4 R4 L4 R4 L8 R12 J4 N16 R4 N4 R4 N4 L8 R4 N24 R4 RJ4 R48 J4 R20
16-3:
16-4:
16-5:
diff --git a/games/leveldevil/tools/rooms.py b/games/leveldevil/tools/rooms.py
index 0107dac8..1fc57d0b 100644
--- a/games/leveldevil/tools/rooms.py
+++ b/games/leveldevil/tools/rooms.py
@@ -194,6 +194,10 @@ def run(v): # _MaximumRunningSpeed
return hero(H_RUN, v * 10)
+def jump(force): # _JumpingForce: the runner's push up (18 gives 188 pixels a second)
+ return hero(H_JUMP, force * 188 / 18)
+
+
def gravity(gx, gy):
return [Op(O_GRAV, None, round(gx * 10), round(gy * 10))]
@@ -559,7 +563,7 @@ r.on(1, show(r.all(609)))
r.on(EV_KEY, hop(r.all(609), 30))
r = room("Controls_4")
-r.init(at(100, hero(H_JUMP, 100), hero(H_MAXUP, 1000)))
+r.init(at(100, jump(100), hero(H_MAXUP, 1000)))
r = room("Controls_5")
r.init(at(50, hero(H_BACK, 1)))
@@ -829,9 +833,9 @@ walls = r.all(609) + r.all(645)
r.init(hero(H_DIR, -1), grow(r.one(600), 3, 1), grow(r.all(645), 35, 11))
r.on(1, hero(H_DIR, -1), at(1000, grow(r.one(600), 1, 1, 1)))
r.on(2, hero(H_DIR, 1),
- at(1000, run(6), hero(H_JUMP, 20), vel([w for w in walls if w.y < 120], 0, .6), vel([w for w in walls if w.y > 120], 0, -.6)),
- at(2000, run(5), hero(H_JUMP, 18)), at(3000, run(4), hero(H_JUMP, 16)), at(4000, run(3), hero(H_JUMP, 14)),
- at(5000, run(2), hero(H_JUMP, 12)), at(7000, steps([r.one(598), r.one(600)], 1, 0, 16, 10)),
+ at(1000, run(6), jump(20), vel([w for w in walls if w.y < 120], 0, .6), vel([w for w in walls if w.y > 120], 0, -.6)),
+ at(2000, run(5), jump(18)), at(3000, run(4), jump(16)), at(4000, run(3), jump(14)),
+ at(5000, run(2), jump(12)), at(7000, steps([r.one(598), r.one(600)], 1, 0, 16, 10)),
at(13000, vel(walls, 0, 0)))
r = room("Flappy_4")