Regression net for behaviour-preserving refactoring

- game/digest: fingerprint of the whole game state (saved stream, unsaved
  run-time values, both random generators)
- season_sim: SIM_DIGEST=<file> writes one digest per desk; SIM_LEAGUE picks
  the start league
- tools/ci/compare_digests.py compares two directories of digest files
- ui_walk (tool): replays an input script against the UI flow and the
  production controller without a window, one picture/state fingerprint per step
- openbmh_ui --frames: the same fingerprints for its scripted mode

No change of game behaviour. Reference files live outside the repository.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
ClaudeandClaude committed 2026-11-10 11:16:52 +01:00
1 parent d9d408069e
commit 901f3dec1c
7 files changed
+399 -3

No files matched your search

+59
View File
@@ -0,0 +1,59 @@
// SPDX-License-Identifier: GPL-3.0-only
// state_digest: see digest.hpp.
#include "game/digest.hpp"
#include "game/save.hpp"
namespace bmh {
namespace {
// FNV-1a, 64 bit: simple, stable across platforms and compilers (no std::hash).
struct Fnv {
uint64_t value = 0xcbf29ce484222325ull;
void byte(uint8_t b) { value = (value ^ b) * 0x100000001b3ull; }
// (integers are fed byte by byte, least significant first, so the result does not depend on
// the byte order of the machine)
void u64(uint64_t v) {
for (int i = 0; i < 8; i++) byte(uint8_t(v >> (i * 8)));
}
void i64(int64_t v) { u64(uint64_t(v)); }
};
} // namespace
uint64_t state_digest(const GameState& g, int32_t game_seed, uint32_t rand_seed) {
Fnv h;
// 1. everything that is saved, in the block order of the original
const Bytes stream = save_stream(g);
h.u64(stream.size());
for (uint8_t b : stream) h.byte(b);
// 2. the run-time values a savegame does not hold (GameState members marked "not saved")
h.i64(g.indoor);
h.i64(g.level);
h.i64(g.chance_rain);
h.i64(g.chance_temperature);
h.i64(g.last_shooter);
h.i64(g.last_pick_quality);
h.i64(g.live_scene);
h.u64(g.live_matches.size());
for (int team : g.live_matches) h.i64(team);
for (uint16_t home : g.sportschau_homes) h.u64(home);
for (uint8_t priority : g.sportschau_priorities) h.u64(priority);
h.i64(g.sportschau_selection_available);
h.i64(g.list_toggle);
h.i64(g.lineups_frozen);
h.i64(g.pools_open);
h.i64(g.autosave_months);
h.i64(g.autosave_month);
h.u64(g.date);
h.u64(g.season_start);
h.i64(g.season);
h.i64(g.development_balance);
h.i64(g.trend_rotation);
// 3. both random generators
h.i64(game_seed);
h.u64(rand_seed);
return h.value;
}
} // namespace bmh
+26
View File
@@ -0,0 +1,26 @@
// SPDX-License-Identifier: GPL-3.0-only
#pragma once
// A fingerprint of the complete game state, for behaviour-preserving refactoring.
//
// Two runs of the same career must produce the same digest after every turn. The digest covers
// - everything a savegame holds (the decrypted stream of save_stream: all state blocks and the
// four name pools), and
// - the run-time values that are not saved but steer later draws (the chance weather, the last
// shooter, the transfer list toggle, the autosave counters, ...).
// The states of the two random generators are passed in by the caller, because they do not belong
// to GameState.
//
// It is a regression tool only: the value has no meaning of its own and may change whenever the
// engine's behaviour is changed on purpose (then the reference files are simply recorded again).
#include <cstdint>
#include "game/state.hpp"
namespace bmh {
// FNV-1a (64 bit) over the saved stream and the unsaved run-time values of `g`, the game
// generator's seed and the Watcom generator's seed.
uint64_t state_digest(const GameState& g, int32_t game_seed, uint32_t rand_seed);
} // namespace bmh