// Verify the road autotiler (ui/tools.hpp): known-answer patterns, and — the real test — that it // reproduces the road codes the original game actually stored, recomputed from each tile's neighbours. #include "sc2k/io/sc2_file.hpp" #include "sc2k/ui/tools.hpp" #include #include #include "test_paths.hpp" using namespace sc2k; using namespace sc2k::ui::detail; #include "test_harness.hpp" int main() { // --- KAT: place roads and check the autotiled codes --- { City c; place_road(c, 5, 5); // isolated → straight default CHECK(c.xbld.at(5, 5) == 0x1d); City h; // horizontal run: all E-W straights for (int col = 4; col <= 7; ++col) place_road(h, 5, col); for (int col = 4; col <= 7; ++col) CHECK(h.xbld.at(5, col) == 0x1d); City L; // an L: (5,5)-(5,6)-(6,6) place_road(L, 5, 5); place_road(L, 5, 6); place_road(L, 6, 6); CHECK(L.xbld.at(5, 5) == 0x1d); // connects E only → straight CHECK(L.xbld.at(5, 6) == 0x23); // connects W+S → SW corner CHECK(L.xbld.at(6, 6) == 0x1e); // connects N only → N-S straight City x; // a + cross place_road(x, 10, 10); place_road(x, 9, 10); place_road(x, 11, 10); place_road(x, 10, 9); place_road(x, 10, 11); CHECK(x.xbld.at(10, 10) == 0x2b); // all four → cross CHECK(x.xbld.at(9, 10) == 0x1e && x.xbld.at(11, 10) == 0x1e); // N/S arms → N-S straight CHECK(x.xbld.at(10, 9) == 0x1d && x.xbld.at(10, 11) == 0x1d); // E/W arms → E-W straight } // --- reproduce the game's stored road codes from neighbour connectivity --- int total = 0, match = 0, slopes = 0; for (const char* name : {"TOKYO.SC2", "LONDON.SC2", "NEWYORK.SC2", "PARIS.SC2", "CENTERVL.SC2"}) { const std::string p = city_file(name); if (!exists(p)) continue; City c; if (!io::load_sc2(p, c).ok) continue; for (int r = 0; r < 128; ++r) for (int col = 0; col < 128; ++col) { const int code = c.xbld.at(r, col); if (!is_road(code)) continue; if (code >= 0x1f && code <= 0x22) { ++slopes; continue; } // sloped variant: out of scope const int m = neighbor_mask(c, r, col, [](int cd) { return road_connects(cd); }); ++total; if (kRoadTile[m] == code) ++match; } } if (total > 0) { std::printf("autotile: road codes reproduced %d/%d flat tiles (%.1f%%); %d sloped skipped\n", match, total, 100.0 * match / total, slopes); CHECK(100.0 * match / total > 97.0); } else { std::printf("autotile: (no game data for the real-city check; KAT ran)\n"); } if (failures == 0) { std::printf("autotile: all checks passed\n"); return 0; } std::printf("autotile: %d failure(s)\n", failures); return 1; }