// Validates the land-value field by correlation against the saved XVAL minimap. // // Land value is iterative and coarsely encoded, so it won't be bit-equal, but it must correlate // strongly with the saved field. The original game's own validation reached r≈0.72; this port // reaches r≈0.69–0.86 across cities. Correlation is taken over developed cells (saved XVAL > 0). #include "sc2k/sim/land_value.hpp" #include "sc2k/io/sc2_file.hpp" #include #include #include #include #include "test_paths.hpp" #include "test_harness.hpp" static double pearson(const std::vector& a, const std::vector& b) { const int n = static_cast(a.size()); if (n < 2) return 0; double sx = 0, sy = 0, sxx = 0, syy = 0, sxy = 0; for (int i = 0; i < n; ++i) { sx += a[i]; sy += b[i]; sxx += a[i] * a[i]; syy += b[i] * b[i]; sxy += a[i] * b[i]; } double den = std::sqrt((n * sxx - sx * sx) * (n * syy - sy * sy)); return den > 0 ? (n * sxy - sx * sy) / den : 0.0; } static void check_city(const char* name) { using namespace sc2k; std::string path = (cities_dir()) + name; City c; auto r = io::load_sc2(path, c); if (!r.ok) { std::printf(" %-13s skipped (%s)\n", name, r.error.c_str()); return; } std::array out{}; land_value_step(c, out); std::vector mine, saved; for (int i = 0; i < 64 * 64; ++i) if (c.xval.cells[i] > 0) { mine.push_back(out[i]); saved.push_back(c.xval.cells[i]); } if (saved.size() < 100) { std::printf(" %-13s (too few developed cells; skipped)\n", name); return; } double rr = pearson(mine, saved); std::printf(" %-13s land-value r = %.4f (over %zu developed cells)\n", name, rr, saved.size()); CHECK(rr > 0.60); // original's own ceiling is ~0.72 } int main() { for (const char* n : {"TOKYO.SC2", "LONDON.SC2", "NYC.SC2", "PARIS.SC2", "BIGGESTC.SC2", "BAYVIEW.SC2"}) check_city(n); if (failures == 0) { std::printf("land_value: all checks passed\n"); return 0; } std::printf("land_value: %d failure(s)\n", failures); return 1; }