Modern UI contract: scheduling, friendlies and rescheduling

The scheduling read lists the own league matches that can be moved with
their target dates and the moved ones; the friendly read quotes a friendly
against a club with its free dates. friendly.book books it (the payer
accepts the cost, a human opponent consents), fixture.reschedule moves a
league match or takes a move back. All without random draws.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ClaudeandClaude Opus 5.5 committed 2026-10-27 13:51:35 +01:00
1 parent f2c895ffb0
commit 06445c24ef
4 files changed
+187 -35

No files matched your search

+4
View File
@@ -35,6 +35,8 @@ Revision kommt vom Aufrufer (Konsole bzw. AppController), der Read ändert nicht
| `advertising` | 14 Banden (`ad:board/<n>`), Trikot (`ad:shirt`), TV-Rechte (`ad:tv`) je mit Vertrag (Sponsor, Monatsbetrag, Restmonate, Verlängerung, Option) und den offenen Angeboten (`offer:ad-<Platz>-<Nr.>`, Sponsor, Betrag, Banden, Monate, `allowed`); die drei Budgets (Merchandising, Presse, Fanarbeit) mit Stand, Höchstbetrag, Lieferwochen; die Finanzvorschau des Originals |
| `stadium` | Umfeld (14 Objekte mit Namen und Bautagen; Verkehrsanbindung mit `stage` und `maxStage`: Classic 3, Modern-Welt 4; sonst `built`), die acht Anlagen (Stufe, Höchststufe, Bauwochen, ob ausbaubar), die acht Tribünenblöcke (Plätze, Höchstplätze, Sitzplätze, Dach, Bauwochen, Plätze nach dem Bau), Eintrittspreis (8–25 €); das offene Angebot des Stadion-Dialogs (`quote`: Umfeld mit Preis, oder Anlage mit Zielstufe, Preis, Bauwochen und dem Trinkgeld-Bereich 6–14 %) |
| `transfer` | die Transferliste (`listing:<n>`: Spieler, Alter, Position, Stärke, Verkäufer, Ablöseforderung, Gehaltsreferenz pro Jahr, Gehaltsforderung in %, Zahl der Angebote, eigene Listung, eigenes Gebot), der eigene Kader (gelistet oder nicht), Kontostand, Kreditrahmen |
| `scheduling` | die verlegbaren eigenen Ligaspiele (`move:<Tag>-<Liga>-<Runde>-<Nr.>`, Datum, Runde, Heim/Gast, mögliche Zieldaten) und die verlegten, die sich zurücknehmen lassen |
| `friendly` | mit `opponentId`, optional `home`: das Angebot für ein Freundschaftsspiel (Heim/Gast, Kosten, Zahler, ob der Gegner einen menschlichen Manager hat) und die freien Daten der Saison; kein Zufall |
| `environment` | das Umfeld (Diamond 3.6): drei Jugendteams, Co-Trainer, Arzt, Physiotherapeut (`environment:<Bereich>`), je Stufe 0–6, Monatskosten, Kosten je Stufe; die Jugendteams mit Stärke, Platz, Liga; ob die Akademie läuft |
| `toto` | der Tippschein ([Toto](toto.md)): `open` (elf Spiele), Spiele, Einsatz und Kosten (`Money`), Spalten, Regeln, letzte Abrechnung |
| `sponsor` | das Exklusiv-Sponsor-Angebot aus einem Trainingslager und ein vorgemerkter Vertrag (`monthly` als `Money`; `asset: null`, siehe [Trainingslager](trainingslager.md)) |
@@ -79,6 +81,8 @@ Die UI ruft diese über `DataSource::read_almanac` und `read_statistics` direkt
| `budget.commit` | `budgetId` (`budget:merchandise`, `budget:press`, `budget:fans`), `amount` (`Money`) | setzt ein Budget; Fehler `unknown_budget`, `invalid_amount`, `advertising_refused` (z. B. Lieferung läuft, zu wenig Geld) |
| `ticket.commit` | `price` (`Money`, 8–25 €) | der Eintrittspreis; Fehler `invalid_amount`, `ticket_refused` |
| `transfer.submit` | `action: list`, `playerId`, optional `loan`; oder `action: bid`, `listingId`, `fee`, `monthlySalary` (`Money`), `years` 1–4, optional `loan` | setzt einen eigenen Spieler auf die Liste (bzw. bietet ihn zum Verleih an) oder gibt über den Angebotseditor des Originals ein Gebot ab (öffnen, Felder setzen, abschicken). `outcome`: `applied` (sofort angenommen), `offer_pending` (Antwort mit der nächsten Woche), `offer_rejected` (zu niedrig/abgelehnt). Fragt die Engine einen menschlichen Verkäufer (Abwerben), wird zurückgerollt: `decision_pending` (noch nicht unterstützt). Fehler `unknown_player`, `already_listed`, `unknown_listing`, `own_player`, `no_bid_slot`, `transfer_refused` |
| `friendly.book` | `opponentId`, optional `home`, `date`, `acceptCost`, bei menschlichem Gegner `opponentConsent` | vereinbart das Freundschaftsspiel; Fehler `declined` (Kosten nicht bestätigt), `opponent_declined`, `insufficient_funds`, `date_unavailable`, `plan_full` u. a. |
| `fixture.reschedule` | `matchId`, `date`; oder `action: undo`, `date` | verlegt eine eigene Ligapartie bzw. nimmt die Verlegung zurück; Fehler `invalid_day`, `day_full`, `team_clash`, `no_free_slot`, `no_moved_match` |
| `environment.commit` | `itemId`, `level` 0–6 | setzt ein Monatsbudget des Umfelds (keine Sofortbuchung, kein Zufall); unverändert: `outcome: no_change`; Fehler `environment_refused` |
| `manager.resign.commit` | `confirmed: true` | Aufgeben (neu in Modern, das Original kennt kein Aussteigen): Der letzte menschliche Manager beendet die Karriere (`outcome: career_ended`, `session`-Read `sessionState: "ended"`, danach antwortet jeder Befehl `career_ended`). Mit weiteren Menschen soll der Computer den Verein übernehmen; das braucht das Nachrücken aller Managertabellen und folgt (`resign_not_supported_yet`). Fehler `confirmation_required` |
| `toto.submit` | `stake` (`Money` je Spalte), `columns` (bis 6 Spalten mit 11 Tipps: 1 Heim, 0 Unentschieden, 2 Auswärts) | gibt den Tippschein ab; Fehler `toto_refused` (z. B. kein offener Schein, Einsatzgrenzen, doppelte Spalte) |
+69
View File
@@ -10094,6 +10094,75 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision
answer = modern::ui_command_result(request_id, previous, revision, {"transfer", "squad", "desktop"}, feedback);
if (bid_pending) std::get<cli::Json::Object>(answer.value)["outcome"] = "offer_pending";
}
} else if (kind == "friendly.book" || kind == "fixture.reschedule") {
const int team = g_.manager_teams[size_t(manager)];
if (team < 0 || team >= league_clubs()) return refuse("no_club", "Am Schreibtisch des Bundestrainers gibt es das nicht.");
// a date of this season as its season day (0..365)
const auto day_of = [&](const std::string& iso) -> int {
for (int day = 0; day <= 365; ++day) {
const AlmanacDate d = almanac_date(g_.season_start + uint32_t(day), g_.display_start_year);
char text[16];
std::snprintf(text, sizeof text, "%04d-%02d-%02d", d.year, d.month, d.day);
if (iso == text) return day;
}
return -1;
};
const auto flag = [&](const char* key) {
const cli::Json* v = ui_field(*payload, key);
return v && std::holds_alternative<bool>(v->value) && std::get<bool>(v->value);
};
if (kind == "friendly.book") {
// {opponentId, home?, date, acceptCost, opponentConsent?}: the quote of the friendly read
// on a free date; the payer accepts the cost, a human opponent's manager consents
const std::string opponent_id = ui_text(*payload, "opponentId");
int opponent = -1;
for (int t = 0; t < int(g_.world_club_id.size()); ++t) if (g_.world_club_id[size_t(t)] == opponent_id) opponent = t;
if (opponent < 0 && opponent_id.starts_with("team:")) try { opponent = std::stoi(opponent_id.substr(5)); } catch (const std::exception&) {}
const int day = day_of(ui_text(*payload, "date"));
if (opponent < 0 || day < 0) return refuse("invalid_payload", "opponentId und date (dieser Saison) nötig.");
const cli::Json* home = ui_field(*payload, "home");
FriendlyBookingRequest r;
r.quote = modern::quote_friendly_match(g_, manager, opponent, !home || !std::holds_alternative<bool>(home->value) || std::get<bool>(home->value));
if (r.quote.status != FriendlyQuoteStatus::quoted) return refuse("friendly_unavailable", "Gegen diesen Verein ist kein Freundschaftsspiel möglich.");
r.season_day = uint16_t(day);
r.accept_opponent = r.quote.opponent_manager < 0 || flag("opponentConsent");
r.consenting_manager = r.quote.opponent_manager;
r.accept_cost = flag("acceptCost");
r.approving_manager = r.quote.payer_manager;
const FriendlyBookingResult result = modern::book_friendly_match(g_, r);
if (result.status != FriendlyBookingStatus::booked) {
static constexpr const char* kStatus[11] = {"booked", "declined", "opponent_declined", "insufficient_funds", "invalid_manager",
"invalid_opponent", "invalid_date", "date_unavailable", "plan_full", "stale_quote", "invalid_request"};
restore();
return refuse(kStatus[size_t(result.status)], "Das Freundschaftsspiel kam nicht zustande.");
}
revision = previous + 1;
answer = modern::ui_command_result(request_id, previous, revision, {"scheduling", "calendar", "desktop", "bank"},
"Freundschaftsspiel vereinbart.");
} else {
// {matchId: "move:...", date}: a league match to another day; {action: "undo", date}: a move taken back
if (ui_text(*payload, "action") == "undo") {
const int day = day_of(ui_text(*payload, "date"));
if (day < 0 || !modern::undo_reschedule(g_, manager, day)) { restore(); return refuse("no_moved_match", "An diesem Tag gibt es keine verlegte Partie."); }
} else {
int day = -1, league = -1, round = -1, match = -1;
if (std::sscanf(ui_text(*payload, "matchId").c_str(), "move:%d-%d-%d-%d", &day, &league, &round, &match) != 4)
return refuse("invalid_payload", "matchId (move:...) und date nötig.");
LeagueMatchRef ref;
for (const auto& r : modern::reschedulable_matches(g_, manager))
if (r.day == day && r.league == league && r.round == round && r.match == match) ref = r;
const int target = day_of(ui_text(*payload, "date"));
if (ref.day < 0 || target < 0) return refuse("unknown_match", "Diese Partie kann nicht verlegt werden.");
const RescheduleStatus st = modern::reschedule_league_match(g_, manager, ref, target);
if (st != RescheduleStatus::moved) {
static constexpr const char* kStatus[7] = {"moved", "invalid_manager", "invalid_match", "invalid_day", "no_free_slot", "day_full", "team_clash"};
restore();
return refuse(kStatus[size_t(st)], "Die Partie lässt sich nicht auf diesen Tag verlegen.");
}
}
revision = previous + 1;
answer = modern::ui_command_result(request_id, previous, revision, {"scheduling", "calendar", "desktop"}, "Spielplan geändert.");
}
} else if (kind == "environment.commit") {
// payload {itemId: "environment:<item>", level 0-6}: a monthly budget of the surroundings
// (no immediate booking, no random draw); the original's notice comes back as feedback
+45
View File
@@ -15,6 +15,7 @@
#include "modern/game/almanac.hpp"
#include "modern/game/desk_actions.hpp"
#include "modern/game/environment.hpp"
#include "modern/game/reschedule.hpp"
namespace bmh::modern {
@@ -369,6 +370,50 @@ cli::Json ui_read(const ModernState& g, const UiContext& c, const cli::Json& req
if (kind == "session") return snapshot(request_id, std::move(m), session_data(g, c));
if (kind == "desktop") return snapshot(request_id, std::move(m), desktop_data(g, c, today));
if (kind == "camps") return snapshot(request_id, std::move(m), camps_data(g, c, std::to_string(c.state_revision)));
if (kind == "scheduling" || kind == "friendly") {
const int own = team_of(g, c.manager);
if (own < 0 || own >= league_clubs())
return failure(request_id, "no_club", "Am Schreibtisch des Bundestrainers gibt es das nicht.", c.state_revision);
const auto date_of = [&](int day) { return iso(almanac_date(g.season_start + uint32_t(day), g.display_start_year)); };
if (kind == "scheduling") {
// league matches that can be moved (own home matches, rounds 1 .. matchdays - 3) with
// the dates they can go to, and moved ones that can be taken back (no random draw)
const auto ref_id = [](const LeagueMatchRef& r) {
return "move:" + std::to_string(r.day) + "-" + std::to_string(r.league) + "-" + std::to_string(r.round) + "-" + std::to_string(r.match);
};
A movable, moved;
for (const auto& r : reschedulable_matches(g, c.manager)) {
A targets;
for (int day : reschedule_target_days(g, c.manager, r)) targets.push_back(date_of(day));
movable.push_back(O{{"id", ref_id(r)}, {"date", date_of(r.day)}, {"round", r.round + 1},
{"home", team_ref(g, r.home, date_of(r.day))}, {"away", team_ref(g, r.away, date_of(r.day))},
{"targetDates", std::move(targets)}});
}
for (const auto& r : moved_matches(g, c.manager))
moved.push_back(O{{"date", date_of(r.day)}, {"round", r.round + 1}, {"home", team_ref(g, r.home, date_of(r.day))},
{"away", team_ref(g, r.away, date_of(r.day))}});
return snapshot(request_id, std::move(m), O{{"kind", "scheduling"}, {"movable", std::move(movable)}, {"moved", std::move(moved)}});
}
// friendly {opponentId, home?}: the price and venue quote and the free dates (no random draw)
const int opponent = requested_team(g, UiContext{c.state_revision, c.manager}, O{{"teamId", text_field(request, "opponentId")}});
const J* home_field = field(request, "home");
const bool home = !home_field || !std::holds_alternative<bool>(home_field->value) || std::get<bool>(home_field->value);
if (opponent < 0 || text_field(request, "opponentId").empty())
return failure(request_id, "unknown_team", "opponentId nennt keinen Verein.", c.state_revision);
const FriendlyBookingQuote q = quote_friendly_match(g, c.manager, opponent, home);
if (q.status != FriendlyQuoteStatus::quoted)
return failure(request_id, "friendly_unavailable", "Gegen diesen Verein ist kein Freundschaftsspiel möglich.", c.state_revision);
A dates;
for (int day = g.season_day() + 1; day <= 365; ++day) {
const FriendlyDateStatus st = friendly_match_date_status(g, q, uint16_t(day));
if (st == FriendlyDateStatus::available || st == FriendlyDateStatus::available_with_calendar_event)
dates.push_back(O{{"date", date_of(day)}, {"withCalendarEvent", st == FriendlyDateStatus::available_with_calendar_event}});
}
return snapshot(request_id, std::move(m),
O{{"kind", "friendly"}, {"home", team_ref(g, q.home_team, iso(almanac_date(g.date, g.display_start_year)))}, {"away", team_ref(g, q.away_team, iso(almanac_date(g.date, g.display_start_year)))},
{"cost", ui_money(q.cost)}, {"payerManagerId", q.payer_manager >= 0 ? J(manager_id(g, q.payer_manager)) : J(nullptr)},
{"opponentHuman", q.opponent_manager >= 0}, {"dates", std::move(dates)}});
}
if (kind == "environment") {
// the club's surroundings (Diamond 3.6): three youth teams, co-trainer, doctor, physio, each
// with a monthly budget level 0-6 and its cost; the youth teams' strength, place and league
+69 -35
View File
@@ -398,6 +398,40 @@ int main(int argc, char** argv) {
check(s(at(session.ui_command(cmd("request:t11", "transfer.submit", O{{"action", "bid"}, {"listingId", "listing:999"}}), rev), "code")) ==
"unknown_listing", "unknown listing refused");
}
// scheduling: move a league match and take it back; a friendly
{
const J sched = session.ui_read(O{{"kind", "scheduling"}}, rev);
const auto* movable = at(at(sched, "data"), "movable").array();
check(s(at(sched, "messageType")) == "snapshot" && movable, "scheduling read");
std::string match, target;
if (movable)
for (const auto& mv : *movable)
if (match.empty() && at(mv, "targetDates").array() && !at(mv, "targetDates").array()->empty())
match = s(at(mv, "id")), target = s(at(mv, "targetDates").array()->front());
if (!match.empty()) {
const uint64_t before = rev;
const J moved = session.ui_command(cmd("request:f1", "fixture.reschedule", O{{"matchId", match}, {"date", target}}), rev);
const J again = session.ui_read(O{{"kind", "scheduling"}}, rev);
check(s(at(moved, "messageType")) == "command_result" && rev == before + 1 && at(at(again, "data"), "moved").array() &&
!at(at(again, "data"), "moved").array()->empty(), "league match moved");
const J undone = session.ui_command(cmd("request:f2", "fixture.reschedule", O{{"action", "undo"}, {"date", target}}), rev);
check(s(at(undone, "messageType")) == "command_result", "move taken back");
std::printf("(moved %s to %s and back)\n", match.c_str(), target.c_str());
}
const J friendly = session.ui_read(O{{"kind", "friendly"}, {"opponentId", "team:70"}, {"home", true}}, rev);
const auto* dates = at(at(friendly, "data"), "dates").array();
if (s(at(friendly, "messageType")) != "snapshot") std::fprintf(stderr, "friendly: %s\n", cli::dump_json(friendly).c_str());
check(dates && !dates->empty() && at(at(at(friendly, "data"), "cost"), "minor").string(), "friendly quote with free dates");
if (dates && !dates->empty()) {
const J day = at(dates->front(), "date");
check(s(at(session.ui_command(cmd("request:f3", "friendly.book", O{{"opponentId", "team:70"}, {"date", day}}), rev), "code")) ==
"declined", "the cost must be accepted");
const uint64_t before = rev;
const J booked = session.ui_command(cmd("request:f4", "friendly.book", O{{"opponentId", "team:70"}, {"date", day}, {"acceptCost", true}}), rev);
if (s(at(booked, "messageType")) != "command_result") std::fprintf(stderr, "friendly book: %s\n", cli::dump_json(booked).c_str());
check(s(at(booked, "messageType")) == "command_result" && rev == before + 1, "friendly booked");
}
}
// the surroundings: six budgets 0-6
{
const J env = session.ui_read(O{{"kind", "environment"}}, rev);
@@ -443,6 +477,41 @@ int main(int argc, char** argv) {
const std::string date_after = s(at(at(session.ui_read(O{{"kind", "desktop"}}, rev), "meta"), "date"));
check(date_after > date_before, "the date moved on");
}
// the live ticker: advance until a kickoff played a match of the human manager, then its recording
{
J fixture;
for (int k = 0; k < 12; ++k) {
fixture = session.read_live(O{{"kind", "fixture"}});
if (truth(at(fixture, "ok"))) break;
check(s(at(fixture, "error")) == "live_no_human_match", "no human match: said so");
session.ui_command(cmd("request:lv" + std::to_string(k), "session.advance", O{}), rev);
}
const auto* frames = at(fixture, "frames").array();
const auto* matches = at(fixture, "matches").array();
check(truth(at(fixture, "ok")) && s(at(fixture, "source")) == "engine-recording" && frames && frames->size() >= 4 &&
matches && !matches->empty() && at(fixture, "owners").array() && !at(fixture, "owners").array()->empty(),
"live fixture of the last kickoff");
if (frames && frames->size() >= 4) {
const J& last = frames->back();
const J one = session.read_live(O{{"kind", "frame"}, {"sequence", int64_t(frames->size() - 1)}});
check(truth(at(one, "ok")) && cli::dump_json(at(one, "frame")) == cli::dump_json(last), "one frame by sequence");
// the last frame's score is the recorded result of the match
const J m = at(at(last, "matches").array()->front(), "score");
std::printf("(live: %zu frames, %zu matches, conference %zu, final %s)\n", frames->size(), matches->size(),
at(fixture, "conference").array() ? at(fixture, "conference").array()->size() : 0, cli::dump_json(m).c_str());
}
check(s(at(session.read_live(O{{"kind", "frame"}, {"sequence", 99999}}), "error")) == "invalid_live_sequence", "bad sequence");
// the after-match steps of that kickoff
const J post = session.ui_read(O{{"kind", "postmatch"}}, rev);
const J& pd = at(post, "data");
const auto* steps = at(pd, "steps").array();
check(s(at(post, "messageType")) == "snapshot" && steps && steps->size() == 5 && truth(at((*steps)[0], "available")) &&
at(pd, "matches").array() && !at(pd, "matches").array()->empty() && at(pd, "reportMatchIds").array() &&
!at(pd, "reportMatchIds").array()->empty(), "postmatch with results and report");
std::printf("(postmatch: %zu matches, %zu tables, %zu elevens)\n", at(pd, "matches").array()->size(),
at(pd, "tables").array() ? at(pd, "tables").array()->size() : 0,
at(pd, "teamOfTheDay").array() ? at(pd, "teamOfTheDay").array()->size() : 0);
}
// a live kickoff: stops in a match of the human manager, steps, intervenes, finishes
{
bool stopped = false;
@@ -517,41 +586,6 @@ int main(int argc, char** argv) {
std::printf("(date now %s)\n", s(at(at(session.ui_read(O{{"kind", "desktop"}}, rev), "meta"), "date")).c_str());
std::printf("(%d contract decisions answered)\n", decisions);
}
// the live ticker: advance until a kickoff played a match of the human manager, then its recording
{
J fixture;
for (int k = 0; k < 12; ++k) {
fixture = session.read_live(O{{"kind", "fixture"}});
if (truth(at(fixture, "ok"))) break;
check(s(at(fixture, "error")) == "live_no_human_match", "no human match: said so");
session.ui_command(cmd("request:lv" + std::to_string(k), "session.advance", O{}), rev);
}
const auto* frames = at(fixture, "frames").array();
const auto* matches = at(fixture, "matches").array();
check(truth(at(fixture, "ok")) && s(at(fixture, "source")) == "engine-recording" && frames && frames->size() >= 4 &&
matches && !matches->empty() && at(fixture, "owners").array() && !at(fixture, "owners").array()->empty(),
"live fixture of the last kickoff");
if (frames && frames->size() >= 4) {
const J& last = frames->back();
const J one = session.read_live(O{{"kind", "frame"}, {"sequence", int64_t(frames->size() - 1)}});
check(truth(at(one, "ok")) && cli::dump_json(at(one, "frame")) == cli::dump_json(last), "one frame by sequence");
// the last frame's score is the recorded result of the match
const J m = at(at(last, "matches").array()->front(), "score");
std::printf("(live: %zu frames, %zu matches, conference %zu, final %s)\n", frames->size(), matches->size(),
at(fixture, "conference").array() ? at(fixture, "conference").array()->size() : 0, cli::dump_json(m).c_str());
}
check(s(at(session.read_live(O{{"kind", "frame"}, {"sequence", 99999}}), "error")) == "invalid_live_sequence", "bad sequence");
// the after-match steps of that kickoff
const J post = session.ui_read(O{{"kind", "postmatch"}}, rev);
const J& pd = at(post, "data");
const auto* steps = at(pd, "steps").array();
check(s(at(post, "messageType")) == "snapshot" && steps && steps->size() == 5 && truth(at((*steps)[0], "available")) &&
at(pd, "matches").array() && !at(pd, "matches").array()->empty() && at(pd, "reportMatchIds").array() &&
!at(pd, "reportMatchIds").array()->empty(), "postmatch with results and report");
std::printf("(postmatch: %zu matches, %zu tables, %zu elevens)\n", at(pd, "matches").array()->size(),
at(pd, "tables").array() ? at(pd, "tables").array()->size() : 0,
at(pd, "teamOfTheDay").array() ? at(pd, "teamOfTheDay").array()->size() : 0);
}
// almanac view after the kickoffs: index, calendar, day, match
{
const J index = session.read_almanac(O{{"kind", "index"}});