Skip to content

Commit d04b04a

Browse files
authored
Merge pull request #568 from OpenVicProject/fixed-pathing-test-seeds
Added optional fixed seeds to the headless SIM pathing tests
2 parents f76ed0a + f299a1e commit d04b04a

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

src/headless/main.cpp

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,23 @@ static void print_rgo(ProvinceInstance const& province) {
7676
}
7777
}
7878

79+
using pathing_rng_t = std::mt19937;
80+
using pathing_rng_seed_t = pathing_rng_t::result_type;
81+
7982
template<size_t TestCount>
80-
static std::chrono::nanoseconds run_pathing_test(AStarPathing& pathing) {
83+
static std::chrono::nanoseconds run_pathing_test(AStarPathing& pathing, std::optional<pathing_rng_seed_t> seed) {
8184
PointMap const& points = pathing.get_point_map();
8285

83-
thread_local std::random_device rd;
84-
thread_local std::mt19937 gen(rd());
86+
if (!seed.has_value()) {
87+
thread_local std::random_device rd;
88+
seed = rd();
89+
90+
Logger::info("Running ", TestCount, " pathing tests with randomly generated seed: ", seed.value());
91+
} else {
92+
Logger::info("Running ", TestCount, " pathing tests with fixed seed: ", seed.value());
93+
}
94+
95+
thread_local pathing_rng_t gen { seed.value() };
8596

8697
using it = decltype(points.points_map().end());
8798
std::array<std::pair<it, it>, TestCount> from_to_tests;
@@ -218,13 +229,19 @@ static bool run_headless(fs::path const& root, memory::vector<memory::string>& m
218229

219230
if (ret) {
220231
static constexpr size_t TESTS = 10;
232+
// Set to std::nullopt to use a different random seed on each run
233+
static constexpr std::optional<pathing_rng_seed_t> LAND_SEED = 1836, SEA_SEED = 1861;
221234

222235
Logger::info("===== Land Pathfinding test... =====");
223-
std::chrono::nanoseconds ns = run_pathing_test<TESTS>(game_manager.get_instance_manager()->get_map_instance().get_land_pathing());
236+
std::chrono::nanoseconds ns = run_pathing_test<TESTS>(
237+
game_manager.get_instance_manager()->get_map_instance().get_land_pathing(), LAND_SEED
238+
);
224239
Logger::info("Ran ", TESTS, " land pathing tests in ", ns);
225240

226241
Logger::info("===== Sea Pathfinding test... =====");
227-
ns = run_pathing_test<TESTS>(game_manager.get_instance_manager()->get_map_instance().get_sea_pathing());
242+
ns = run_pathing_test<TESTS>(
243+
game_manager.get_instance_manager()->get_map_instance().get_sea_pathing(), SEA_SEED
244+
);
228245
Logger::info("Ran ", TESTS, " sea pathing tests in ", ns);
229246
}
230247

0 commit comments

Comments
 (0)