Maze scripts now work reliably.

This commit is contained in:
Zed A. Shaw 2026-03-13 10:41:42 -04:00
parent c615f4fc1e
commit 9001af214a
3 changed files with 27 additions and 22 deletions

View file

@ -37,7 +37,7 @@ tracy_build:
meson compile -j 10 -C builddir meson compile -j 10 -C builddir
test: build test: build
./builddir/runtests -d yes "[mazes]" ./builddir/runtests -d yes
run: build test run: build test
ifeq '$(OS)' 'Windows_NT' ifeq '$(OS)' 'Windows_NT'
@ -60,7 +60,7 @@ clean:
meson compile --clean -C builddir meson compile --clean -C builddir
debug_test: build 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: win_installer:
powershell 'start "C:\Program Files (x86)\solicus\InstallForge\bin\ifbuilderenvx86.exe" scripts\win_installer.ifp' powershell 'start "C:\Program Files (x86)\solicus\InstallForge\bin\ifbuilderenvx86.exe" scripts\win_installer.ifp'

View file

@ -289,7 +289,7 @@ namespace maze {
matrix::perimeter it{room.x - 1, room.y - 1, room.width + 2, room.height + 2}; matrix::perimeter it{room.x - 1, room.y - 1, room.width + 2, room.height + 2};
while(it.next()) { 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}; last_door = {it.x, it.y};
possible_doors++; possible_doors++;
} }
@ -458,7 +458,6 @@ namespace maze {
for(auto& action : config) { for(auto& action : config) {
std::string aname = action["action"]; std::string aname = action["action"];
fmt::println("ACTION {}", aname);
if(aname == "hunt_and_kill") { if(aname == "hunt_and_kill") {
maze.hunt_and_kill(); maze.hunt_and_kill();

View file

@ -152,24 +152,30 @@ TEST_CASE("hunt-and-kill validator", "[mazes]") {
TEST_CASE("hunt-and-kill scripting", "[mazes]") { TEST_CASE("hunt-and-kill scripting", "[mazes]") {
using namespace nlohmann::literals; using namespace nlohmann::literals;
auto script = R"( // go up by 2 to keep odd
[ for(int i = 0; i < 20; i+=2) {
{"action": "hunt_and_kill"}, auto script = R"(
{"action": "clear"}, [
{"action": "inner_box", "data": [6, 4]}, {"action": "hunt_and_kill"},
{"action": "randomize_rooms", "data": [4]}, {"action": "clear"},
{"action": "divide", "data": [3, 3, 10, 10]}, {"action": "inner_box", "data": [6, 4]},
{"action": "inner_donut", "data": [5.5,4.5]}, {"action": "randomize_rooms", "data": [4]},
{"action": "hunt_and_kill"}, {"action": "divide", "data": [3, 3, 10, 10]},
{"action": "open_box", "data": [6]}, {"action": "inner_donut", "data": [5.5,4.5]},
{"action": "remove_dead_ends"}, {"action": "hunt_and_kill"},
{"action": "make_doors"} {"action": "open_box", "data": [6]},
] {"action": "remove_dead_ends"},
)"_json; {"action": "make_doors"}
]
)"_json;
Map map(23+i, 23+i);
auto [maze, valid] = maze::script(map, script);
Map map(33, 33); if(valid) {
auto [maze, valid] = maze::script(map, script); REQUIRE(maze.validate() == true);
maze.dump("SCRIPTED"); }
REQUIRE(valid == true);
if(DUMP) maze.dump(valid ? "SCRIPTED" : "SCRIPTED FAIL!");
}
} }