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: keys for 62 rooms

Mason36334252950c4d9
diff --git a/games/leveldevil/tests/play.c b/games/leveldevil/tests/play.c
index 1d98bb75..136726c5 100644
--- a/games/leveldevil/tests/play.c
+++ b/games/leveldevil/tests/play.c
@@ -75,12 +75,14 @@ static int keys_of(char c) {
}
/* plays keys ("R30 RJ12 N8"); 1 the door reached, 0 dead, -1 neither */
+static int exact; /* (no waiting after the last keys) */
static int play(const char *s, const char *film, int trace) {
int t = 0;
char path[256];
for (;;) {
while (*s == ' ') s++;
int in = 0, n = 300; /* (after the last keys, nothing for a while) */
+ if (!*s && exact) return -1;
for (; *s >= 'A' && *s <= 'Z'; s++) in |= keys_of(*s);
if (*s) {
char *e;
@@ -161,6 +163,7 @@ static int by_score(const void *a, const void *b) {
#define BEAM 1000
#define DEPTH 900
#define CELL_MAX 4
+static const char *prefix; /* keys played before the search */
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),
@@ -170,6 +173,7 @@ static int search(int i, int nmoves, const uint8_t *moves, int chunk, char *out,
uint16_t *cellv = malloc(2 * BEAM * 9);
int ncur = 1, found = 0;
setup(i);
+ if (prefix) exact = 1, play(prefix, 0, 0), exact = 0;
take(cur);
for (int d = 0; d < depth_max && d < DEPTH && !found; d++) {
int nn = 0;
@@ -180,8 +184,8 @@ static int search(int i, int nmoves, const uint8_t *moves, int chunk, char *out,
if (dead) continue;
memcpy(npath + (size_t)nn * DEPTH, path + (size_t)c * DEPTH, (size_t)d);
npath[(size_t)nn * DEPTH + d] = (uint8_t)m;
- if (won) { /* the keys */
- char *o = out;
+ if (won || (have_goal && score() < 6 && (ground || frozen))) { /* the keys (to the door, or the waypoint) */
+ char *o = out + sprintf(out, "%s%s", prefix ? prefix : "", prefix ? " " : "");
const uint8_t *p = npath + (size_t)nn * DEPTH;
for (int a = 0; a <= d;) {
int b = a;
@@ -198,12 +202,14 @@ static int search(int i, int nmoves, const uint8_t *moves, int chunk, char *out,
take(nxt + sz * nn);
uint64_t key = (uint64_t)(hx >> 9) * 1000003u ^ (uint64_t)(hy >> 9) * 9176u ^ (uint64_t)((vx >> 6) + 512) * 131u ^
(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];
+ for (int e = 0; e < EVENTS; e++) /* (and how long ago each event went off) */
+ key = key * 31 + cnt[e] + (cnt[e] ? (uint64_t)imin((uint16_t)(frame - at_[e]), 600) / 8 * 7 : 0);
+ key = key * 31 + (uint64_t)frozen + (uint64_t)born * 64;
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;
+ 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) ^ ev * 40503u ^ (uint32_t)(frozen >> 2) << 15) * 2654435761u;
cellv[nn] = (uint16_t)(cell >> 16);
sc[nn] = score() * 4;
ord[nn] = nn;
@@ -231,7 +237,14 @@ static int search(int i, int nmoves, const uint8_t *moves, int chunk, char *out,
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]]);
+ if (getenv("PLAY_DEBUG")) {
+ fprintf(stderr, "depth %d: %d states, %d kept:", d, nn, ncur);
+ for (int c = 0; c < ncur; c++) {
+ give(cur + sz * c);
+ if (cnt[1]) fprintf(stderr, " %d,%d%s%d", (int)(hx >> 8), (int)(hy >> 8), frozen ? "f" : "", frozen);
+ }
+ fprintf(stderr, "\n");
+ }
}
free(cur), free(nxt), free(path), free(npath), free(sc), free(ord), free(keyv), free(cellv);
return found;
@@ -249,6 +262,7 @@ int main(int argc, char **argv) {
I_LEFT | I_DOWN};
int n = argc > 4 && strchr(argv[4], 'D') ? 9 : 6, chunk = argc > 5 ? atoi(argv[5]) : 4;
if (argc > 6) have_goal = sscanf(argv[6], "%d,%d", &goal_x, &goal_y) == 2;
+ if (argc > 7) prefix = argv[7];
if (search(i, n, moves, chunk, out, 900)) {
printf("%d-%d: %s\n", i / ROOMS + 1, i % ROOMS + 1, out);
return 0;
diff --git a/games/leveldevil/tests/solutions.txt b/games/leveldevil/tests/solutions.txt
index 28a59821..e04794d3 100644
--- a/games/leveldevil/tests/solutions.txt
+++ b/games/leveldevil/tests/solutions.txt
@@ -37,8 +37,8 @@
7-5: R56 RJ4 R120 N8 R84
8-1: R180 RJ4 R4 L8 N8 L8 N12 L4 N4 R52 L8 N4 R4
8-2: R68 N8 L4 R56 RJ4 R48 N4 R4 J4 N4 R4 N32 R4 RJ4 R12 N4 R4 N8 L12 R48 N12 L4 N8 R12
-8-3:
-8-4:
+8-3: N20 R60 RJ8 R12 L4 LJ4 L40 N4 L48 LJ4 L16 N4 L4 N4 L4 R48 RJ4 R4 N4 R4 N4 L4 R4 N8 L4 N4 R48 N20 L4 N12 R8
+8-4: R300 N4 R84 N4 R76 R56 N4 J4 N64 R4 R8 L8 N12 J4 L12 N4 L4 R124
8-5: R20 RJ4 R20 L4 R64 L8 N8 L4 R4 L4 N24 R4 L4 R92 L4 N4 L4 R44 N4 R8 L4 R4
9-1: R16 N4 L16 R80 RJ4 R200
9-2:
@@ -77,6 +77,6 @@
15-5:
16-1:
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-3: N892 J4 N16 R8 J4 N4 R12 L4 R4 N12 LJ4 R12 N48 R4 RJ4 R4 N228 R4 N28 J4 R28 L8 R4 N4 R4 L4 N4 R68 RJ4 R12 N4 J4 N4 R556 RJ4 R88 L4 N4 R268
16-4:
16-5: