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.

Deltarune: host tests

Mason363926a1000c7aa
diff --git a/games/deltarune/src/battle.c b/games/deltarune/src/battle.c
index c6707b0c..b0fd11cc 100644
--- a/games/deltarune/src/battle.c
+++ b/games/deltarune/src/battle.c
@@ -640,7 +640,7 @@ static void begin_fight(void) {
return;
}
/* one bolt each, in a random order, 12 or 18 frames apart (diff 10, +2 in one-button mode) */
- int off = -1, last = -1;
+ int off = 0, last = -1; /* (boltxoff, lastbolt) */
for (int i = 0; i < nf; i++) {
int j = rnd_n(nf - i) + i, t = fighters[i];
fighters[i] = fighters[j], fighters[j] = t;
diff --git a/games/deltarune/tests/check.py b/games/deltarune/tests/check.py
new file mode 100644
index 00000000..db4206e7
--- /dev/null
+++ b/games/deltarune/tests/check.py
@@ -0,0 +1,97 @@
+#!/usr/bin/env python3
+"""Deltarune played on a computer (build/play, with the sanitizers):
+
+ python3 tests/check.py build/play
+
+- the battle's rules against the original's (spec: FIGHT's points and damage, TP, ACTs, sparing)
+- a scripted run from Kris's room into the Dark World, and one from the landing to the castle, Lancer's
+ fight and Ralsei
+- random keys in many places, a few hundred thousand frames: nothing may crash"""
+import os
+import re
+import subprocess
+import sys
+
+HERE = os.path.dirname(os.path.abspath(__file__))
+PLAY = sys.argv[1] if len(sys.argv) > 1 else os.path.join(HERE, "..", "build", "play")
+fails = 0
+
+
+def ids():
+ out = {}
+ with open(os.path.join(HERE, "..", "src", "data.h")) as f:
+ for ln in f:
+ m = re.match(r"\s+(room_\w+) = (\d+),", ln)
+ if m:
+ out[m.group(1)] = int(m.group(2))
+ return out
+
+
+R = ids()
+
+
+def play(*args):
+ r = subprocess.run([PLAY, "--saves", os.path.join(HERE, "..", "build")] + [str(a) for a in args],
+ capture_output=True, text=True)
+ if r.returncode:
+ print(r.stdout[-2000:], r.stderr[-4000:])
+ st = {}
+ for ln in r.stdout.splitlines():
+ if ln.startswith("STATE") or ln.startswith("BATTLE"):
+ w = ln.split()[1:]
+ for k in range(0, len(w) - 1, 2):
+ st[w[k]] = w[k + 1]
+ return r.returncode, st
+
+
+def check(name, ok):
+ global fails
+ print(("ok " if ok else "FAIL ") + name)
+ fails += not ok
+
+
+# ---------------------------------------------------------------- the rules
+# Rudinn: 120 HP, DF 0; Kris AT 10 with the Wood Blade. A perfect FIGHT (its bolt hit on the frame it reaches
+# the line) scores 150 points: damage round(AT * 150 / 20 - DF * 3) = 75, TP + 150 / 10
+rc, s = play("--battle", 4, "--party", "1,0,0", "--frames", 140, "--keys", "40:z,46:z", "--perfect")
+check("FIGHT, a perfect hit: 75 damage, 15 TP", rc == 0 and s.get("enemies", "").startswith("45,") and s.get("tp") == "15")
+# DEFEND: 40 TP (16%)
+rc, s = play("--battle", 4, "--party", "1,0,0", "--frames", 60, "--keys", "40:right,44:right,48:right,52:right,56:z")
+check("DEFEND: 40 TP", rc == 0 and s.get("tp") == "40")
+# Rudinn's Convince: mercy 100; then SPARE wins, and the D$ come (30, and the TP's tenth)
+rc, s = play("--battle", 4, "--party", "1,0,0", "--frames", 900, "--menukeys", "right,z,z,right,z,right,right,z,z",
+ "--mash")
+check("ACT Convince, then SPARE: the battle is won", rc == 0 and s.get("alive") == "0" and int(s.get("gold", 0)) >= 30)
+# Lancer's first fight: Kris and Susie FIGHT until he's beaten, back to the overworld
+rc, s = play("--battle", 2, "--party", "1,2,0", "--frames", 9000, "--mash")
+check("Lancer's first fight, won", rc == 0 and s.get("alive") == "0" and s.get("mode") == "1")
+
+# ---------------------------------------------------------------- scripted runs
+rc, s = play("--room", R["room_krisroom"], "--at", "246,97", "--frames", 12000, "--mash", "--path",
+ "150,216;420,82r;590,130r;460,100@%d;460,20@%d" % (R["room_schoollobby"], R["room_schoollobby"]))
+check("Kris's room to the Dark World", rc == 0 and s.get("plot") == "10" and s.get("room") == str(R["room_dark1"]))
+path = ";".join([
+ "600,220@%d" % R["room_dark1"], "600,220@%d" % R["room_dark1a"], "3600,290@%d" % R["room_dark2"],
+ "1480,880@%d" % R["room_dark3"], "1280,300@%d" % R["room_dark_wobbles"], "1310,300@%d" % R["room_dark_eyepuzzle"],
+ "1270,620@%d" % R["room_dark7"], "2000,660@%d" % R["room_dark7"], "5360,800@%d" % R["room_dark_chase1"],
+ "600,260@%d" % R["room_castle_outskirts"], "300,150@%d" % R["room_castle_town"]])
+rc, s = play("--room", R["room_dark1"], "--at", "280,200", "--plot", 10, "--flag", "201=1", "--frames", 16000, "--mash",
+ "--path", path)
+check("the landing to the castle, Lancer's fight and Ralsei", rc == 0 and s.get("plot") == "30" and s.get("party") == "1,3,0")
+
+# ---------------------------------------------------------------- random keys
+starts = [("room_krisroom", "246,97", 0), ("room_schoollobby", "110,200", 3), ("room_dark1", "280,200", 10),
+ ("room_dark_eyepuzzle", "200,300", 12), ("room_castle_town", "300,600", 30), ("room_field1", "450,310", 33)]
+bad = 0
+for i in range(60):
+ room, at, plot = starts[i % len(starts)]
+ rc, s = play("--room", R[room], "--at", at, "--plot", plot, "--party", "1,2,3" if plot >= 33 else "1,0,0",
+ "--frames", 4000, "--fuzz", i + 1)
+ bad += rc != 0
+for i in range(20):
+ rc, s = play("--battle", [2, 3, 4, 5, 6, 9][i % 6], "--party", "1,2,3", "--frames", 4000, "--fuzz", 100 + i)
+ bad += rc != 0
+check("random keys: 80 sessions, nothing crashed", bad == 0)
+
+print("%d failed" % fails if fails else "all passed")
+sys.exit(1 if fails else 0)
diff --git a/games/deltarune/tests/play.c b/games/deltarune/tests/play.c
index 9d941c98..a1424dd1 100644
--- a/games/deltarune/tests/play.c
+++ b/games/deltarune/tests/play.c
@@ -2,7 +2,7 @@
*
* play [--frames N] [--keys "10-40:right,50:z,..."] [--shots 30,60|all|every:N] [--out DIR] [--saves DIR]
* [--room NAME_NUMBER --at X,Y] [--plot P] [--party 1,2,3] [--flag F=V]... [--battle N] [--fuzz SEED]
- * [--mash] [--trace]
+ * [--mash] [--trace] [--perfect] [--menukeys "right,z,..."]
*
* Keys: left right up down z x c home. "a-b:key" holds the key from frame a to b, "a:key" for one frame.
* --room starts a new game in room N (its number in data.h) with Kris's top-left at (X, Y), past the title.
@@ -169,7 +169,9 @@ static uint32_t path_keys(void) {
int main(int argc, char **argv) {
int frames = 300, room = -1, ax = 0, ay = 0, plotv = -1, battle = -1, every = 0;
unsigned fuzz = 0;
- bool all = false, mash = false, trace = false;
+ bool all = false, mash = false, trace = false, perfect = false;
+ int bars_t = -1, mk_wait = 0;
+ const char *menukeys = NULL;
const char *out = "build/shots", *shots = "";
int party[3] = {0, 0, 0};
static int flags[64][2];
@@ -192,6 +194,8 @@ int main(int argc, char **argv) {
else if (!strcmp(a, "--battle")) battle = atoi(v), i++;
else if (!strcmp(a, "--fuzz")) fuzz = (unsigned)atoi(v), i++;
else if (!strcmp(a, "--mash")) mash = true;
+ else if (!strcmp(a, "--perfect")) perfect = true;
+ else if (!strcmp(a, "--menukeys")) menukeys = v, i++;
else if (!strcmp(a, "--trace")) trace = true;
else if (!strcmp(a, "--path")) path_at = argv[++i];
}
@@ -217,6 +221,19 @@ int main(int argc, char **argv) {
seed ^= seed << 13, seed ^= seed >> 17, seed ^= seed << 5;
static const uint32_t ks[] = {K_LEFT, K_RIGHT, K_UP, K_DOWN, K_Z, K_X, K_C, 0};
k = ks[seed % 8] | ((seed >> 8) % 3 == 0 ? ks[(seed >> 12) % 8] : 0);
+ } else if (menukeys && *menukeys && g_mode == MODE_BATTLE && battle_ui() >= BUI_BUTTONS && battle_ui() <= BUI_PARTY) {
+ /* the battle's menus: the next key of the list, one every 3 frames */
+ if (++mk_wait >= 3) {
+ mk_wait = 0;
+ k = key_of(menukeys);
+ while (*menukeys && *menukeys != ',') menukeys++;
+ if (*menukeys) menukeys++;
+ }
+ } else if (perfect && battle_ui() == BUI_BARS) {
+ /* FIGHT's bar: Z the frame a lone bolt reaches the line (its frame 29: a perfect hit) */
+ if (bars_t < 0) bars_t = 0;
+ k = bars_t == 29 ? K_Z : 0;
+ bars_t++;
} else if (!k && (k = path_keys())) {
} else if (mash && !k && f % 4 == 0) {
k = K_Z;
@@ -248,5 +265,7 @@ int main(int argc, char **argv) {
printf("STATE mode %d room %d kris %d,%d dir %d plot %d hp %d,%d,%d gold %ld party %d,%d,%d dropped %d blocks %u\n",
g_mode, g_room, (int)pl.x, (int)pl.y, pl.dir, sv.plot, sv.hp[1], sv.hp[2], sv.hp[3], (long)sv.gold,
sv.chr[0], sv.chr[1], sv.chr[2], gfx_dropped, (unsigned)blk_most_in_frame);
+ printf("BATTLE tp %d enemies %d,%d,%d mercy %d,%d,%d alive %d\n", g_tension, en[0].hp, en[1].hp, en[2].hp, en[0].mercy,
+ en[1].mercy, en[2].mercy, enemies_alive());
return 0;
}