Can now script maze gen with a json.

This commit is contained in:
Zed A. Shaw 2026-03-13 01:55:26 -04:00
parent a71d6340db
commit c615f4fc1e
3 changed files with 79 additions and 10 deletions

View file

@ -7,7 +7,7 @@
#include "algos/maze.hpp"
#include "algos/stats.hpp"
#define DUMP 1
#define DUMP 0
using std::string;
using matrix::Matrix;
@ -130,21 +130,46 @@ TEST_CASE("hunt-and-kill validator", "[mazes]") {
maze.make_doors();
valid = maze.repair();
if(i == 9) {
if(valid) {
maze.dump("VALIDATED");
} else {
matrix::dump("PATHING", maze.$paths.$paths);
}
if(i == 9 && DUMP) {
maze.dump(valid ? "VALIDATED" : "FAILED!");
}
door_prob.sample(valid);
} while(!valid);
door_prob.dump();
if(DUMP) door_prob.dump();
mofm.sample(door_prob.mean());
}
fmt::println("FINAL m-of-m");
mofm.dump();
if(DUMP) {
fmt::println("FINAL m-of-m");
mofm.dump();
}
REQUIRE(mofm.mean() > 0.20);
}
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;
Map map(33, 33);
auto [maze, valid] = maze::script(map, script);
maze.dump("SCRIPTED");
REQUIRE(valid == true);
}