Fix Almanac shoot-out recording and verified legacy views (by Codex)
This commit is contained in:
1 parent
ddd4447563
commit
f9e8719b2d
11 files changed
+309
-28
No files matched your search
+1
-1
@@ -1215,7 +1215,7 @@ add_executable(modern_camp_tests tests/modern_camp_tests.cpp)
|
||||
target_link_libraries(modern_camp_tests PRIVATE bmh_season_modern)
|
||||
add_test(NAME modern_camp_tests COMMAND modern_camp_tests)
|
||||
add_executable(modern_almanac_tests tests/modern_almanac_tests.cpp)
|
||||
target_link_libraries(modern_almanac_tests PRIVATE bmh_season_modern)
|
||||
target_link_libraries(modern_almanac_tests PRIVATE bmh_modern_content)
|
||||
add_test(NAME modern_almanac_tests COMMAND modern_almanac_tests)
|
||||
add_executable(modern_toto_tests tests/modern_toto_tests.cpp)
|
||||
target_link_libraries(modern_toto_tests PRIVATE bmh_season_modern)
|
||||
|
||||
@@ -59,7 +59,7 @@ Für 0.3 gilt außerdem:
|
||||
| M5 | Datenrevision 1.4 des Modern-Datensatzes (privat), Wirtschaftsprüfung | erledigt: Revision 1.4 abgenommen (Lager, 100 Schiedsrichter, Geburtsdaten; siehe Phasen) |
|
||||
| M6 | Modern-Spielstände (`modern-career-v1`), Projektionen für die UI | Spielstände erledigt (Rundreise identisch); Projektionen offen |
|
||||
| M7 | Balance-Läufe und Anpassungen | erledigt: Spielerwerte nach Rangfolge, Langläufe über 12 Saisons ohne Drift gegenüber Classic ([Balance](balance.md)); offen nur Läufe mit aktivem Manager |
|
||||
| M8 | Fußball-Almanach: alle Spiele mit Ereignissen und Aufstellungen ([Almanach](almanach.md)) | Engine erledigt (Aufzeichnung, Spielstand, IDs); UI und Projektionen offen |
|
||||
| M8 | Fußball-Almanach: alle Spiele mit Ereignissen und Aufstellungen ([Almanach](almanach.md)) | Engine und Leseprojektionen vorhanden; nativer Almanach angeschlossen; Elfmeterschuss-Aufzeichnung und belegte Altarchive korrigiert (#18) |
|
||||
| M9 | Nationalteams mit echten Kadern ([Nationalteams](nationalteams.md)) | Engine erledigt: 24 von 61 Nationen des Diamond-Datensatzes spielen mit Spielern |
|
||||
|
||||
Details und Abnahmekriterien stehen in [Phasen](phasen.md).
|
||||
@@ -32,7 +32,7 @@ Pro Saison zusätzlich:
|
||||
## Woher die Daten kommen (keine Wirkung auf das Spiel)
|
||||
|
||||
- Tore, Fehlschüsse, Karten, Verletzungen: das Ereignisprotokoll der Spielgruppe (`MatchGroup::log`), das die Engine wie das Original für **jedes** Spiel führt.
|
||||
- Elfmeterschießen: die Show-Ereignisse der Match-Engine (das Protokoll hat keine Elfmeter); Modern sammelt sie jetzt immer.
|
||||
- Elfmeterschießen: die Tor-/Fehlschusspaare mit Minute 121 aus dem vollständigen Matchprotokoll. Show-Ereignisse sind nur ein Ersatz bei fehlendem Schussprotokoll; sichtbare und unbeobachtete Partien erhalten dieselbe Serie, ohne Doppelerfassung.
|
||||
- Wechsel: Vergleich der Spieler auf dem Platz nach jeder Minute. Damit werden auch Wechsel des menschlichen Managers (Bildschirm, Halbzeit) erfasst.
|
||||
- Aufstellung, Schiedsrichter, Wetter, Spieltag: beim Anpfiff; Ergebnis und Zuschauer nach dem Spieltag.
|
||||
- Der Almanach zieht keine Zufallszahlen und ändert nichts, was die Saisonlogik liest. Geprüft: Ein Modern-Lauf über 60 Züge ist mit und ohne Almanach identisch.
|
||||
@@ -71,3 +71,40 @@ keine F10-/OBS-Dateien und ändert keine Engine- oder Spielstanddaten.
|
||||
- Behoben (25.10.2026): Die Spiele der deutschen Nationalmannschaft fehlten ganz, weil ihre Team-Nummer (357) zugleich „kein Team“ ist und als Platzhalter aussortiert wurde.
|
||||
- Projektionen für die Almanach-Oberfläche.
|
||||
- Kompression: Version 3 spart gegenüber Version 2 rund ein Viertel (eine halbe Saison: Almanach 294 → 218 KB, Spielstand 501 → 432 KB). Den Rest belegen vor allem die Ereignisse; eine stärkere ZIP-Stufe brächte nur etwa 10 %.
|
||||
|
||||
## Korrektur der Elfmeterschießen · 28. Oktober 2026 · #18
|
||||
|
||||
Der Recorder trennte bisher die mit Minute 121 protokollierten Elfmeterschüsse
|
||||
nicht von normalen Toren/Fehlschüssen. Zusätzlich wurden dieselben Schüsse aus
|
||||
den Show-Ereignissen aufgenommen. Dadurch enthielt der Spielstand normale Tore
|
||||
inklusive Elfmetertreffern, während der abgeleitete Elfmeterstand 0:0 blieb.
|
||||
|
||||
Die Aufzeichnung erfasst jetzt jeden protokollierten Elfmeter genau einmal und
|
||||
zählt normale Tore sowie Elfmetertreffer getrennt. Die tatsächliche Schussserie
|
||||
bleibt auch dann vollständig, wenn `CupTie2` seine gepackte Ergebnisanzeige
|
||||
begrenzt. Die Berechnung der Partie, ihr gepacktes Ergebnis und beide RNGs
|
||||
werden dabei nicht geändert.
|
||||
|
||||
Für ältere betroffene Archive normalisiert die gemeinsame Leseprojektion nur
|
||||
**Kopien**: Beide vollständigen Schussfolgen müssen in Seite, Spieler und
|
||||
Treffer/Miss übereinstimmen, eine abgeschlossene zulässige Serie bilden und mit
|
||||
dem gespeicherten gepackten Endstand einschließlich dessen Begrenzung vereinbar
|
||||
sein. Nur dann werden die doppelten Tor-/Fehlschusseinträge in der Lesekopie
|
||||
entfernt und Spieltore/Elfmetertore getrennt. Rohdaten des geladenen Spielstands
|
||||
und abgeschlossener Saisons bleiben bytegleich. Unvollständige oder
|
||||
widersprüchliche Überlieferungen werden nicht geraten. Auch Torschützen- und
|
||||
andere Archivstatistiken verwenden die normalisierte Lesekopie.
|
||||
|
||||
Hallenturniere und Hallenmasters gehen nach 40 Minuten direkt ins Elfmeterschießen;
|
||||
die Projektion behauptet dort keine Verlängerung. Bei Feldspielen überschneiden
|
||||
sich protokollierte Minuten 91–93 aus Nachspielzeit und Verlängerung. Enthält eine
|
||||
verlängerte Partie solche Tore oder kein vollständiges Torprotokoll, bleiben die
|
||||
Teilstände für reguläre Zeit/Verlängerung unbekannt (`null`); der gespeicherte
|
||||
Endstand und eine belegte Schussserie bleiben verfügbar.
|
||||
|
||||
Es gibt keine OBW-/Editor-Formatänderung und keinen neuen F10-Binärstand. Die
|
||||
Versionsrundreisen bleiben unverändert. Die synthetische Prüfung deckt sichtbare
|
||||
und unbeobachtete Schussserien, Doppelerfassung, Ergebnisbegrenzung, alte
|
||||
laufende/abgeschlossene Saisons, Statistik, Hallenspiele und unklare Teilstände ab.
|
||||
Private Vergleichsläufe und GUI-Nachweise liegen unter
|
||||
`bmh_4k_ui/docs/qa/almanac-shootout-2026-10-28/`.
|
||||
@@ -98,3 +98,16 @@ Danach: `modern_season_sim` mit der neuen Welt (zwei Saisons, `SIM_CONTRACTS=1`)
|
||||
- Korrekturen zuerst in den Daten (etwa Werte der neu ergänzten Spieler, Preise), dann in Regeln; jede Regeländerung in [DIFFERENCES](../DIFFERENCES.md).
|
||||
|
||||
**Abnahme:** Bericht mit Kennzahlen und begründeten Anpassungen.
|
||||
|
||||
## M8 · Almanach: Anschluss und Schussserien
|
||||
|
||||
Die native Oberfläche liest Kalender, Tagespaarungen, Spielberichte und Ereignisse
|
||||
über die revisionsgebundene Modern-Sessionprojektion; die getrennte Demo bleibt
|
||||
eine eigene Quelle. Details stehen im [Almanach-Menü](../new_ui/desktop/almanac/README.md).
|
||||
|
||||
Nachbesserung vom 28. Oktober 2026 (#18): Der Recorder erfasst Elfmeterschüsse aus
|
||||
dem Matchprotokoll einmalig und getrennt von Spieltoren. Die Leseprojektion
|
||||
berichtigt eindeutig belegte ältere Doppelprotokolle in Kopien. Spielstandbytes,
|
||||
Spielentscheidungen und RNG bleiben unverändert. Hallen- und unklare
|
||||
Verlängerungs-Teilstände werden ausdrücklich behandelt. Format und Editor
|
||||
benötigen keine Anpassung; [Nachweise und Grenzen](almanach.md).
|
||||
@@ -35,8 +35,9 @@ Almanachaufzeichnungen im OBS, einschließlich der von der Engine verfügbaren
|
||||
abgeschlossenen Saisons. Es gibt keinen Import des Pseudoarchivs in eine OBS.
|
||||
|
||||
Die archivierten Namen und Aufstellungen werden unverändert übernommen.
|
||||
Fehlende Positionen bleiben unbekannt. Ein Enginebefund zu widersprüchlichen
|
||||
Phasenangaben ist als #18 erfasst. Die UI kennzeichnet ein gemeldetes,
|
||||
Fehlende Positionen bleiben unbekannt. Die Elfmeterschuss-Aufzeichnung und eindeutig belegte ältere Doppelprotokolle
|
||||
sind seit der Korrektur #18 berichtigt; alte Saisonbytes bleiben dabei erhalten.
|
||||
Nicht belegbare Alt-Phasen bleiben unbekannt. Die UI kennzeichnet ein gemeldetes,
|
||||
entschiedenes Elfmeterschießen mit gleichem Heim-/Auswärtswert als unklare
|
||||
Phasenüberlieferung und zeigt den gelieferten Endstand. Sie rekonstruiert kein
|
||||
Ersatzresultat. Die folgenden Demo-Validierungsdetails bleiben für den
|
||||
|
||||
@@ -57,12 +57,14 @@ aktiven Welt aufgelöst; das ist kein historisches Grafikarchiv. Der gemeinsame
|
||||
Wappenpfad unterstützt dabei den Silver-Kontrastfix.
|
||||
|
||||
Beim tatsächlichen Anschluss wurde [Engine-Issue #18](https://github.com/Weyoune/openbmh/issues/18)
|
||||
gefunden: einzelne abgeschlossene Datensätze melden ein Elfmeterschießen mit
|
||||
gefunden und am 28. Oktober im Recorder/Leser korrigiert: ältere Datensätze
|
||||
konnten ein Elfmeterschießen melden mit
|
||||
0:0. Der Presenter zeigt bei solchen widersprüchlichen Angaben den gelieferten
|
||||
Endstand und „Spielphasen nicht eindeutig überliefert“. Er erfindet weder
|
||||
Elfmeterschüsse noch eine Ersatzentscheidung. Die unveränderten Rohdaten
|
||||
bleiben im Prüfbeleg erhalten; der Recorder/Engine-Read muss separat geprüft
|
||||
werden. Andere gelieferte Phasenwerte werden ohne neue Spielregeln dargestellt.
|
||||
bleiben im Prüfbeleg erhalten. Der gemeinsame Engine-Read berichtigt jetzt
|
||||
eindeutig belegte Alt-Doppelprotokolle nur in Lesekopien; unklare Fälle behalten
|
||||
diese Kennzeichnung. Andere gelieferte Phasenwerte werden ohne neue Spielregeln dargestellt.
|
||||
|
||||
Öffnen, Jahrwechsel, Navigation und Speichern verändern keine Archivspiele
|
||||
oder RNG-Zustände. Die private QA enthält einen regulär erzeugten OBS-Stand
|
||||
@@ -202,3 +204,15 @@ und Fehlwertfälle wurden tatsächlich bedient. Bilder, Skripte, Inputs und
|
||||
Checkpoints liegen privat unter `bmh_4k_ui/docs/qa/almanac-2026-10-24/`.
|
||||
Die Belege betreffen Linux/OpenGL und Browser, keine vollständige native
|
||||
Windows-/macOS-Abnahme. Eine F10-/OBS-Anbindung ist weiterhin nicht enthalten.
|
||||
|
||||
## Elfmeterschuss-Korrektur · 28. Oktober 2026
|
||||
|
||||
Der Engine-Read liefert die nachweislich getrennten Spiel-/Elfmetertore und eine
|
||||
einmalige Schussserie. Damit zeigt auch der bereits gespeicherte Referenzfall
|
||||
`match:2026-446` regulär 0:0, Verlängerung 0:0 und Elfmeterschießen 2:4. Die
|
||||
vorhandenen Spielstand-/Archivbytes werden nicht umgeschrieben. Die UI behält die
|
||||
Kennzeichnung unklarer Phasen für nicht eindeutig rekonstruierbare Alt-Daten.
|
||||
Fehlende Teilstände werden als — dargestellt; direkte Hallen-Elfmeterschießen
|
||||
werden ohne behauptete Verlängerung angezeigt. [Engine-Details](../../../new_engine/almanach.md).
|
||||
Private Vorher-/Nachher-QA mit denselben OBS-Dateien:
|
||||
`bmh_4k_ui/docs/qa/almanac-shootout-2026-10-28/`.
|
||||
@@ -45,6 +45,10 @@ std::vector<AlmanacSeason> seasons_of(const ModernState& g) {
|
||||
std::vector<AlmanacSeason> out;
|
||||
for (const auto& [name, bytes] : g.almanac.finished) out.push_back(decode_almanac_season(bytes));
|
||||
if (g.almanac.current.season >= 0) out.push_back(g.almanac.current);
|
||||
// Work on query copies only: finished season bytes and the loaded career
|
||||
// remain immutable, including older saves affected by double-counted kicks.
|
||||
for (auto& season : out)
|
||||
for (auto& match : season.matches) modern::normalize_legacy_shootout(match);
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -309,7 +313,18 @@ J almanac_match(const ModernState& g, const AlmanacSeason& s, size_t index) {
|
||||
int regulation[2] = {0, 0};
|
||||
for (const auto& e : m.events)
|
||||
if (e.kind == AlmanacEventKind::Goal && e.minute <= 90 && e.side < 2) ++regulation[e.side];
|
||||
const bool extra = m.decided >= 1, shootout = m.decided == 2;
|
||||
const bool shootout = m.decided == 2;
|
||||
const bool indoor = m.type == 12 || m.type == 13; // indoor cup / masters: 2 x 20, then penalties
|
||||
const bool extra = m.decided >= 1 && !indoor;
|
||||
int goals[2] = {};
|
||||
bool ambiguous_stoppage = false;
|
||||
for (const auto& e : m.events) if (e.kind == AlmanacEventKind::Goal && e.side < 2) {
|
||||
++goals[e.side];
|
||||
// Both regular stoppage time and the first extra-time minutes use
|
||||
// 91..93. F10 has no phase tag; do not invent a 90-minute score there.
|
||||
if (e.minute > 90 && e.minute <= 93) ambiguous_stoppage = true;
|
||||
}
|
||||
const bool split_known = goals[0] == m.home_goals && goals[1] == m.away_goals && !ambiguous_stoppage;
|
||||
J lineups = O{};
|
||||
for (int side = 0; side < 2; ++side) {
|
||||
const auto& l = m.lineup[size_t(side)];
|
||||
@@ -328,8 +343,8 @@ J almanac_match(const ModernState& g, const AlmanacSeason& s, size_t index) {
|
||||
return O{{"id", match_id(s, index)}, {"date", iso_date(m.date, s.display_start_year)}, {"season", season_label(s.start_year)},
|
||||
{"competition", O{{"id", c.id}, {"name", c.name}, {"type", type}}}, {"round", int(m.round)},
|
||||
{"home", almanac_side(g, s, m.home, m.home_manager)}, {"away", almanac_side(g, s, m.away, m.away_manager)},
|
||||
{"result", O{{"regulation", extra ? J(A{J(regulation[0]), J(regulation[1])}) : J(A{J(int(m.home_goals)), J(int(m.away_goals))})},
|
||||
{"extra", extra ? J(A{J(int(m.home_goals) - regulation[0]), J(int(m.away_goals) - regulation[1])}) : J(nullptr)},
|
||||
{"result", O{{"regulation", extra ? (split_known ? J(A{J(regulation[0]), J(regulation[1])}) : J(nullptr)) : J(A{J(int(m.home_goals)), J(int(m.away_goals))})},
|
||||
{"extra", extra && split_known ? J(A{J(int(m.home_goals) - regulation[0]), J(int(m.away_goals) - regulation[1])}) : J(nullptr)},
|
||||
{"penalties", shootout ? J(A{J(int(m.home_shootout)), J(int(m.away_shootout))}) : J(nullptr)},
|
||||
{"final", A{J(int(m.home_goals)), J(int(m.away_goals))}}, {"extra_played", extra}, {"penalties_played", shootout}}},
|
||||
{"referee", m.referee > 0 && m.referee < s.referees.size() ? J(s.referees[m.referee]) : J(nullptr)},
|
||||
|
||||
+75
-12
@@ -488,6 +488,51 @@ void new_player_identity(ModernState& g, int player) {
|
||||
g.world_player_id[size_t(player)] = "player:gen-" + std::to_string(++g.almanac.generated_players);
|
||||
}
|
||||
|
||||
bool normalize_legacy_shootout(AlmanacMatch& match) {
|
||||
if (match.decided != 2 || match.home_shootout || match.away_shootout) return false;
|
||||
std::vector<const AlmanacEvent*> log, shown;
|
||||
int normal[2] = {}, penalties[2] = {}, taken[2] = {};
|
||||
for (const auto& e : match.events) {
|
||||
if (e.side > 1) return false;
|
||||
if ((e.kind == AlmanacEventKind::Goal || e.kind == AlmanacEventKind::Miss) && e.minute == 121) {
|
||||
if (e.other != kAlmanacNone || e.detail != 0) return false;
|
||||
log.push_back(&e);
|
||||
} else if (e.kind == AlmanacEventKind::Goal) ++normal[e.side];
|
||||
if (e.kind == AlmanacEventKind::ShootoutKick) shown.push_back(&e);
|
||||
}
|
||||
if (log.empty() || log.size() != shown.size()) return false;
|
||||
for (size_t i = 0; i < log.size(); ++i) {
|
||||
const auto& l = *log[i];
|
||||
const auto& s = *shown[i];
|
||||
const bool goal = l.kind == AlmanacEventKind::Goal;
|
||||
if (s.minute != 121 || s.side != l.side || s.player != l.player ||
|
||||
s.detail != (goal ? 1 : 0) || l.side != (log[0]->side ^ (i & 1))) return false;
|
||||
++taken[l.side];
|
||||
if (goal) ++penalties[l.side];
|
||||
bool ended = false;
|
||||
if (taken[0] <= 5 && taken[1] <= 5)
|
||||
ended = penalties[0] > penalties[1] + 5 - taken[1] || penalties[1] > penalties[0] + 5 - taken[0];
|
||||
else if (taken[0] == taken[1]) ended = penalties[0] != penalties[1];
|
||||
if (ended != (i + 1 == log.size())) return false;
|
||||
}
|
||||
if (normal[0] > 31 || normal[1] > 31 || penalties[0] > 12 || penalties[1] > 12) return false;
|
||||
// Verify the old CupTie2 packing, including its total/side limits. The
|
||||
// complete event streams still retain the actual goals before that clamp.
|
||||
int packed_home = normal[0] + penalties[0], packed_away = normal[1] + penalties[1];
|
||||
while (packed_home + packed_away > 29) --packed_home, --packed_away;
|
||||
packed_home = std::clamp(packed_home, 0, 15);
|
||||
packed_away = std::clamp(packed_away, 0, 15);
|
||||
if (packed_home != match.home_goals || packed_away != match.away_goals) return false;
|
||||
match.home_goals = uint8_t(normal[0]);
|
||||
match.away_goals = uint8_t(normal[1]);
|
||||
match.home_shootout = uint8_t(penalties[0]);
|
||||
match.away_shootout = uint8_t(penalties[1]);
|
||||
std::erase_if(match.events, [](const AlmanacEvent& e) {
|
||||
return e.minute == 121 && (e.kind == AlmanacEventKind::Goal || e.kind == AlmanacEventKind::Miss);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
// --- recording -------------------------------------------------------------------------
|
||||
|
||||
AlmanacRecorder::AlmanacRecorder(ModernState& g, const std::vector<MatchGroup>& groups) : g_(g), groups_(groups) {
|
||||
@@ -619,6 +664,7 @@ void AlmanacRecorder::after_minute(int minute) {
|
||||
|
||||
void AlmanacRecorder::finish(const std::vector<ShowEvent>& shown) {
|
||||
std::vector<std::vector<AlmanacEvent>> events(running_.size());
|
||||
std::vector<bool> logged_shootout(running_.size(), false);
|
||||
std::map<std::pair<size_t, int>, size_t> by_match;
|
||||
for (size_t i = 0; i < running_.size(); ++i) by_match[{running_[i].group, running_[i].match}] = i;
|
||||
auto ref = [&](int player) { return player >= 0 && player < 0x0fff ? player_ref(player) : kAlmanacNone; };
|
||||
@@ -653,9 +699,20 @@ void AlmanacRecorder::finish(const std::vector<ShowEvent>& shown) {
|
||||
e.player = ref(player);
|
||||
switch (code) {
|
||||
case 0: case 1:
|
||||
e.kind = code == 0 ? AlmanacEventKind::Goal : AlmanacEventKind::Miss;
|
||||
e.detail = uint8_t(detail);
|
||||
e.other = ref(assistant);
|
||||
// CupTie2 uses the same log codes for its kicks. Minute
|
||||
// 121 is reserved for the shoot-out; the normal extra-time
|
||||
// driver ends at that minute before playing another chance.
|
||||
if (value == 121 && groups_[gi].results.empty() &&
|
||||
size_t(running_[it->second].match) < groups_[gi].cup_results.size() &&
|
||||
(groups_[gi].cup_results.at(size_t(running_[it->second].match)) >> 10 & 3) == 2) {
|
||||
e.kind = AlmanacEventKind::ShootoutKick;
|
||||
e.detail = code == 0 ? 1 : 0;
|
||||
logged_shootout[it->second] = true;
|
||||
} else {
|
||||
e.kind = code == 0 ? AlmanacEventKind::Goal : AlmanacEventKind::Miss;
|
||||
e.detail = uint8_t(detail);
|
||||
e.other = ref(assistant);
|
||||
}
|
||||
break;
|
||||
case 3: e.kind = AlmanacEventKind::YellowCard; break;
|
||||
case 4: e.kind = AlmanacEventKind::SecondYellow; break;
|
||||
@@ -666,11 +723,14 @@ void AlmanacRecorder::finish(const std::vector<ShowEvent>& shown) {
|
||||
events[it->second].push_back(e);
|
||||
}
|
||||
}
|
||||
// The kicks of a shoot-out (the log has none): the show events of the match engine.
|
||||
// A presentation-only caller may supply just show events. The complete
|
||||
// match log is authoritative when present, so visible matches never double
|
||||
// their kicks and background matches do not depend on presentation events.
|
||||
for (const ShowEvent& s : shown) {
|
||||
if (s.what != Show::PenaltyKick) continue;
|
||||
const auto it = by_match.find({size_t(s.group), int(s.match)});
|
||||
if (it == by_match.end()) continue;
|
||||
if (logged_shootout[it->second]) continue;
|
||||
AlmanacEvent e;
|
||||
e.kind = AlmanacEventKind::ShootoutKick;
|
||||
e.minute = uint8_t(std::clamp<int>(s.minute, 0, 255));
|
||||
@@ -698,17 +758,20 @@ void AlmanacRecorder::finish(const std::vector<ShowEvent>& shown) {
|
||||
AlmanacMatch& rec = r.record;
|
||||
rec.events = std::move(events[i]);
|
||||
if (group.results.empty()) rec.decided = uint8_t(group.cup_results[size_t(m)] >> 10 & 3);
|
||||
// After a shoot-out the stored score includes its goals (CupTie2): the goals of the
|
||||
// match are those of the log, the rest were scored in the shoot-out.
|
||||
// CupTie2's packed score adds (and may clamp) shoot-out goals. Archive
|
||||
// the actual two event streams separately, without changing that score.
|
||||
if (rec.decided == 2) {
|
||||
int goals[2] = {0, 0};
|
||||
for (const AlmanacEvent& e : rec.events)
|
||||
int goals[2] = {0, 0}, penalties[2] = {0, 0};
|
||||
for (const AlmanacEvent& e : rec.events) if (e.side < 2) {
|
||||
if (e.kind == AlmanacEventKind::Goal) ++goals[e.side];
|
||||
rec.home_shootout = uint8_t(std::max(0, home - goals[0]));
|
||||
rec.away_shootout = uint8_t(std::max(0, away - goals[1]));
|
||||
if (e.kind == AlmanacEventKind::ShootoutKick && e.detail == 1) ++penalties[e.side];
|
||||
}
|
||||
home = goals[0], away = goals[1];
|
||||
rec.home_shootout = uint8_t(penalties[0]);
|
||||
rec.away_shootout = uint8_t(penalties[1]);
|
||||
}
|
||||
rec.home_goals = uint8_t(std::max(0, home - rec.home_shootout));
|
||||
rec.away_goals = uint8_t(std::max(0, away - rec.away_shootout));
|
||||
rec.home_goals = uint8_t(home);
|
||||
rec.away_goals = uint8_t(away);
|
||||
if (size_t(m) < group.spectators.size()) rec.attendance = group.spectators[size_t(m)];
|
||||
season.matches.push_back(std::move(rec));
|
||||
}
|
||||
|
||||
@@ -179,6 +179,11 @@ std::string encode_almanac_season(const AlmanacSeason& season);
|
||||
// Throws FormatError when the bytes are not an almanac season of a known version.
|
||||
AlmanacSeason decode_almanac_season(const std::string& bytes);
|
||||
|
||||
// Repair the old double recording of shoot-out kicks in a presentation copy.
|
||||
// Only a complete, matching log/show pair with consistent totals qualifies.
|
||||
// Uncertain records and the saved season bytes remain untouched.
|
||||
bool normalize_legacy_shootout(AlmanacMatch& match);
|
||||
|
||||
// A player index now belongs to a new person (retirement or youth player): gives it a new
|
||||
// stable identity so the almanac does not merge the two careers.
|
||||
void new_player_identity(ModernState& g, int player);
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
// The football almanac (docs/new_engine/almanach.md, M8) on synthetic data: the binary
|
||||
// season round trip, damaged input, the calendar dates and new player identities.
|
||||
// season round trip, damaged input, dates/identities, shoot-out recording and read-only
|
||||
// legacy normalization through the actual statistics projection.
|
||||
#include <cstdio>
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
|
||||
#include "formats/binary.hpp"
|
||||
#include "game/match_engine.hpp"
|
||||
#include "game/world_layout.hpp"
|
||||
#include "modern/content/statistics.hpp"
|
||||
#include "modern/game/almanac.hpp"
|
||||
#include "modern/game/modern_state.hpp"
|
||||
|
||||
@@ -20,6 +25,85 @@ void check(bool ok, const char* what) {
|
||||
}
|
||||
}
|
||||
|
||||
AlmanacMatch recorded_shootout(bool with_log, bool with_show, bool capped = false) {
|
||||
ModernState g;
|
||||
g.season = 0; g.display_start_year = 2026;
|
||||
const int home = first_foreign_cup(), away = home + 1;
|
||||
g.world_club_id.resize(size_t(away + 1)); g.world_club_name.resize(size_t(away + 1));
|
||||
g.world_club_id[size_t(home)] = "club:a"; g.world_club_name[size_t(home)] = "A";
|
||||
g.world_club_id[size_t(away)] = "club:b"; g.world_club_name[size_t(away)] = "B";
|
||||
std::vector<MatchGroup> groups(1);
|
||||
auto& group = groups[0];
|
||||
group.desc.resize(0xd0); group.desc[0] = 2;
|
||||
group.fixtures = {home, away}; group.spectators = {12345};
|
||||
const int normal = capped ? 5 : 1;
|
||||
const int combined_home = capped ? 15 : 5, combined_away = capped ? 14 : 4;
|
||||
group.cup_results = {uint16_t(0x800 | combined_home << 5 | combined_away)};
|
||||
AlmanacRecorder recorder(g, groups);
|
||||
const auto log = [&](int side, bool goal, int minute) {
|
||||
const int team = side ? away : home;
|
||||
group.log.insert(group.log.end(), {uint16_t(0xfff + (goal ? 0 : 0x1000)),
|
||||
uint16_t(team * 0x80 + minute), uint16_t(0x2fff), uint16_t(team * 0x80 + 1)});
|
||||
};
|
||||
for (int n = 0; n < normal; ++n) { log(0, true, 10+n); log(1, true, 70+n); }
|
||||
std::vector<ShowEvent> shown;
|
||||
const auto kick = [&](int side, bool goal) {
|
||||
if (with_log) log(side, goal, 121);
|
||||
if (with_show) {
|
||||
ShowEvent e{Show::PenaltyKick}; e.group = 0; e.match = 0; e.minute = 121;
|
||||
e.side = uint8_t(side); e.flag = goal; e.player = 0xfff; shown.push_back(e);
|
||||
}
|
||||
};
|
||||
if (capped) {
|
||||
for (int i = 0; i < 12; ++i) { kick(0, true); kick(1, i != 11); }
|
||||
} else {
|
||||
const bool h[5] = {true,true,false,true,true}, a[5] = {true,false,true,true,false};
|
||||
for (int i=0;i<5;++i) { kick(0,h[i]); kick(1,a[i]); }
|
||||
}
|
||||
const auto packed = group.cup_results;
|
||||
recorder.finish(shown);
|
||||
check(group.cup_results == packed, "recorder never rewrites packed match scores");
|
||||
return g.almanac.current.matches.at(0);
|
||||
}
|
||||
|
||||
void check_shootout_recording() {
|
||||
const auto both=recorded_shootout(true,true), background=recorded_shootout(true,false),
|
||||
shown_only=recorded_shootout(false,true), capped=recorded_shootout(true,true,true);
|
||||
check(both==background && both==shown_only, "visible/background/show-only shoot-outs agree");
|
||||
check(both.home_goals==1 && both.away_goals==1 && both.home_shootout==4 && both.away_shootout==3,
|
||||
"normal and shoot-out goals stay separate");
|
||||
check(both.events.size()==12 && std::count_if(both.events.begin(),both.events.end(),[](const auto& e){return e.kind==AlmanacEventKind::ShootoutKick;})==10,
|
||||
"each logged/shown kick is recorded exactly once");
|
||||
check(std::none_of(both.events.begin(),both.events.end(),[](const auto& e){return e.minute==121 && e.kind!=AlmanacEventKind::ShootoutKick;}),
|
||||
"shoot-out misses and goals do not become normal match events");
|
||||
check(capped.home_goals==5 && capped.away_goals==5 && capped.home_shootout==12 && capped.away_shootout==11,
|
||||
"packed-score clamping cannot erase actual shoot-out goals");
|
||||
|
||||
auto legacy=both;
|
||||
legacy.home_goals=5; legacy.away_goals=4; legacy.home_shootout=legacy.away_shootout=0;
|
||||
std::vector<AlmanacEvent> duplicates;
|
||||
for(const auto& e:both.events)if(e.kind==AlmanacEventKind::ShootoutKick) {
|
||||
auto copy=e;copy.kind=e.detail?AlmanacEventKind::Goal:AlmanacEventKind::Miss;copy.detail=0;duplicates.push_back(copy);
|
||||
}
|
||||
legacy.events.insert(legacy.events.begin()+2,duplicates.begin(),duplicates.end());
|
||||
const auto original=legacy;
|
||||
check(normalize_legacy_shootout(legacy) && legacy==both, "exact legacy duplicate signature is recoverable");
|
||||
check(!normalize_legacy_shootout(legacy), "legacy normalization is idempotent");
|
||||
auto legacy_capped=capped;
|
||||
legacy_capped.home_goals=15;legacy_capped.away_goals=14;legacy_capped.home_shootout=legacy_capped.away_shootout=0;
|
||||
std::vector<AlmanacEvent> capped_duplicates;
|
||||
for(const auto& e:capped.events)if(e.kind==AlmanacEventKind::ShootoutKick){auto copy=e;copy.kind=e.detail?AlmanacEventKind::Goal:AlmanacEventKind::Miss;copy.detail=0;capped_duplicates.push_back(copy);}
|
||||
legacy_capped.events.insert(legacy_capped.events.begin()+10,capped_duplicates.begin(),capped_duplicates.end());
|
||||
check(normalize_legacy_shootout(legacy_capped)&&legacy_capped==capped,"complete legacy sources also recover clamped shoot-out scores");
|
||||
auto uncertain=original;uncertain.events.back().player=7;
|
||||
const auto uncertain_before=uncertain;
|
||||
check(!normalize_legacy_shootout(uncertain) && uncertain==uncertain_before, "disagreeing legacy sources remain unchanged");
|
||||
uncertain=original;uncertain.events.pop_back();
|
||||
const auto partial=uncertain;
|
||||
check(!normalize_legacy_shootout(uncertain) && uncertain==partial, "partial legacy series is not guessed");
|
||||
|
||||
}
|
||||
|
||||
AlmanacSeason sample() {
|
||||
AlmanacSeason s;
|
||||
s.season = 3, s.start_year = 2029, s.display_start_year = 2026;
|
||||
@@ -102,7 +186,48 @@ std::string encode_version_2(const AlmanacSeason& s) {
|
||||
}
|
||||
} // namespace
|
||||
|
||||
const cli::Json& field(const cli::Json& j,const char* key) { return j.object()->at(key); }
|
||||
void check_shootout_projection() {
|
||||
auto match=recorded_shootout(true,true);
|
||||
auto season=sample();season.season=0;season.start_year=2026;season.matches={match};
|
||||
// Valid historical player references let the same read prove that penalty
|
||||
// takers do not acquire normal goals in the statistics projection.
|
||||
for(auto& e:season.matches[0].events)e.player=e.side;
|
||||
auto& legacy=season.matches[0];
|
||||
legacy.home_goals=5;legacy.away_goals=4;legacy.home_shootout=legacy.away_shootout=0;
|
||||
std::vector<AlmanacEvent> duplicate;
|
||||
for(const auto& e:legacy.events)if(e.kind==AlmanacEventKind::ShootoutKick){auto copy=e;copy.kind=e.detail?AlmanacEventKind::Goal:AlmanacEventKind::Miss;copy.detail=0;duplicate.push_back(copy);}
|
||||
legacy.events.insert(legacy.events.begin()+2,duplicate.begin(),duplicate.end());
|
||||
ModernState g;g.season=0;g.display_start_year=2026;g.almanac.current=season;
|
||||
const auto bytes=encode_almanac_season(season);
|
||||
const auto read=[&]{return query_almanac(g,cli::Json::Object{{"kind","match"},{"id","match:2026-0"}});};
|
||||
const auto result=read();const auto& scores=field(field(result,"match"),"result");
|
||||
check(*field(scores,"final").array()->at(0).integer()==1 && *field(scores,"penalties").array()->at(0).integer()==4,
|
||||
"legacy running-season query separates scores");
|
||||
const auto stats=query_statistics(g,cli::Json::Object{{"kind","player_stats"},{"competition","cup:1"}});
|
||||
const auto* players=field(stats,"players").array();
|
||||
check(players&&players->size()==2&&*field(players->at(0),"goals").integer()==1&&*field(players->at(1),"goals").integer()==1,
|
||||
"shoot-out hits are excluded from old-season scorer statistics");
|
||||
check(encode_almanac_season(g.almanac.current)==bytes,"query normalization leaves running-season bytes unchanged");
|
||||
g.almanac.current=AlmanacSeason{};g.almanac.finished={{"history/season-2026.bin",bytes}};
|
||||
const auto finished=read();
|
||||
check(cli::dump_json(finished)==cli::dump_json(result)&&g.almanac.finished[0].second==bytes,
|
||||
"finished-season query repairs view without rewriting history bytes");
|
||||
|
||||
g.almanac.finished.clear();g.almanac.current=season;
|
||||
auto& m=g.almanac.current.matches[0];m=match;m.type=12;m.events[1].minute=30;
|
||||
const auto indoor=read();const auto& ir=field(field(indoor,"match"),"result");
|
||||
check(!std::get<bool>(field(ir,"extra_played").value)&&std::holds_alternative<std::nullptr_t>(field(ir,"extra").value)&&std::get<bool>(field(ir,"penalties_played").value),
|
||||
"indoor shoot-out does not invent extra time");
|
||||
m=match;m.events[0].minute=91;
|
||||
const auto ambiguous=read();const auto& ar=field(field(ambiguous,"match"),"result");
|
||||
check(std::holds_alternative<std::nullptr_t>(field(ar,"regulation").value)&&std::holds_alternative<std::nullptr_t>(field(ar,"extra").value),
|
||||
"overlapping stoppage/extra-time goal minute has unknown partial score");
|
||||
}
|
||||
|
||||
int main() {
|
||||
check_shootout_recording();
|
||||
check_shootout_projection();
|
||||
const AlmanacSeason s = sample();
|
||||
const std::string bytes = encode_almanac_season(s);
|
||||
const AlmanacSeason back = decode_almanac_season(bytes);
|
||||
|
||||
@@ -11,8 +11,8 @@ using namespace bmh::modern_ui;
|
||||
int main(int argc, char **argv) {
|
||||
try {
|
||||
const std::string mode=argc>1?argv[1]:"";
|
||||
const std::set<std::string> modes{"prepare","prepare-two","prepare-national","prepare-almanac","inspect","inspect-friendlies","inspect-almanac","verify","verify-lineup","verify-sports","verify-bank","verify-commerce","verify-contracts","verify-calendar","verify-friendlies","verify-national","verify-almanac"};
|
||||
if(argc!=4||!modes.contains(mode))throw std::runtime_error("usage: modern_engine_bridge_probe <prepare[-two|-national|-almanac]|inspect[-friendlies|-almanac]|verify[-lineup|-sports|-bank|-commerce|-contracts|-calendar|-friendlies|-national|-almanac]> <world.obw> <new-output-directory>");
|
||||
const std::set<std::string> modes{"prepare","prepare-two","prepare-national","prepare-almanac","inspect","inspect-friendlies","inspect-almanac","verify","verify-lineup","verify-sports","verify-bank","verify-commerce","verify-contracts","verify-calendar","verify-friendlies","verify-national","verify-almanac","verify-shootouts"};
|
||||
if(argc!=4||!modes.contains(mode))throw std::runtime_error("usage: modern_engine_bridge_probe <prepare[-two|-national|-almanac]|inspect[-friendlies|-almanac]|verify[-lineup|-sports|-bank|-commerce|-contracts|-calendar|-friendlies|-national|-almanac|-shootouts]> <world.obw> <new-output-directory>");
|
||||
const fs::path world = argv[2], out = argv[3]; fs::create_directories(out);
|
||||
const auto write = [&](const char *file, const Json &j) { editor::write_atomic(out / file, j.dump(2)); };
|
||||
if (mode == "prepare-almanac" || std::string(argv[1]) == "prepare-national" || std::string(argv[1]) == "prepare" || std::string(argv[1]) == "prepare-two") {
|
||||
@@ -277,7 +277,7 @@ int main(int argc, char **argv) {
|
||||
for(const auto *kind:{"friendly-plan","calendar"})if(loaded.at(kind).at("data")!=after.at(kind).at("data"))throw std::runtime_error("national plan/calendar lost on restart");
|
||||
if(loaded.at("desktop").at("data").at("accounts")!=after.at("desktop").at("data").at("accounts"))throw std::runtime_error("national funds lost on restart");
|
||||
}
|
||||
if(mode=="inspect-almanac"||mode=="verify-almanac") {
|
||||
if(mode=="inspect-almanac"||mode=="verify-almanac"||mode=="verify-shootouts") {
|
||||
const auto run=[&](const Json &q){const auto read=link->read({{"kind","almanac"},{"query",q}});if(link->read({{"kind","almanac"},{"query",q}})!=read)throw std::runtime_error("archive read changed on repeat");return std::pair{read,engine_almanac_projection(before,read,q)};};
|
||||
const auto [index_read,index]=run({{"kind","index"}});write("index-read.json",index_read);
|
||||
Json catalogue=Json::array();int total=0;
|
||||
@@ -285,7 +285,15 @@ int main(int argc, char **argv) {
|
||||
const auto [cr,calendar]=run({{"kind","calendar"},{"year",year}});write(("calendar-"+std::to_string(year.get<int>())+".json").c_str(),cr);
|
||||
for(const auto &day:calendar.at("days")) {
|
||||
const auto [dr,d]=run({{"kind","day"},{"date",day.at("date")}});if(d.at("matches").size()!=size_t(day.at("count").get<int>()))throw std::runtime_error("archive day count mismatch");total+=day.at("count").get<int>();
|
||||
for(const auto &m:d.at("matches"))catalogue.push_back({{"id",m.at("id")},{"date",m.at("date")},{"home",m.at("home")},{"away",m.at("away")},{"result",m.at("result")},{"events",m.at("events").size()},{"competition",m.at("competition")}});
|
||||
for(const auto &m:d.at("matches")) {
|
||||
if(mode=="verify-shootouts") {
|
||||
int goals[2]={},penalties[2]={};int kicks=0;
|
||||
for(const auto &e:m.at("events")){const int side=e.at("side")=="away"?1:0;if(e.at("kind")=="goal"){if(e.at("minute")==121)throw std::runtime_error("shoot-out goal counted as normal goal");++goals[side];}if(e.at("kind")=="shootout"){++kicks;if(e.at("detail")==1)++penalties[side];}}
|
||||
if(m.at("result").at("final")!=Json::array({goals[0],goals[1]}))throw std::runtime_error("normal goals differ from recorded match events");
|
||||
if(m.at("result").at("penalties_played")==true && (!kicks||penalties[0]==penalties[1]||m.at("result").at("penalties")!=Json::array({penalties[0],penalties[1]})))throw std::runtime_error("shoot-out score differs from actual kicks");
|
||||
}
|
||||
catalogue.push_back({{"id",m.at("id")},{"date",m.at("date")},{"home",m.at("home")},{"away",m.at("away")},{"result",m.at("result")},{"events",m.at("events").size()},{"competition",m.at("competition")}});
|
||||
}
|
||||
}
|
||||
}
|
||||
if(total!=index.at("match_count"))throw std::runtime_error("archive index count differs from calendars");write("catalogue.json",catalogue);
|
||||
|
||||
Reference in new issue
Block a user