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:
1 parent
f2c895ffb0
commit
06445c24ef
4 files changed
+187
-35
No files matched your search
@@ -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"}});
|
||||
|
||||
Reference in new issue
Block a user