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.

Isaac: rooms always reachable, a bot that plays it on a computer

Mason36393640eed89d3
diff --git a/games/isaac/src/data.bin b/games/isaac/src/data.bin
index 9d55379d..171de10c 100644
Binary files a/games/isaac/src/data.bin and b/games/isaac/src/data.bin differ
diff --git a/games/isaac/src/monsters.c b/games/isaac/src/monsters.c
index 1d8e409d..dd628a3e 100644
--- a/games/isaac/src/monsters.c
+++ b/games/isaac/src/monsters.c
@@ -146,6 +146,8 @@ Ent *mon_spawn(int type, float x, float y) {
e->t = (int16_t)(20 + rnd(40));
e->a = rndf() * 6.2831853f;
e->c = x, e->b = y; /* (where it began: tethers) */
+ if (m->ai == AI_CHARGER || m->ai == AI_KNIGHT || m->ai == AI_LEECH || m->ai == AI_WALL || m->ai == AI_VIS)
+ e->c = (float)rnd(4); /* (for these, the way they go) */
return e;
}
diff --git a/games/isaac/src/tears.c b/games/isaac/src/tears.c
index e0e74759..aa1e3f21 100644
--- a/games/isaac/src/tears.c
+++ b/games/isaac/src/tears.c
@@ -358,5 +358,5 @@ void explode(float x, float y, float radius, float dmg, bool hurt_player, int ki
grid_explode(x, y, radius);
float dx = pl.x - x, dy = pl.y - y;
if (hurt_player && dx * dx + dy * dy < (radius + 4) * (radius + 4) && !pl.has[190]) player_hurt(2, -1);
- decal_blood(x, y, -radius * 0.7f); /* (a scorch mark: negative is black) */
+ decal_blood(x, y, -radius * 0.45f); /* (a scorch mark: negative is black) */
}
diff --git a/games/isaac/tests/play.c b/games/isaac/tests/play.c
index 1b0778f0..3cbf751a 100644
--- a/games/isaac/tests/play.c
+++ b/games/isaac/tests/play.c
@@ -48,7 +48,8 @@ static void parse_keys(char *s) {
}
/* ---------------------------------------------------------------- the bot */
-static int bot_stuck, bot_last_room = -1, bot_target_door = -1;
+static int bot_stuck, bot_last_room = -1, bot_target_door = -1, bot_target = -1, bot_chase, bot_ignore_room = -1;
+static uint8_t bot_ignore[MAX_ENTS];
static float bot_lx, bot_ly;
static uint32_t bot_keys(void) {
uint32_t k = 0;
@@ -58,7 +59,7 @@ static uint32_t bot_keys(void) {
float best = 1e9f;
for (int i = 0; i < MAX_ENTS; i++) {
Ent *e = &ents[i];
- if (e->kind != EK_MON || (e->flags & (EF_FRIEND | EF_HIDDEN))) continue;
+ if (e->kind != EK_MON || (e->flags & (EF_FRIEND | EF_HIDDEN | EF_NOCOUNT))) continue;
float d = dist2(e->x, e->y, pl.x, pl.y);
if (d < best) best = d, m = e;
}
@@ -66,11 +67,14 @@ static uint32_t bot_keys(void) {
if (m) {
/* line up with it, a little way off, and cry at it */
float dx = m->x - pl.x, dy = m->y - pl.y;
+ static const float off[4] = {55, 30, -55, -30};
if (absf(dx) < absf(dy)) {
tx = m->x, ty = m->y + (dy > 0 ? -50 : 50);
+ for (int i = 0; i < 4 && solid_at(tx, ty, false); i++) ty = m->y + (dy > 0 ? -off[i] : off[i]);
if (absf(dx) < 12) k |= dy > 0 ? K_SDOWN : K_SUP;
} else {
ty = m->y, tx = m->x + (dx > 0 ? -55 : 55);
+ for (int i = 0; i < 4 && solid_at(tx, ty, false); i++) tx = m->x + (dx > 0 ? -off[i] : off[i]);
if (absf(dy) < 12) k |= dx > 0 ? K_SRIGHT : K_SLEFT;
}
if (!(k & K_SHOOT)) k |= absf(dx) > absf(dy) ? (dx > 0 ? K_SRIGHT : K_SLEFT) : (dy > 0 ? K_SDOWN : K_SUP);
@@ -78,14 +82,21 @@ static uint32_t bot_keys(void) {
/* pickups and items first, then the trapdoor, then a door to a room not yet visited */
Ent *p = NULL;
best = 1e9f;
+ if (bot_ignore_room != fl.cur) memset(bot_ignore, 0, sizeof bot_ignore), bot_ignore_room = fl.cur;
for (int i = 0; i < MAX_ENTS; i++) {
Ent *e = &ents[i];
+ if (bot_ignore[i]) continue;
bool want = (e->kind == EK_PEDESTAL && e->t3 && !(e->flags & EF_DEVIL) && !e->price) || e->kind == EK_TRAPDOOR
|| (e->kind == EK_PICKUP && !(e->flags & EF_SHOP) && e->type != PK_LOCKED_CHEST);
if (!want) continue;
float d = dist2(e->x, e->y, pl.x, pl.y) + (e->kind == EK_TRAPDOOR ? 1e6f : 0);
if (d < best) best = d, p = e;
}
+ /* (what it can't reach after a while, it leaves) */
+ if (p && (int)(p - ents) == bot_target) {
+ if (++bot_chase > 150 && p->kind != EK_TRAPDOOR) bot_ignore[p - ents] = 1, bot_chase = 0;
+ } else
+ bot_target = p ? (int)(p - ents) : -1, bot_chase = 0;
if (p && !(p->kind == EK_TRAPDOOR && bot_target_door >= 0 && fl.cur != fl.boss_room)) tx = p->x, ty = p->y;
else {
if (fl.cur != bot_last_room) bot_last_room = fl.cur, bot_target_door = -1;
@@ -179,6 +190,7 @@ int main(int argc, char **argv) {
for (int i = 0; i < nholds; i++)
if (f >= holds[i].a && f <= holds[i].b) k |= holds[i].k;
if (bot && !k) k = bot_keys();
+ if (getenv("TRACE") && f % 50 == 0) printf("f %d pl %.1f,%.1f v %.2f,%.2f keys %x mode %d room %d\n", f, pl.x, pl.y, pl.vx, pl.vy, k, g_mode, fl.cur);
if (god) pl.invuln = pl.invuln > 2 ? pl.invuln : 2, pl.dead = false;
host_keys = k;
host_time += 33;
@@ -193,6 +205,10 @@ int main(int argc, char **argv) {
host_shot(p);
}
}
+ for (int i = 0; i < MAX_ENTS; i++)
+ if (ents[i].kind == EK_MON)
+ printf("MON %d type %d hp %.1f/%.1f state %d at %.0f,%.0f flags %x\n", i, ents[i].type, ents[i].hp, ents[i].maxhp,
+ ents[i].state, ents[i].x, ents[i].y, ents[i].flags);
printf("END mode %d stage %d room %d kind %d hp %d/%d soul %d coins %d bombs %d keys %d items %d frames %u floors %d dropped %d\n",
g_mode, fl.stage, fl.cur, room_cur()->kind, pl.red, pl.containers * 2, pl.soul, pl.coins, pl.bombs, pl.keys, pl.norder,
g_frame, floors_seen, gfx_dropped);
diff --git a/games/isaac/tools/rooms.py b/games/isaac/tools/rooms.py
index 8d9ba410..ad82559c 100644
--- a/games/isaac/tools/rooms.py
+++ b/games/isaac/tools/rooms.py
@@ -166,7 +166,7 @@ room([".............",
"....r...r....",
".1.........1.",
"............."], weight=2)
-room(["......t......",
+room([".....t.......",
".2...........",
"...r.....r...",
"......3......",
@@ -201,13 +201,13 @@ room([".............",
"..s.s.s.s.s..",
".1.........1.",
"............."])
-room(["......o......",
- "......o......",
- "..1...o...1..",
- "ooo.......ooo",
- "..2...o...2..",
- "......o......",
- "......o......"], chapters=30)
+room([".............",
+ ".....o.o.....",
+ "..1..o.o..1..",
+ ".oo.......oo.",
+ "..2..o.o..2..",
+ ".....o.o.....",
+ "............."], chapters=30)
room([".............",
".....rrr.....",
"..2..r*r..2..",
@@ -250,13 +250,13 @@ room([".............",
".r..1...1..r.",
".rr.......rr.",
"............."], weight=2)
-room(["......r......",
+room([".............",
"......r......",
"...3..r..3...",
".............",
"...2..r..2...",
"......r......",
- "......r......"])
+ "............."])
room([".............",
".............",
".1..1..1..1..",
@@ -271,13 +271,13 @@ room([".............",
"...r.....r...",
"...rrr.rrr...",
"............."])
-room(["o.o.o.o.o.o.o",
+room(["o.o.o...o.o.o",
".............",
"o.....2.....o",
".............",
"o...2...2...o",
".............",
- "o.o.o.o.o.o.o"], chapters=30)
+ "o.o.o...o.o.o"], chapters=30)
room([".............",
"..x.......x..",
".............",
@@ -302,7 +302,7 @@ room([".............",
room(["..ppp...ppp..",
".............",
"p.....2.....p",
- "p...........p",
+ ".............",
"p.....2.....p",
".............",
"..ppp...ppp.."])
@@ -474,9 +474,29 @@ for k in ("SHOP", "BOSS", "ARCADE", "SACRIFICE", "LIBRARY", "MINIBOSS", "CHALLEN
room(["............."] * 7, k) # (laid out by the game itself)
+SOLID = set("rmtbpqoxkfF")
+
+
+def check(rows):
+ """every door's cell reaches every other's, walking (no bombs, no flight)"""
+ doors = [(6, 0), (0, 3), (6, 6), (12, 3)]
+ for c, r in doors:
+ assert rows[r][c] not in SOLID, (rows, "a door is blocked")
+ seen, todo = {doors[0]}, [doors[0]]
+ while todo:
+ c, r = todo.pop()
+ for dc, dr in ((1, 0), (-1, 0), (0, 1), (0, -1)):
+ n = (c + dc, r + dr)
+ if 0 <= n[0] < 13 and 0 <= n[1] < 7 and n not in seen and rows[n[1]][n[0]] not in SOLID:
+ seen.add(n)
+ todo.append(n)
+ assert all(d in seen for d in doors), (rows, "a door can't be reached")
+
+
def encode():
out = bytearray(struct.pack("<I", len(L)))
for kind, chapters, weight, rows, mons in L:
+ check(rows)
out += bytes([KINDS.index(kind), chapters, weight, 0])
for r in rows:
for ch in r: