Merge current Engine contracts before publishing post-match UI (by Codex)
This commit is contained in:
commit
ef25407484
23 files changed
+1025
-22
No files matched your search
@@ -743,7 +743,7 @@ int main(int argc, char** argv) {
|
||||
read({{"kind", "squad"}});
|
||||
read({{"kind", "table"}, {"league", 42}});
|
||||
// the interface contract (docs/new_engine/ui-anbindung.md)
|
||||
for (const char* kind : {"session", "desktop", "squad", "camps", "nonsense"}) {
|
||||
for (const char* kind : {"session", "desktop", "squad", "camps", "stadium", "nonsense"}) {
|
||||
const auto request = cli::Json::Object{{"kind", kind}, {"requestId", std::string("request:sim-") + kind}};
|
||||
std::printf("ui_read %s\n -> %s\n", kind, cli::dump_json(session.ui_read(request, revision)).c_str());
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
// The traffic access stages (modern/game/traffic.hpp): the original's three in steps of 0x55,
|
||||
// a Modern world's four in steps of 64, and the conversion of the original's scale.
|
||||
#include <cstdio>
|
||||
|
||||
#include "game/world_layout.hpp"
|
||||
#include "modern/game/traffic.hpp"
|
||||
|
||||
using namespace bmh;
|
||||
using namespace bmh::modern;
|
||||
|
||||
namespace {
|
||||
int failures = 0;
|
||||
void check(bool ok, const char* what) {
|
||||
if (!ok) {
|
||||
std::fprintf(stderr, "FAIL: %s\n", what);
|
||||
++failures;
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
int main() {
|
||||
// Classic: 0 -> 85 -> 170 -> 255, a build is offered below 0xab
|
||||
set_world_layout(classic_world_layout());
|
||||
check(traffic_after_build(0) == 85 && traffic_after_build(85) == 170 && traffic_after_build(170) == 255, "classic builds");
|
||||
check(traffic_buildable(170) && !traffic_buildable(255), "classic offer limit");
|
||||
check(traffic_stage(85) == 1 && traffic_stage(170) == 2 && traffic_stage(255) == 3 && traffic_stage(84) == 1, "classic stages");
|
||||
check(traffic_full_stages(255) == 3 && traffic_full_stages(169) == 1, "classic size steps");
|
||||
check(traffic_from_original(170) == 170, "classic keeps its scale");
|
||||
|
||||
// a Modern world: 0 -> 64 -> 128 -> 192 -> 255, a build is offered below 193
|
||||
WorldLayout modern = classic_world_layout();
|
||||
modern.traffic_stages = 4;
|
||||
set_world_layout(modern);
|
||||
check(traffic_after_build(0) == 64 && traffic_after_build(64) == 128 && traffic_after_build(128) == 192 &&
|
||||
traffic_after_build(192) == 255, "four builds");
|
||||
check(traffic_buildable(192) && !traffic_buildable(255), "fourth stage offered, then no more");
|
||||
check(traffic_stage(64) == 1 && traffic_stage(128) == 2 && traffic_stage(192) == 3 && traffic_stage(255) == 4, "four stages");
|
||||
check(traffic_stage(63) == 1 && traffic_stage(191) == 3, "aged values keep their stage");
|
||||
check(traffic_full_stages(255) == 4 && traffic_full_stages(192) == 3 && traffic_full_stages(191) == 2, "size steps");
|
||||
check(traffic_stage_boundary(128) && !traffic_stage_boundary(127), "ageing message at a stage boundary");
|
||||
check(traffic_from_original(85) == 64 && traffic_from_original(170) == 128 && traffic_from_original(255) == 192 &&
|
||||
traffic_from_original(0) == 0 && traffic_from_original(150) == 128, "the original's stages in the new scale");
|
||||
|
||||
set_world_layout(classic_world_layout());
|
||||
if (failures == 0) std::printf("modern traffic tests passed\n");
|
||||
return failures == 0 ? 0 : 1;
|
||||
}
|
||||
@@ -260,6 +260,136 @@ int main(int argc, char** argv) {
|
||||
"code")) == "stale_quote" && rev == before + 2, "a used quote is gone");
|
||||
}
|
||||
}
|
||||
// advertising: the first acceptable offer, a budget
|
||||
{
|
||||
const J ads = session.ui_read(O{{"kind", "advertising"}}, rev);
|
||||
check(s(at(ads, "messageType")) == "snapshot" && at(at(ads, "data"), "boards").array() &&
|
||||
at(at(ads, "data"), "boards").array()->size() == 14, "advertising read");
|
||||
std::string offer;
|
||||
const auto pick = [&](const J& place) {
|
||||
if (const auto* list = at(place, "offers").array())
|
||||
for (const auto& o : *list)
|
||||
if (offer.empty() && truth(at(o, "allowed"))) offer = s(at(o, "id"));
|
||||
};
|
||||
pick(at(at(ads, "data"), "shirt"));
|
||||
pick(at(at(ads, "data"), "television"));
|
||||
if (const auto* boards = at(at(ads, "data"), "boards").array())
|
||||
for (const auto& b : *boards) pick(b);
|
||||
const uint64_t before = rev;
|
||||
if (!offer.empty()) {
|
||||
const J done = session.ui_command(cmd("request:w1", "advertising.accept", O{{"offerId", offer}}), rev);
|
||||
if (s(at(done, "messageType")) != "command_result") std::fprintf(stderr, "advertising: %s\n", cli::dump_json(done).c_str());
|
||||
check(s(at(done, "messageType")) == "command_result" && rev == before + 1, "advertising offer accepted");
|
||||
}
|
||||
const auto kept = modern::save_stream(session.state());
|
||||
check(s(at(session.ui_command(cmd("request:w2", "advertising.accept", O{{"offerId", "offer:ad-3-99"}}), rev), "code")) ==
|
||||
"unknown_offer" && modern::save_stream(session.state()) == kept, "unknown offer refused");
|
||||
std::printf("(advertising offer %s)\n", offer.empty() ? "none" : offer.c_str());
|
||||
}
|
||||
// stadium: periphery, facilities, blocks; the ticket price
|
||||
{
|
||||
const J stadium = session.ui_read(O{{"kind", "stadium"}}, rev);
|
||||
const J& d = at(stadium, "data");
|
||||
if (s(at(stadium, "messageType")) != "snapshot") std::fprintf(stderr, "stadium: %s\n", cli::dump_json(stadium).c_str());
|
||||
check(at(d, "periphery").array() && at(d, "periphery").array()->size() == 14 && at(d, "blocks").array() &&
|
||||
at(d, "blocks").array()->size() == 8 && at(d, "facilities").array() && at(d, "facilities").array()->size() == 8,
|
||||
"stadium read");
|
||||
if (const auto* p = at(d, "periphery").array(); p && !p->empty())
|
||||
check(!s(at((*p)[0], "name")).empty() && at((*p)[0], "stage").integer(), "traffic access with its stage");
|
||||
const uint64_t before = rev;
|
||||
const J done = session.ui_command(cmd("request:e1", "ticket.commit", O{{"price", O{{"minor", "1200"}, {"currency", "EUR"}, {"minorUnits", 2}}}}), rev);
|
||||
if (s(at(done, "messageType")) != "command_result") std::fprintf(stderr, "ticket: %s\n", cli::dump_json(done).c_str());
|
||||
const J after = session.ui_read(O{{"kind", "stadium"}}, rev);
|
||||
check(s(at(done, "messageType")) == "command_result" && s(at(at(at(after, "data"), "ticketPrice"), "minor")) == "1200" &&
|
||||
rev <= before + 1, "ticket price set");
|
||||
check(s(at(session.ui_command(cmd("request:e2", "ticket.commit", O{{"price", O{{"minor", "3000"}, {"currency", "EUR"}, {"minorUnits", 2}}}}), rev),
|
||||
"code")) == "invalid_amount", "ticket price above 25 refused");
|
||||
// building: a periphery object not built yet, then a facility level without the tip
|
||||
std::string object;
|
||||
if (const auto* p = at(at(after, "data"), "periphery").array())
|
||||
for (const auto& o : *p)
|
||||
if (object.empty() && at(o, "built").value.index() == 1 && !truth(at(o, "built")) && *at(o, "constructionDays").integer() == 0)
|
||||
object = s(at(o, "id"));
|
||||
const auto quote_of = [&]() { const J st = session.ui_read(O{{"kind", "stadium"}}, rev); return J(at(at(st, "data"), "quote")); };
|
||||
if (!object.empty()) {
|
||||
const uint64_t b0 = rev;
|
||||
const J q = session.ui_command(cmd("request:e3", "quote.request", O{{"kind", "periphery"}, {"objectId", object}}), rev);
|
||||
if (s(at(q, "messageType")) != "command_result") std::fprintf(stderr, "periphery quote: %s\n", cli::dump_json(q).c_str());
|
||||
const J quote = quote_of();
|
||||
check(s(at(q, "outcome")) == "offer_pending" && s(at(quote, "objectId")) == object && rev == b0 + 1, "periphery quoted");
|
||||
const J built = session.ui_command(cmd("request:e4", "stadium.commit", O{{"quoteId", at(quote, "id")}, {"accept", true}}), rev);
|
||||
if (s(at(built, "messageType")) != "command_result") std::fprintf(stderr, "periphery build: %s\n", cli::dump_json(built).c_str());
|
||||
check(s(at(built, "messageType")) == "command_result" && rev == b0 + 2 && std::holds_alternative<std::nullptr_t>(quote_of().value),
|
||||
"periphery built, the stadium closed");
|
||||
}
|
||||
{
|
||||
const uint64_t b0 = rev;
|
||||
const J q = session.ui_command(cmd("request:e5", "quote.request", O{{"kind", "facility"}, {"facilityId", "facility:safety"}, {"increment", 1}}), rev);
|
||||
const J quote = quote_of();
|
||||
if (s(at(q, "messageType")) == "command_result") {
|
||||
check(s(at(quote, "kind")) == "facility" && at(quote, "price").object(), "facility quoted");
|
||||
const J done = session.ui_command(cmd("request:e6", "stadium.commit", O{{"quoteId", at(quote, "id")}, {"accept", true}, {"tip", false}}), rev);
|
||||
if (s(at(done, "messageType")) != "command_result") std::fprintf(stderr, "facility build: %s\n", cli::dump_json(done).c_str());
|
||||
check(s(at(done, "messageType")) == "command_result" && rev == b0 + 2, "facility ordered");
|
||||
} else {
|
||||
std::printf("(facility quote: %s)\n", s(at(q, "code")).c_str());
|
||||
}
|
||||
const J q2 = session.ui_command(cmd("request:e7", "quote.request", O{{"kind", "facility"}, {"facilityId", "facility:comfort"}, {"increment", 1}}), rev);
|
||||
if (s(at(q2, "messageType")) == "command_result") {
|
||||
const J declined = session.ui_command(cmd("request:e8", "stadium.commit", O{{"quoteId", at(quote_of(), "id")}, {"accept", false}}), rev);
|
||||
check(s(at(declined, "messageType")) == "command_result" && std::holds_alternative<std::nullptr_t>(quote_of().value),
|
||||
"facility offer declined, the stadium closed");
|
||||
}
|
||||
}
|
||||
}
|
||||
// transfers: list an own player, bid on a listed one (asking fee and salary reference)
|
||||
{
|
||||
const J market = session.ui_read(O{{"kind", "transfer"}}, rev);
|
||||
const auto* listings = at(at(market, "data"), "listings").array();
|
||||
const auto* squad = at(at(market, "data"), "squad").array();
|
||||
check(s(at(market, "messageType")) == "snapshot" && listings && squad && !squad->empty(), "transfer read");
|
||||
const uint64_t before = rev;
|
||||
if (squad && squad->size() > 15) {
|
||||
const std::string seller = s(at(squad->back(), "playerId"));
|
||||
const J listed = session.ui_command(cmd("request:t9", "transfer.submit", O{{"action", "list"}, {"playerId", seller}}), rev);
|
||||
if (s(at(listed, "messageType")) != "command_result") std::fprintf(stderr, "list: %s\n", cli::dump_json(listed).c_str());
|
||||
check(s(at(listed, "messageType")) == "command_result" && rev == before + 1, "own player listed");
|
||||
}
|
||||
std::string listing;
|
||||
J fee, salary;
|
||||
if (listings)
|
||||
for (const auto& l : *listings)
|
||||
if (listing.empty() && !truth(at(l, "ownListing")) && !truth(at(l, "ownBidPending")))
|
||||
listing = s(at(l, "id")), fee = at(l, "askingFee"), salary = at(l, "salaryReference");
|
||||
if (!listing.empty()) {
|
||||
// the salary reference is annual in the market row; the offer takes a monthly salary
|
||||
const int64_t monthly = std::stoll(s(at(salary, "minor"))) / 12 / 100 * 100;
|
||||
const uint64_t b2 = rev;
|
||||
const J bid = session.ui_command(cmd("request:t10", "transfer.submit",
|
||||
O{{"action", "bid"}, {"listingId", listing}, {"fee", fee},
|
||||
{"monthlySalary", O{{"minor", std::to_string(monthly)}, {"currency", "EUR"}, {"minorUnits", 2}}}, {"years", 2}}), rev);
|
||||
std::printf("(bid on %s: %s)\n", listing.c_str(), cli::dump_json(bid).substr(0, 260).c_str());
|
||||
check((s(at(bid, "messageType")) == "command_result" && rev == b2 + 1) ||
|
||||
(s(at(bid, "messageType")) == "error" && rev == b2), "bid answered or refused cleanly");
|
||||
}
|
||||
check(s(at(session.ui_command(cmd("request:t11", "transfer.submit", O{{"action", "bid"}, {"listingId", "listing:999"}}), rev), "code")) ==
|
||||
"unknown_listing", "unknown listing refused");
|
||||
}
|
||||
// toto and the exclusive sponsor
|
||||
{
|
||||
const J toto = session.ui_read(O{{"kind", "toto"}}, rev);
|
||||
check(s(at(toto, "messageType")) == "snapshot" && at(at(at(toto, "data"), "stake"), "minor").string(), "toto read with Money");
|
||||
const J::Array column{J(1), J(0), J(2), J(1), J(1), J(0), J(2), J(1), J(1), J(0), J(2)};
|
||||
const uint64_t before = rev;
|
||||
const J done = session.ui_command(cmd("request:o1", "toto.submit",
|
||||
O{{"stake", O{{"minor", "5000000"}, {"currency", "EUR"}, {"minorUnits", 2}}}, {"columns", J::Array{J(column), J(column)}}}), rev);
|
||||
if (truth(at(at(toto, "data"), "open")))
|
||||
check(s(at(done, "messageType")) == "command_result" && rev == before + 1, "two toto columns submitted");
|
||||
else
|
||||
check(s(at(done, "code")) == "toto_refused" && rev == before, "toto closed: refused without change");
|
||||
check(s(at(session.ui_command(cmd("request:o2", "sponsor.answer", O{{"accept", true}}), rev), "messageType")) == "error",
|
||||
"no sponsor offer to answer");
|
||||
}
|
||||
// session.advance: three kickoffs, each one revision, the date moves on
|
||||
{
|
||||
const std::string date_before = s(at(at(session.ui_read(O{{"kind", "desktop"}}, rev), "meta"), "date"));
|
||||
@@ -273,6 +403,52 @@ 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");
|
||||
}
|
||||
// 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)
|
||||
{
|
||||
O expiry;
|
||||
int decisions = 0, advances = 0;
|
||||
for (int k = 0; k < 200 && advances < 120; ++k) {
|
||||
const uint64_t before = rev;
|
||||
const J done = session.ui_command(cmd("request:s" + std::to_string(k), "session.advance", O{{"contractExpiry", expiry}}), rev);
|
||||
if (s(at(done, "messageType")) == "command_result") { ++advances; continue; }
|
||||
const std::string code = s(at(done, "code"));
|
||||
const std::string player = s(at(at(at(done, "message"), "args"), "playerId"));
|
||||
check(code == "decision_pending" && !player.empty() && rev == before, "a pending contract names the player, nothing changed");
|
||||
if (code != "decision_pending" || player.empty() || expiry.count(player)) break;
|
||||
expiry[player] = O{{"action", "release"}};
|
||||
++decisions;
|
||||
}
|
||||
check(advances == 120, "two seasons of kickoffs with answered contract decisions");
|
||||
check(decisions > 0, "running-out contracts were asked for");
|
||||
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");
|
||||
}
|
||||
// almanac view after the kickoffs: index, calendar, day, match
|
||||
{
|
||||
const J index = session.read_almanac(O{{"kind", "index"}});
|
||||
@@ -295,15 +471,17 @@ int main(int argc, char** argv) {
|
||||
check(s(at(session.read_almanac(O{{"kind", "match"}, {"id", "match:0-0"}}), "error")) == "almanac_match_not_found",
|
||||
"unknown match");
|
||||
// the statistics screen: real data (fictional false), unrecorded views say so
|
||||
// (the club views need a club desk: on an international day the manager sits at the national one)
|
||||
const J minutes = session.read_statistics_screen(O{{"section", 8}});
|
||||
check(truth(at(minutes, "ok")) && !truth(at(minutes, "fictional")) && at(minutes, "rows").array() &&
|
||||
at(minutes, "rows").array()->size() == 4, "minute statistics");
|
||||
const J transfers = session.read_statistics_screen(O{{"section", 1}});
|
||||
const bool club_desk = !std::holds_alternative<std::nullptr_t>(at(minutes, "club").value);
|
||||
check(truth(at(minutes, "ok")) && !truth(at(minutes, "fictional")) &&
|
||||
(!club_desk || (at(minutes, "rows").array() && at(minutes, "rows").array()->size() == 4)), "minute statistics");
|
||||
const J transfers = session.read_statistics_screen(O{{"section", 0}});
|
||||
check(truth(at(transfers, "ok")) && !truth(at(transfers, "available")) && s(at(transfers, "reason")) == "not_recorded",
|
||||
"transfer history not recorded");
|
||||
"title chances not recorded");
|
||||
check(s(at(session.read_statistics_screen(O{{"section", 9}}), "error")) == "invalid_statistics_filter", "bad section");
|
||||
const J curves = session.read_statistics_screen(O{{"section", 2}});
|
||||
check(at(curves, "series").array() && at(curves, "series").array()->size() == 6, "the six curves of the original");
|
||||
check(!club_desk || (at(curves, "series").array() && at(curves, "series").array()->size() == 6), "the six curves of the original");
|
||||
}
|
||||
} catch (const std::exception& ex) {
|
||||
std::fprintf(stderr, "FAIL: %s\n", ex.what());
|
||||
|
||||
Reference in new issue
Block a user