Liven up the match day: varied ticker wording, whistles, results of the day, eleven of the day

The ticker picks its sentence from several variants by the event's facts
and names equalisers, leads and late goals; kickoff, half time and the
final whistle are reported, with the same wording while the kickoff runs
live. The ticker's third tab lists the other results of the day. Modern
chooses an eleven of the day per league from the recorded match facts and
the review shows it.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
MichaelandClaude Fable 5.2 committed 2026-11-14 11:34:47 +01:00
1 parent 333bc57526
commit 1732a2477b
11 files changed
+288 -24

No files matched your search

+159 -16
View File
@@ -850,29 +850,75 @@ cli::Json query_rankings(const ModernState& g, int manager, const cli::Json& req
// --- the live ticker of the Modern UI: the recorded matches of the last kickoff ---------------
// The ticker's wording of one event. The sentence is picked from a few variants by the
// event's own facts (minute, side, kind), so the same match always reads the same and no
// random number of the game is drawn. `home`/`away` is the score after the event.
std::pair<std::string, std::string> ticker_phrase(int kind, const std::string& team, const std::string& who,
const std::string& other, int detail, int minute, int home, int away,
bool away_side) {
const std::string score = std::to_string(home) + ":" + std::to_string(away);
const std::string player = who.empty() ? team : who;
const auto pick = [&](std::initializer_list<const char*> variants) {
const size_t n = variants.size();
uint32_t hash = 2166136261u; // FNV-1a over the player's name, the minute, the kind and the side
for (unsigned char c : player) hash = (hash ^ c) * 16777619u;
for (unsigned v : {unsigned(minute), unsigned(kind), away_side ? 1u : 0u}) hash = (hash ^ v) * 16777619u;
const size_t at = size_t(hash >> 7) % n;
return std::string(*(variants.begin() + at));
};
const auto fill = [&](std::string text) {
for (const auto& [key, value] : {std::pair<const char*, const std::string&>{"%p", player}, {"%t", team}, {"%s", score}, {"%o", other}})
for (size_t at = text.find(key); at != std::string::npos; at = text.find(key, at + value.size())) text.replace(at, 2, value);
return text;
};
switch (AlmanacEventKind(kind)) {
case AlmanacEventKind::Goal: {
const int own = away_side ? away : home, theirs = away_side ? home : away;
std::string headline = own == theirs ? "Ausgleich für " + team
: own == theirs + 1 ? "Führung für " + team
: own > theirs + 2 ? team + " zieht davon"
: own == theirs - 1 ? "Anschlusstreffer für " + team
: "Tor für " + team;
std::string body = detail == 1 ? pick({"%p verwandelt den ruhenden Ball zum %s.", "%p trifft nach einem Standard zum %s."})
: detail == 2 ? pick({"%p staubt zum %s ab.", "%p ist beim Nachschuss zur Stelle: %s."})
: detail == 3 ? pick({"%p trifft nach einer Ecke zum %s.", "Ecke, Abschluss, Tor: %p erzielt das %s."})
: pick({"%p trifft zum %s.", "%p vollendet zum %s.", "%p lässt dem Torwart keine Chance: %s.",
"%p schließt zum %s ab."});
if (!other.empty()) body += pick({" Vorlage: %o.", " %o hatte aufgelegt.", " Die Vorarbeit kam von %o."});
if (minute >= 88 && own == theirs + 1) body += " Ein später Treffer.";
return {headline, fill(body)};
}
case AlmanacEventKind::Miss:
return {"Chance für " + team,
fill(detail == 1 ? pick({"%p vergibt den Standard.", "%p setzt den ruhenden Ball neben das Tor."})
: detail == 3 ? pick({"Nach einer Ecke kommt %p zum Abschluss, ohne Erfolg.", "%p köpft nach der Ecke vorbei."})
: pick({"%p vergibt.", "%p scheitert am Torwart.", "%p zielt zu ungenau.", "%p bringt den Ball nicht im Tor unter."}))};
case AlmanacEventKind::YellowCard:
return {"Gelbe Karte", fill(pick({"%p (%t) sieht Gelb.", "Gelb für %p (%t).", "%p (%t) wird verwarnt."}))};
case AlmanacEventKind::SecondYellow:
return {"Gelb-Rot", fill(pick({"%p (%t) sieht Gelb-Rot und muss vom Platz.", "Zweite Verwarnung für %p: %t spielt in Unterzahl weiter."}))};
case AlmanacEventKind::RedCard:
return {"Rote Karte", fill(pick({"%p (%t) sieht Rot.", "Platzverweis für %p: %t spielt in Unterzahl weiter."}))};
case AlmanacEventKind::Injury:
return {"Verletzung", fill(pick({"%p (%t) muss behandelt werden.", "%p (%t) bleibt verletzt liegen."}))};
case AlmanacEventKind::Substitution:
return {"Wechsel bei " + team,
fill(other.empty() ? "%p kommt ins Spiel." : pick({"%p kommt für %o.", "%o geht, %p kommt.", "%p ersetzt %o."}))};
case AlmanacEventKind::ShootoutKick:
return {"Elfmeterschießen", fill(detail ? pick({"%p verwandelt.", "%p trifft sicher."}) : pick({"%p verschießt.", "%p scheitert."}))};
}
return {"", ""};
}
namespace {
// The ticker's lines for an event of the almanac (German, as the interface's demo).
std::pair<std::string, std::string> ticker_text(const AlmanacSeason& s, const AlmanacMatch& m, const AlmanacEvent& e,
int home, int away) {
const std::string team = s.clubs[e.side ? m.away : m.home].name;
const std::string who = e.player != kAlmanacNone && e.player < s.players.size() ? player_name(s.players[e.player]) : team;
const std::string who = e.player != kAlmanacNone && e.player < s.players.size() ? player_name(s.players[e.player]) : std::string{};
const std::string other = e.other != kAlmanacNone && e.other < s.players.size() ? player_name(s.players[e.other]) : std::string{};
const std::string score = std::to_string(home) + ":" + std::to_string(away);
switch (e.kind) {
case AlmanacEventKind::Goal:
return {"Tor für " + team, who + " trifft zum " + score + "." + (other.empty() ? "" : " Vorlage: " + other + ".")};
case AlmanacEventKind::Miss: return {"Chance für " + team, who + " vergibt."};
case AlmanacEventKind::YellowCard: return {"Gelbe Karte", who + " (" + team + ") sieht Gelb."};
case AlmanacEventKind::SecondYellow: return {"Gelb-Rot", who + " (" + team + ") muss vom Platz."};
case AlmanacEventKind::RedCard: return {"Rote Karte", who + " (" + team + ") fliegt vom Platz."};
case AlmanacEventKind::Injury: return {"Verletzung", who + " (" + team + ") ist verletzt."};
case AlmanacEventKind::Substitution:
return {"Wechsel bei " + team, who + (other.empty() ? " kommt ins Spiel." : " kommt für " + other + ".")};
case AlmanacEventKind::ShootoutKick:
return {"Elfmeterschießen", who + (e.detail ? " verwandelt." : " verschießt.")};
}
return {"", ""};
return ticker_phrase(int(e.kind), team, who, other, e.detail, e.minute, home, away, e.side != 0);
}
const char* event_kind(AlmanacEventKind k) {
@@ -1045,6 +1091,27 @@ cli::Json live_fixture(const ModernState& g, uint32_t after_date, uint32_t until
{"body", body}, {"score", A{J(t.score[0]), J(t.score[1])}}, {"side", side ? "away" : "home"},
{"player", almanac_person(s, e.player)}, {"other", almanac_person(s, e.other)}});
}
if (!mo.event && mo.phase) {
// the whistle: kickoff, half time and the end of each ticker match, with the score then
const std::string phase = mo.phase;
const char* kind = phase == "kickoff" ? "kickoff" : phase == "interval" ? "interval"
: phase == "fulltime" || phase == "shootout_end" ? "fulltime" : nullptr;
for (size_t k = 0; kind && k < human.size(); ++k) {
const AlmanacSeason& s = *human[k].season;
const AlmanacMatch& m = s.matches[human[k].index];
const Tally& t = tally[k];
const std::string mid = match_id(s, human[k].index);
const std::string score = std::to_string(t.score[0]) + ":" + std::to_string(t.score[1]);
const std::string headline = phase == "kickoff" ? "Anpfiff" : phase == "interval" ? "Halbzeit" : "Abpfiff";
const std::string body = phase == "kickoff" ? s.clubs[m.home].name + " gegen " + s.clubs[m.away].name + ": Der Ball rollt."
: phase == "interval" ? "Zur Pause steht es " + score + "."
: phase == "shootout_end" ? "Das Elfmeterschießen ist entschieden."
: mo.minute > 90 ? "Endstand nach Verlängerung: " + score + "." : "Endstand: " + score + ".";
events.push_back(O{{"id", mid + ":event:" + std::to_string(events.size())}, {"sequence", int64_t(frames.size())},
{"match_id", mid}, {"minute", mo.minute}, {"kind", kind}, {"headline", headline}, {"body", body},
{"score", A{J(t.score[0]), J(t.score[1])}}, {"side", "home"}, {"player", nullptr}, {"other", nullptr}});
}
}
A scores;
for (size_t k = 0; k < human.size(); ++k) {
const Tally& t = tally[k];
@@ -1074,7 +1141,83 @@ cli::Json live_fixture(const ModernState& g, uint32_t after_date, uint32_t until
{"notice", "Aufzeichnung der Engine: die Spiele des letzten Anstoßes"}};
}
// Modern's eleven of the day: for every league with a match of a human manager in the kickoff,
// the best starters of that league's matches by what the almanac recorded (goals, assists,
// cards, the result, clean sheets), one goalkeeper, three defenders, four midfielders and
// three forwards. Nothing is drawn at random and no rating of the original is used; the
// current strength of a player only breaks ties.
cli::Json team_of_the_day(const ModernState& g, uint32_t from_date, uint32_t until_date) {
std::map<std::string, int> runtime; // world player id -> runtime index
for (size_t p = 0; p < g.world_player_id.size(); ++p)
if (!g.world_player_id[p].empty()) runtime[g.world_player_id[p]] = int(p);
A out;
const auto seasons = seasons_of(g);
for (const auto& s : seasons) {
std::set<int> leagues;
for (const auto& m : s.matches)
if (m.date >= from_date && m.date <= until_date && m.type == 0 && m.league < kLeagueCount &&
(m.home_manager >= 0 || m.away_manager >= 0)) leagues.insert(m.league);
for (const int league : leagues) {
struct Candidate { int score = 0, strength = 0, position = 0; uint16_t player = 0, club = 0; };
std::vector<Candidate> candidates;
for (const auto& m : s.matches) {
if (m.date < from_date || m.date > until_date || m.type != 0 || m.league != league) continue;
for (int side = 0; side < 2; ++side) {
const int scored = side ? m.away_goals : m.home_goals, conceded = side ? m.home_goals : m.away_goals;
const auto& lineup = m.lineup[size_t(side)];
for (size_t i = 0; i < lineup.size() && i < 11; ++i) {
const uint16_t player = lineup[i];
if (player == kAlmanacNone || player >= s.players.size()) continue;
const auto at = runtime.find(s.players[player].id);
if (at == runtime.end() || size_t(at->second) >= g.players.size()) continue;
const Player& now = g.players[size_t(at->second)];
Candidate c;
c.player = player, c.club = side ? m.away : m.home;
c.position = std::clamp(int(now.position()), 0, 3), c.strength = int(now.strength());
c.score = 10 + (scored > conceded ? 4 : scored == conceded ? 1 : 0);
if (conceded == 0) c.score += c.position == 0 ? 8 : c.position == 1 ? 5 : 0;
if (c.position == 0) c.score -= 2 * conceded;
for (const auto& e : m.events) {
if (e.kind == AlmanacEventKind::Goal && e.side == side && e.player == player) c.score += 12;
if (e.kind == AlmanacEventKind::Goal && e.side == side && e.other == player) c.score += 6;
if (e.kind == AlmanacEventKind::YellowCard && e.side == side && e.player == player) c.score -= 4;
if ((e.kind == AlmanacEventKind::RedCard || e.kind == AlmanacEventKind::SecondYellow) && e.side == side &&
e.player == player) c.score -= 12;
}
candidates.push_back(c);
}
}
}
std::stable_sort(candidates.begin(), candidates.end(), [&](const Candidate& a, const Candidate& b) {
if (a.score != b.score) return a.score > b.score;
if (a.strength != b.strength) return a.strength > b.strength;
return s.players[a.player].id < s.players[b.player].id;
});
static constexpr int kWanted[4] = {1, 3, 4, 3};
static constexpr const char* kPositions[4] = {"gk", "def", "mid", "fwd"};
A players;
bool complete = true;
for (int position = 0; position < 4; ++position) {
int taken = 0;
for (const Candidate& c : candidates) {
if (c.position != position || taken == kWanted[position]) continue;
++taken;
players.push_back(O{{"playerId", s.players[c.player].id}, {"name", player_name(s.players[c.player])},
{"teamId", s.clubs[c.club].id}, {"club", s.clubs[c.club].name},
{"position", kPositions[position]}, {"score", c.score}});
}
complete = complete && taken == kWanted[position];
}
if (!complete) continue;
const Competition c = league_competition(s, league);
out.push_back(O{{"competitionId", c.id}, {"competition", c.name}, {"formation", "3-4-3"}, {"players", std::move(players)}});
}
}
return out;
}
cli::Json almanac_matches_between(const ModernState& g, uint32_t from_date, uint32_t until_date) {
A out;
for (const auto& s : seasons_of(g))
for (size_t i = 0; i < s.matches.size(); ++i)