// Integration: tick a loaded city through the scheduler and confirm the wired phases run. // // Power (tick 1) and water (tick 20) are now wired into the scheduler. With the growth phases // still stubbed (XBLD unchanged), recomputing the grids each month must reproduce the saved XBIT // bits exactly — so after a couple of months the powered (0x40) and watered (0x10) bits still // match what the game saved. This checks the scheduler dispatches into the real subsystems. #include "sc2k/sim/simulation.hpp" #include "sc2k/io/sc2_file.hpp" #include #include #include "test_paths.hpp" #include "test_harness.hpp" int main() { using namespace sc2k; City c; auto r = io::load_sc2((city_file("TOKYO.SC2")), c); if (!r.ok) { std::printf("sim_tick: skipped (%s)\n", r.error.c_str()); return 0; } std::vector savedPow(City::kTiles), savedWat(City::kTiles); for (int t = 0; t < City::kTiles; ++t) { savedPow[t] = (c.xbit.cells[t] & 0x40) != 0; savedWat[t] = (c.xbit.cells[t] & 0x10) != 0; } Simulation sim(c); const int m0 = sim.month(); for (int i = 0; i < 50; ++i) sim.tick(); // two full months: hits power (t=1) and water (t=20) int powMiss = 0, watMiss = 0; for (int t = 0; t < City::kTiles; ++t) { if (((c.xbit.cells[t] & 0x40) != 0) != savedPow[t]) ++powMiss; if (((c.xbit.cells[t] & 0x10) != 0) != savedWat[t]) ++watMiss; } std::printf(" TOKYO ticked 50: month %d -> %d power-bit drift=%d water-bit drift=%d\n", m0, sim.month(), powMiss, watMiss); CHECK(powMiss == 0); // phase_power reproduced the saved powered grid CHECK(watMiss == 0); // phase_water reproduced the saved watered grid CHECK(sim.clock() == static_cast(c.days()) + 50); if (failures == 0) { std::printf("sim_tick: all checks passed\n"); return 0; } std::printf("sim_tick: %d failure(s)\n", failures); return 1; }