Something went wrong. Try again.
[Mirror] Libreopolis is a cross-platform city simulation game fully compatible with SimCity 2000. gitlab.com/conasg/libreopolis
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192// Tests the road/transit-access predicate + its neighbor-scan table.//// (1) Known-answer: a lone road tile is "seen" by exactly its 24 offset-neighbours and no far tile;// non-transit tiles confer no access. This proves the scan pattern and the accept-set are faithful.// (2) Diagnostic: agreement with the saved XBIT near-road bit (0x04) on real cities — informative about// whether 0x04 is this exact predicate (not asserted, since 0x04 may also fold in water adjacency).#include "sc2k/sim/transit_access.hpp"#include "sc2k/io/sc2_file.hpp"#include <cstdio>#include "test_paths.hpp"
#include "test_harness.hpp"
static void kat() { using namespace sc2k; City c; c.xbld.cells[64 * 128 + 64] = 29; // a single road tile
int seen = 0; for (const auto& d : kNeighborScan) { int r = 64 - d[0], cc = 64 - d[1]; // the tile that sees (64,64) via offset d if (has_transit_access(c, r, cc)) ++seen; } CHECK(seen == 24); // all 24 distinct offset-neighbours see the road CHECK(!has_transit_access(c, 64, 64)); // the road tile is not its own neighbour CHECK(!has_transit_access(c, 10, 10)); // far away: no access
// A non-transit tile (e.g. a building code) confers no access. City c2; c2.xbld.cells[64 * 128 + 64] = 0x70; // a building, not a road CHECK(!has_transit_access(c2, 63, 64));
// Accept-set boundaries (the original's ranges): 28 out, 29 in; 43 in, 44 out; 71 out; 75/76 in; 233/236/237 in. CHECK(!is_transit_tile(28) && is_transit_tile(29) && is_transit_tile(43) && !is_transit_tile(44)); CHECK(!is_transit_tile(71) && is_transit_tile(75) && is_transit_tile(76)); CHECK(is_transit_tile(233) && is_transit_tile(236) && is_transit_tile(237) && !is_transit_tile(235));
// Power gate. FAITHFUL (diagonal=false): a powered XBIT 0x40 confers power to itself + the // 4 orthogonal neighbours only, NOT diagonals. City p; p.xbit.cells[50 * 128 + 50] = 0x40; // one powered tile CHECK(is_growth_powered(p, 50, 50, false)); // self CHECK(is_growth_powered(p, 49, 50, false) && is_growth_powered(p, 51, 50, false)); // up/down CHECK(is_growth_powered(p, 50, 49, false) && is_growth_powered(p, 50, 51, false)); // left/right CHECK(!is_growth_powered(p, 49, 49, false)); // diagonal: NOT powered (faithful) CHECK(!is_growth_powered(p, 52, 50, false)); // two away: not powered // DEVIATION (diagonal=true, the default): the four diagonals now count, so corner-adjacent power confers it. CHECK(is_growth_powered(p, 49, 49, true) && is_growth_powered(p, 51, 51, true)); // NW / SE diagonal CHECK(is_growth_powered(p, 49, 51, true) && is_growth_powered(p, 51, 49, true)); // NE / SW diagonal CHECK(!is_growth_powered(p, 52, 50, true)); // still not two-away // Asymmetric edge bound: the up neighbour is only consulted when row >= 2 (the original tests coord > 1). City e; e.xbit.cells[0 * 128 + 40] = 0x40; // powered at row 0 CHECK(!is_growth_powered(e, 1, 40, false)); // row 1 does NOT look up to row 0 (the original's quirk) CHECK(is_growth_powered(e, 0, 40, false)); // row 0 sees itself}
static void corr_xbit04(const char* name) { using namespace sc2k; std::string path = (cities_dir()) + name; City c; if (!io::load_sc2(path, c).ok) { std::printf(" %-13s skipped\n", name); return; }
long agree = 0, total = 0, predTrue = 0, bitTrue = 0; for (int r = 0; r < 128; ++r) for (int cc = 0; cc < 128; ++cc) { bool pred = has_transit_access(c, r, cc); bool bit = (c.xbit.cells[r * 128 + cc] & 0x04) != 0; agree += (pred == bit); ++total; predTrue += pred; bitTrue += bit; } std::printf(" %-13s has_transit_access vs XBIT&0x04: %.1f%% agree (pred=%ld, bit=%ld of %ld)\n", name, 100.0 * agree / total, predTrue, bitTrue, total);}
int main() { kat(); for (const char* n : {"TOKYO.SC2", "BAYVIEW.SC2", "LONDON.SC2", "NYC.SC2", "PARIS.SC2"}) corr_xbit04(n); if (failures == 0) { std::printf("transit_access: KAT passed\n"); return 0; } std::printf("transit_access: %d failure(s)\n", failures); return 1;}