Modern UI contract: live table in the paused kickoff

live_league_table is shared by the recording and the paused live state;
a paused league match now reports its league with the running scores.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ClaudeandClaude Opus 5.5 committed 2026-10-27 14:09:04 +01:00
1 parent eb5c5d6211
commit 6e400d708c
5 files changed
+92 -38

No files matched your search

+1 -1
View File
@@ -61,7 +61,7 @@ Die UI ruft diese über `DataSource::read_almanac` und `read_statistics` direkt
- `matches`: die Spiele mit menschlichem Manager (höchstens vier), `owners`: die Manager mit Team und `match_id` (`view` ist `null`; die Aufstellung kommt aus dem `lineup`-Read).
- `frames` in Minutenfolge: Anpfiff, jedes Ereignis (Tor, Chance, Karten, Verletzung, Wechsel, Elfmeter), Halbzeit, Wiederanpfiff, Abpfiff; je Spiel Stand, Chancen, Gelb, Rot, Elfmeter, Spieler auf dem Feld. `events` (fortlaufend) mit Überschrift und Satz, Spieler, Seite, Stand.
- `conference`: die übrigen Spiele des Tages im Almanach-Format.
- `standings` (Live-Tabelle) je Frame: pro Liga eines Ticker-Spiels die Tabelle vor dem Spieltag plus alle Spiele dieser Runde im Anstoß mit dem Stand der Minute (beim Abpfiff das gewertete Ergebnis); Zeilen mit `rank`, `previousRank`, `team`, `played`, `won`, `drawn`, `lost`, `goalsFor`, `goalsAgainst`, `points`. In der Aufzeichnung trägt ein Frame nur die Tabellen, die sich in ihm geändert haben (der erste alle); `kind: frame` liefert den vollständigen Stand bis dahin. Im angehaltenen Live-Anstoß noch ohne Tabelle. Fehler: `live_unavailable` (noch kein Anstoß), `live_no_human_match`, `stale_live_revision`, `stale_live_fixture`, `invalid_live_sequence`.
- `standings` (Live-Tabelle) je Frame: pro Liga eines Ticker-Spiels die Tabelle vor dem Spieltag plus alle Spiele dieser Runde im Anstoß mit dem Stand der Minute (beim Abpfiff das gewertete Ergebnis); Zeilen mit `rank`, `previousRank`, `team`, `played`, `won`, `drawn`, `lost`, `goalsFor`, `goalsAgainst`, `points`. In der Aufzeichnung trägt ein Frame nur die Tabellen, die sich in ihm geändert haben (der erste alle); `kind: frame` liefert den vollständigen Stand bis dahin. Der angehaltene Live-Anstoß liefert `standings` ebenso: je Ligagruppe mit einem Live-Spiel die Tabelle mit den Ständen der laufenden Spiele. Fehler: `live_unavailable` (noch kein Anstoß), `live_no_human_match`, `stale_live_revision`, `stale_live_fixture`, `invalid_live_sequence`.
- **Live mit Eingriffen:** `session.advance {live: true}` startet den Anstoß in einem eigenen Ablauf, der nach der ersten Minute eines laufenden Live-Spiels eines Menschen anhält (eine gewertete Partie, z. B. ein Forfeit, läuft ohne Halt durch). Solange er steht, liefert `read_live` `{live: true, status: "paused", minute, matches}`: je Live-Spiel Stand, Manager je Seite und die bisherigen Ereignisse (`goal`, `miss`, `yellow`, `second_yellow`, `red`, `injury` mit Minute, Seite, Spieler, Vorlage); Wechsel zeigt der `lineup`-Read. Die vollständige Aufzeichnung folgt nach dem Abpfiff. Alle anderen Befehle antworten `live_running`, bis der Spieltag vorbei ist.
## Commands
+19 -1
View File
@@ -8809,7 +8809,25 @@ cli::Json ModernSession::read_live(const cli::Json& request) const {
{"awayManagerId", am >= 0 ? cli::Json(modern::ui_manager_id(g_, am)) : cli::Json(nullptr)},
{"score", cli::Json::Array{cli::Json(h), cli::Json(a)}}});
}
return O{{"ok", true}, {"live", true}, {"status", "paused"}, {"minute", live_->minute}, {"matches", std::move(matches)}};
// the live tables: each league group with a live match, its matches at their score so far
// (the group's results reach the season's result bytes only after its final whistle)
cli::Json::Array standings;
for (const MatchGroup& grp : *live_->groups) {
const uint32_t league = grp.desc.size() >= 0xd0 ? le32(grp.desc, 0xcc) : 0xffffffffu;
if (league >= uint32_t(kLeagueCount) || grp.results.size() != size_t(grp.matches())) continue;
std::vector<modern::LiveGame> games;
bool live = false;
for (int m = 0; m < grp.matches(); ++m) {
const int home = grp.fixtures.at(size_t(m) * 2), away = grp.fixtures.at(size_t(m) * 2 + 1);
live |= std::find(g_.live_matches.begin(), g_.live_matches.end(), home) != g_.live_matches.end();
const int h = grp.results[size_t(m)] >> 4, a = grp.results[size_t(m)] & 0xf;
if (h < 0xc && a < 0xc) games.push_back({home, away, h, a});
}
if (live && league < g_.league_rounds.size())
standings.push_back(modern::live_league_table(g_, int(league), int(g_.league_rounds[league]) + 1, games));
}
return O{{"ok", true}, {"live", true}, {"status", "paused"}, {"minute", live_->minute}, {"matches", std::move(matches)},
{"standings", std::move(standings)}};
}
if (!ui_last_advance_) return fail("live_unavailable");
if (const cli::Json* r = ui_field(request, "revision"); r && (!r->integer() || uint64_t(*r->integer()) != ui_last_advance_revision_))
+44 -36
View File
@@ -784,6 +784,36 @@ const char* event_kind(AlmanacEventKind k) {
} // namespace
cli::Json live_league_table(const ModernState& g, int league, int round, const std::vector<LiveGame>& games) {
LeagueTable base;
if (round > 1) base = compute_league_table(g, league, 0, round - 1, 7, 1);
else base.league = league, base.size = int(kLeagueSizes[league]);
const int first = league_first_team(league);
LeagueTable t = base;
for (const LiveGame& game : games) {
const int club[2] = {game.home - first, game.away - first};
if (club[0] < 0 || club[0] >= t.size || club[1] < 0 || club[1] >= t.size) continue;
const uint8_t goals[2] = {uint8_t(game.home_goals), uint8_t(game.away_goals)};
add_result(t, club, goals, 3, 1);
}
sort_table(t, 0);
std::vector<int> order(size_t(t.size));
for (int i = 0; i < t.size; ++i) order[size_t(i)] = i;
std::stable_sort(order.begin(), order.end(), [&](int a, int b) { return t.rank(a) < t.rank(b); });
A rows;
for (int i : order) {
const int played = t.games(i), won = t.wins[size_t(i)], lost = t.defeats[size_t(i)];
std::string name = size_t(first + i) < g.world_club_name.size() ? g.world_club_name[size_t(first + i)] : std::string{};
if (name.empty()) name = almanac_utf8(g.club_name(first + i));
rows.push_back(O{{"rank", t.rank(i) + 1}, {"previousRank", round > 1 ? J(base.rank(i) + 1) : J(nullptr)},
{"team", O{{"id", ui_team_id(g, first + i)}, {"name", name}}}, {"played", played}, {"won", won},
{"drawn", std::max(0, played - won - lost)}, {"lost", lost}, {"goalsFor", int(t.goals_for[size_t(i)])},
{"goalsAgainst", int(t.goals_against[size_t(i)])}, {"points", int(t.points[size_t(i)])}});
}
const Competition c = league_competition(g.almanac.current, league);
return O{{"competitionId", c.id}, {"name", c.name}, {"round", round}, {"rows", std::move(rows)}};
}
cli::Json live_fixture(const ModernState& g, uint32_t after_date, uint32_t until_date, uint64_t revision) {
// the matches of the last kickoff (dates after_date <= d < until_date) from the almanac: the
// ones with a human manager are the ticker's matches (at most four), all others the conference
@@ -848,11 +878,9 @@ cli::Json live_fixture(const ModernState& g, uint32_t after_date, uint32_t until
// there (all of them on the first frame).
struct LiveLeague {
int league = 0, round = 0;
std::string id, name;
LeagueTable base;
std::vector<const AlmanacMatch*> games;
std::vector<std::array<int, 2>> at; // draw positions of each game's clubs
std::string last; // the scores the table was last built from
std::vector<std::array<int, 2>> teams; // runtime teams of each game
std::string last; // the scores the table was last built from
};
std::vector<LiveLeague> live_leagues;
for (const Ref& r : human) {
@@ -861,56 +889,36 @@ cli::Json live_fixture(const ModernState& g, uint32_t after_date, uint32_t until
if (std::any_of(live_leagues.begin(), live_leagues.end(), [&](const LiveLeague& l) { return l.league == m.league; })) continue;
LiveLeague l;
l.league = m.league, l.round = m.round;
const Competition c = competition_of(g, *r.season, m);
l.id = c.id, l.name = c.name;
if (m.round > 1) l.base = compute_league_table(g, m.league, 0, m.round - 1, 7, 1);
else l.base.league = m.league, l.base.size = int(kLeagueSizes[m.league]);
const int first = league_first_team(m.league);
std::map<std::string, int> position;
for (int c2 = 0; c2 < l.base.size; ++c2) position[ui_team_id(g, first + c2)] = c2;
std::map<std::string, int> team;
for (int t = first; t < first + int(kLeagueSizes[m.league]); ++t) team[ui_team_id(g, t)] = t;
for (const std::vector<Ref>* list : {&human, &others})
for (const Ref& o : *list) {
const AlmanacMatch& x = o.season->matches[o.index];
if (x.type != 0 || x.league != m.league || x.round != m.round) continue;
const auto h = position.find(o.season->clubs[x.home].id), a = position.find(o.season->clubs[x.away].id);
if (h == position.end() || a == position.end()) continue;
const auto h = team.find(o.season->clubs[x.home].id), a = team.find(o.season->clubs[x.away].id);
if (h == team.end() || a == team.end()) continue;
l.games.push_back(&x);
l.at.push_back({h->second, a->second});
l.teams.push_back({h->second, a->second});
}
live_leagues.push_back(std::move(l));
}
const auto live_table = [&](LiveLeague& l, int minute, bool final_whistle) -> J {
LeagueTable t = l.base;
std::vector<LiveGame> games;
std::string key;
for (size_t k = 0; k < l.games.size(); ++k) {
const AlmanacMatch& x = *l.games[k];
uint8_t goals[2] = {0, 0};
if (final_whistle) goals[0] = x.home_goals, goals[1] = x.away_goals;
LiveGame game{l.teams[k][0], l.teams[k][1], 0, 0};
if (final_whistle) game.home_goals = x.home_goals, game.away_goals = x.away_goals;
else
for (const auto& e : x.events)
if (e.kind == AlmanacEventKind::Goal && e.minute <= minute) ++goals[e.side ? 1 : 0];
const int club[2] = {l.at[k][0], l.at[k][1]};
if (minute > 0) add_result(t, club, goals, 3, 1);
key += std::to_string(goals[0]) + ":" + std::to_string(goals[1]) + ",";
if (e.kind == AlmanacEventKind::Goal && e.minute <= minute) ++(e.side ? game.away_goals : game.home_goals);
if (minute > 0) games.push_back(game);
key += std::to_string(game.home_goals) + ":" + std::to_string(game.away_goals) + ",";
}
if (key == l.last) return nullptr;
l.last = key;
sort_table(t, 0);
std::vector<int> order(size_t(t.size));
for (int i = 0; i < t.size; ++i) order[size_t(i)] = i;
std::stable_sort(order.begin(), order.end(), [&](int a, int b) { return t.rank(a) < t.rank(b); });
const int first = league_first_team(l.league);
A rows;
for (int i : order) {
const int games = t.games(i), won = t.wins[size_t(i)], lost = t.defeats[size_t(i)];
std::string name = size_t(first + i) < g.world_club_name.size() ? g.world_club_name[size_t(first + i)] : std::string{};
if (name.empty()) name = almanac_utf8(g.club_name(first + i));
rows.push_back(O{{"rank", t.rank(i) + 1}, {"previousRank", l.round > 1 ? J(l.base.rank(i) + 1) : J(nullptr)},
{"team", O{{"id", ui_team_id(g, first + i)}, {"name", name}}}, {"played", games}, {"won", won},
{"drawn", std::max(0, games - won - lost)}, {"lost", lost}, {"goalsFor", int(t.goals_for[size_t(i)])},
{"goalsAgainst", int(t.goals_against[size_t(i)])}, {"points", int(t.points[size_t(i)])}});
}
return O{{"competitionId", l.id}, {"name", l.name}, {"round", l.round}, {"rows", std::move(rows)}};
return live_league_table(g, l.league, l.round, games);
};
struct Tally { int score[2] = {0, 0}, chances[2] = {0, 0}, yellow[2] = {0, 0}, red[2] = {0, 0}, shootout[2] = {0, 0}; };
std::vector<Tally> tally(human.size());
+9
View File
@@ -12,6 +12,8 @@
// goals, assists, cards per player in one competition,
// of one season ("2026/27") or all seasons
#include <vector>
#include "cli/json.hpp"
#include "modern/game/modern_state.hpp"
@@ -42,6 +44,13 @@ cli::Json query_statistics_screen(const ModernState& g, int manager, const cli::
// day as the conference. source: "engine-recording".
cli::Json live_fixture(const ModernState& g, uint32_t after_date, uint32_t until_date, uint64_t revision);
// A game of a matchday under way: runtime teams and goals so far.
struct LiveGame { int home = 0, away = 0, home_goals = 0, away_goals = 0; };
// The live table of a league during matchday `round` (1-based): the table before it plus the
// given games. {competitionId, name, round, rows: [{rank, previousRank, team, played, won,
// drawn, lost, goalsFor, goalsAgainst, points}]}.
cli::Json live_league_table(const ModernState& g, int league, int round, const std::vector<LiveGame>& games);
// All recorded matches with from_date <= date < until_date in the almanac form (the matches of a kickoff).
cli::Json almanac_matches_between(const ModernState& g, uint32_t from_date, uint32_t until_date);
+19
View File
@@ -577,6 +577,8 @@ int main(int argc, char** argv) {
check(s(at(stepped, "messageType")) == "command_result" && at(state, "minute").integer() &&
*at(state, "minute").integer() >= 30, "thirty minutes on");
std::printf("(live state: %s)\n", cli::dump_json(state).substr(0, 400).c_str());
check(at(state, "standings").array() != nullptr, "the paused kickoff names its live tables");
std::printf("(paused live tables: %zu)\n", at(state, "standings").array() ? at(state, "standings").array()->size() : 0);
if (const auto* live = at(state, "matches").array(); live && !live->empty()) {
int goals = 0;
for (const auto& e : *at((*live)[0], "events").array()) goals += s(at(e, "kind")) == "goal";
@@ -611,6 +613,23 @@ int main(int argc, char** argv) {
}
check(s(at(session.ui_command(cmd("request:lz", "live.step", O{}), rev), "code")) == "live_not_running", "no live kickoff");
}
// a paused league match: its live table (the league as it stands with the scores so far)
{
bool seen = false;
for (int k = 0; k < 16 && !seen; ++k) {
session.ui_command(cmd("request:lt" + std::to_string(k), "session.advance", O{{"live", true}}), rev);
const J state = session.read_live(O{{"kind", "fixture"}});
if (!truth(at(state, "live"))) continue;
if (const auto* tables = at(state, "standings").array(); tables && !tables->empty()) {
const auto* rows = at(tables->front(), "rows").array();
seen = rows && rows->size() >= 10 && *at(rows->front(), "rank").integer() == 1;
std::printf("(paused league table: %s, %zu rows)\n", s(at(tables->front(), "name")).c_str(), rows ? rows->size() : 0);
check(seen, "the paused league match has its live table");
}
session.ui_command(cmd("request:ltf" + std::to_string(k), "live.finish", O{}), rev);
}
if (!seen) std::printf("(no paused league match on this path)\n");
}
// a season of kickoffs: running-out contracts stop the run with decision_pending and the
// player; the advance is sent again with the answer (here: release)
{