From 9001af214accf056cb2fac2b8c1edf96ea070d50 Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Fri, 13 Mar 2026 10:41:42 -0400 Subject: [PATCH] Maze scripts now work reliably. --- Makefile | 4 ++-- src/algos/maze.cpp | 3 +-- tests/mazes.cpp | 42 ++++++++++++++++++++++++------------------ 3 files changed, 27 insertions(+), 22 deletions(-) diff --git a/Makefile b/Makefile index 52d5aed..9913705 100644 --- a/Makefile +++ b/Makefile @@ -37,7 +37,7 @@ tracy_build: meson compile -j 10 -C builddir test: build - ./builddir/runtests -d yes "[mazes]" + ./builddir/runtests -d yes run: build test ifeq '$(OS)' 'Windows_NT' @@ -60,7 +60,7 @@ clean: meson compile --clean -C builddir debug_test: build - gdb --nx -x .gdbinit --ex run --ex bt --ex q --args builddir/runtests "[mazes]" + gdb --nx -x .gdbinit --ex run --ex bt --ex q --args builddir/runtests win_installer: powershell 'start "C:\Program Files (x86)\solicus\InstallForge\bin\ifbuilderenvx86.exe" scripts\win_installer.ifp' diff --git a/src/algos/maze.cpp b/src/algos/maze.cpp index 861a3e0..0756811 100644 --- a/src/algos/maze.cpp +++ b/src/algos/maze.cpp @@ -289,7 +289,7 @@ namespace maze { matrix::perimeter it{room.x - 1, room.y - 1, room.width + 2, room.height + 2}; while(it.next()) { - if($walls[it.y][it.x] == SPACE_VALUE) { + if(matrix::inbounds($walls, it.x, it.y) && $walls[it.y][it.x] == SPACE_VALUE) { last_door = {it.x, it.y}; possible_doors++; } @@ -458,7 +458,6 @@ namespace maze { for(auto& action : config) { std::string aname = action["action"]; - fmt::println("ACTION {}", aname); if(aname == "hunt_and_kill") { maze.hunt_and_kill(); diff --git a/tests/mazes.cpp b/tests/mazes.cpp index cfd3591..e202e82 100644 --- a/tests/mazes.cpp +++ b/tests/mazes.cpp @@ -152,24 +152,30 @@ TEST_CASE("hunt-and-kill validator", "[mazes]") { TEST_CASE("hunt-and-kill scripting", "[mazes]") { using namespace nlohmann::literals; - auto script = R"( - [ - {"action": "hunt_and_kill"}, - {"action": "clear"}, - {"action": "inner_box", "data": [6, 4]}, - {"action": "randomize_rooms", "data": [4]}, - {"action": "divide", "data": [3, 3, 10, 10]}, - {"action": "inner_donut", "data": [5.5,4.5]}, - {"action": "hunt_and_kill"}, - {"action": "open_box", "data": [6]}, - {"action": "remove_dead_ends"}, - {"action": "make_doors"} - ] - )"_json; + // go up by 2 to keep odd + for(int i = 0; i < 20; i+=2) { + auto script = R"( + [ + {"action": "hunt_and_kill"}, + {"action": "clear"}, + {"action": "inner_box", "data": [6, 4]}, + {"action": "randomize_rooms", "data": [4]}, + {"action": "divide", "data": [3, 3, 10, 10]}, + {"action": "inner_donut", "data": [5.5,4.5]}, + {"action": "hunt_and_kill"}, + {"action": "open_box", "data": [6]}, + {"action": "remove_dead_ends"}, + {"action": "make_doors"} + ] + )"_json; + Map map(23+i, 23+i); + auto [maze, valid] = maze::script(map, script); - Map map(33, 33); - auto [maze, valid] = maze::script(map, script); - maze.dump("SCRIPTED"); - REQUIRE(valid == true); + if(valid) { + REQUIRE(maze.validate() == true); + } + + if(DUMP) maze.dump(valid ? "SCRIPTED" : "SCRIPTED FAIL!"); + } }