Bind player rankings and fair play to recorded season events (by Codex)
This commit is contained in:
1 parent
6b4aa9772d
commit
738ecc7a09
27 files changed
+436
-36
No files matched your search
@@ -11,7 +11,7 @@ using namespace bmh::modern_ui;
|
||||
int main(int argc, char **argv) {
|
||||
try {
|
||||
const std::string mode=argc>1?argv[1]:"";
|
||||
const std::set<std::string> modes{"prepare","prepare-two","prepare-national","prepare-almanac","inspect","inspect-friendlies","inspect-almanac","verify","verify-lineup","verify-sports","verify-bank","verify-commerce","verify-contracts","verify-calendar","verify-friendlies","verify-national","verify-almanac","verify-shootouts","verify-reports","verify-fixtures","verify-other"};
|
||||
const std::set<std::string> modes{"prepare","prepare-two","prepare-national","prepare-almanac","inspect","inspect-friendlies","inspect-almanac","verify","verify-lineup","verify-sports","verify-bank","verify-commerce","verify-contracts","verify-calendar","verify-friendlies","verify-national","verify-almanac","verify-shootouts","verify-reports","verify-fixtures","verify-other","verify-rankings","prepare-rankings-archived"};
|
||||
if(argc!=4||!modes.contains(mode))throw std::runtime_error("usage: modern_engine_bridge_probe <prepare[-two|-national|-almanac]|inspect[-friendlies|-almanac]|verify[-lineup|-sports|-bank|-commerce|-contracts|-calendar|-friendlies|-national|-almanac|-shootouts]> <world.obw> <new-output-directory>");
|
||||
const fs::path world = argv[2], out = argv[3]; fs::create_directories(out);
|
||||
const auto write = [&](const char *file, const Json &j) { editor::write_atomic(out / file, j.dump(2)); };
|
||||
@@ -44,6 +44,21 @@ int main(int argc, char **argv) {
|
||||
if (!session.save_game(out / "input.obs", 0, false, error)) throw std::runtime_error(error);
|
||||
modern::set_current_world(nullptr);
|
||||
}
|
||||
if(mode=="prepare-rankings-archived") {
|
||||
std::string person,league;
|
||||
{
|
||||
auto package=modern::open_world_package(world);content::Mount mount(world,package.classic);modern::set_current_world(package.world);
|
||||
modern::app::ModernSession session(mount.root(),1u,out/"input.obs",false);auto &g=session.state();league=g.world_league_id.at(0);
|
||||
const auto read=Json::parse(cli::dump_json(session.ui_read(cli::Json::Object{{"kind","player-rankings"},{"leagueId",league},{"scope",0}},0)));
|
||||
person=read.at("data").at("categories")[0][0].at("player").at("id");
|
||||
const auto found=std::find(g.world_player_id.begin(),g.world_player_id.end(),person);if(found==g.world_player_id.end())throw std::runtime_error("archive fixture player missing");const auto player=size_t(found-g.world_player_id.begin());
|
||||
for(auto &slot:g.squad_slots)if((slot&0x0fff)==player)slot=kEmptySlot;
|
||||
std::string error;if(!session.save_game(out/"archived.obs",0,false,error))throw std::runtime_error(error);
|
||||
write("synthetic-mutation.json",{{"qa_only",true},{"kind","remove-current-squad-membership"},{"playerId",person},{"archive","unchanged"},{"real_retirement",false}});
|
||||
}
|
||||
modern::set_current_world(nullptr);auto fixture=EngineBridge::open(world,out/"archived.obs");const auto bundle=fixture->snapshot(),index=fixture->read({{"kind","report-index"}}),read=fixture->read({{"kind","player-rankings"},{"leagueId",league},{"scope",0}});const auto value=engine_rankings_projection(bundle,index,read,league,0);
|
||||
if(value.at("categories")[0][0].at("player")!=person||!value.at("categories")[0][0].at("currentTeam").is_null())throw std::runtime_error("archived-only counterexample not retained");write("rankings.json",read);std::cout<<"synthetic archived-only rankings fixture passed\n";return 0;
|
||||
}
|
||||
auto link = EngineBridge::open(world, out / "input.obs");
|
||||
const auto before = link->snapshot(); write("before.json", before);
|
||||
if (before != link->snapshot()) throw std::runtime_error("reads changed the engine projection");
|
||||
@@ -337,6 +352,13 @@ int main(int argc, char **argv) {
|
||||
write("saved.json",link->save_copy(out/"reports.obs"));link.reset();link=EngineBridge::open(world,out/"reports.obs");
|
||||
if(link->read({{"kind","report-index"}}).at("data")!=index_read.at("data"))throw std::runtime_error("report index changed after OBS restart");
|
||||
}
|
||||
if(mode=="verify-rankings") {
|
||||
const auto index=link->read({{"kind","report-index"}}),catalogue=engine_report_index(before,index);write("rankings-index.json",index);Json all=Json::array();
|
||||
for(const auto &league:catalogue.at("leagues"))for(int scope=0;scope<2;++scope){const Json request={{"kind","player-rankings"},{"leagueId",league.at("id")},{"scope",scope}};const auto read=link->read(request);write("latest-read.json",read);(void)engine_rankings_projection(before,index,read,league.at("id"),scope);if(link->read(request)!=read)throw std::runtime_error("rankings read is not repeatable");all.push_back(read);}
|
||||
const auto fair=link->read({{"kind","fairplay"}});write("fairplay.json",fair);(void)engine_fairplay_projection(before,index,fair);write("all-rankings.json",all);
|
||||
if(link->snapshot()!=before)throw std::runtime_error("rankings changed engine");write("saved.json",link->save_copy(out/"rankings.obs"));link.reset();link=EngineBridge::open(world,out/"rankings.obs");
|
||||
if(link->read({{"kind","fairplay"}}).at("data")!=fair.at("data"))throw std::runtime_error("fairplay changed after OBS restart");
|
||||
}
|
||||
if(mode=="verify-other") {
|
||||
const auto index=link->read({{"kind","other-index"}}),data=engine_other_index(before,index);write("other-index.json",index);Json all=Json::array();
|
||||
for(const auto &v:data.at("views"))for(int round=1;round<=v.at("rounds").get<int>();++round) {
|
||||
|
||||
@@ -387,6 +387,18 @@ int main() {
|
||||
bad_other=other_read;bad_other["data"]["matches"][0]["result"]={1,2};rejects([&]{engine_other_projection(report_bundle,other_index,bad_other,"cup-view:0:0",1);});
|
||||
bad_other=other_read;bad_other["data"]["entry"]=1;rejects([&]{engine_other_projection(report_bundle,other_index,bad_other,"cup-view:0:0",1);});
|
||||
bad_other=other_read;bad_other["meta"]["stateRevision"]="42";rejects([&]{engine_other_projection(report_bundle,other_index,bad_other,"cup-view:0:0",1);});
|
||||
auto rankings_bundle=report_bundle;for(auto &r:rankings_bundle)r["meta"]["season"]={{"label","2026/27"}};
|
||||
const auto rw=[&](const Json &d){return Json{{"messageType","snapshot"},{"meta",rankings_bundle.at("desktop").at("meta")},{"data",d}};};const auto ri=rw(report_index_data);
|
||||
Json ranking_row={{"rank",1},{"player",{{"id","player:score"},{"name","Synthetic Scorer"}}},{"club",{{"id","club:6"},{"name","Live A"}}},{"goals",2},{"assists",1},{"yellow",0},{"red",0},{"second_yellow",0},{"appearances",3},{"value",2},{"photoAssetId",nullptr},{"currentTeam",{{"id","club:7"},{"name","Live B"}}}};
|
||||
Json rc=Json::array({Json::array({ranking_row}),Json::array(),Json::array(),Json::array()});const auto rr=rw({{"kind","player-rankings"},{"requestLeagueId","league:live"},{"leagueId","league:live"},{"scope",0},{"season","2026/27"},{"team",{{"id","club:6"},{"name","Live A"}}},{"categories",rc}});
|
||||
require(engine_rankings_projection(rankings_bundle,ri,rr,"league:live",0).at("categories")[0][0].at("player")=="player:score","ranked player identity lost");
|
||||
auto archived_rank=rr;archived_rank["data"]["categories"][0][0]["currentTeam"]=nullptr;require(engine_rankings_projection(rankings_bundle,ri,archived_rank,"league:live",0).at("categories")[0][0].at("currentTeam").is_null(),"archived-only identity received a fake current team");
|
||||
auto bad_rank=rr;bad_rank["data"]["categories"][0][0]["rank"]=2;rejects([&]{engine_rankings_projection(rankings_bundle,ri,bad_rank,"league:live",0);});
|
||||
bad_rank=rr;bad_rank["data"]["categories"][0][0]["value"]=5;rejects([&]{engine_rankings_projection(rankings_bundle,ri,bad_rank,"league:live",0);});
|
||||
bad_rank=rr;bad_rank["data"]["season"]="2025/26";rejects([&]{engine_rankings_projection(rankings_bundle,ri,bad_rank,"league:live",0);});
|
||||
bad_rank=rr;bad_rank["meta"]["stateRevision"]="42";rejects([&]{engine_rankings_projection(rankings_bundle,ri,bad_rank,"league:live",0);});
|
||||
const auto fr=rw({{"kind","fairplay"},{"leagueId","league:live"},{"season","2026/27"},{"weights",{{"yellow",1},{"red",4}}},{"recordedMatches",1},{"rows",{{{"rank",1},{"team",{{"id","club:6"},{"name","Live A"}}},{"yellow",1},{"red",0},{"points",1}},{{"rank",2},{"team",{{"id","club:7"},{"name","Live B"}}},{"yellow",0},{"red",1},{"points",4}}}}});
|
||||
require(engine_fairplay_projection(rankings_bundle,ri,fr).at("rows").size()==2,"fairplay rows lost");auto bad_fair=fr;bad_fair["data"]["rows"][1]["points"]=1;rejects([&]{engine_fairplay_projection(rankings_bundle,ri,bad_fair);});
|
||||
std::cout << "engine DTO, exact money, scope and booking tests passed\n";
|
||||
return 0;
|
||||
} catch (const std::exception &e) { std::cerr << e.what() << '\n'; return 1; }
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
// Authored archive events; no game data or assets.
|
||||
#include "modern/content/statistics.hpp"
|
||||
#include "modern/content/ui_contract.hpp"
|
||||
#include "game/schedule.hpp"
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
using namespace bmh;
|
||||
namespace {
|
||||
using J=cli::Json;using O=J::Object;
|
||||
const J& at(const J& j,const char* k){return j.object()->at(k);}
|
||||
int n(const J& j){return int(*j.integer());}
|
||||
void check(bool yes,const char* why){if(!yes)throw std::runtime_error(why);}
|
||||
}
|
||||
int main() try {
|
||||
modern::ModernState g;g.manager_teams={0};g.manager_records.resize(0xb0c);g.display_start_year=2026;
|
||||
for(int l=0;l<kLeagueCount;++l){g.world_league_id.push_back("league:"+std::to_string(l));g.world_league_name.push_back("Synthetic league "+std::to_string(l));}
|
||||
for(int t=0;t<modern::league_clubs();++t){g.world_club_id.push_back("club:"+std::to_string(t));g.world_club_name.push_back("Synthetic club "+std::to_string(t));}
|
||||
auto &s=g.almanac.current;s.season=0;s.start_year=2026;s.display_start_year=2026;s.clubs={{"club:0","Club A"},{"club:1","Club B"}};s.players={{"player:a","Alpha","One",""},{"player:b","Beta","Two",""},{"player:c","Gamma","Three",""}};s.leagues={{0,"league:0","Synthetic league 0"}};
|
||||
modern::AlmanacMatch m;m.type=0;m.league=0;m.home=0;m.away=1;m.home_goals=1;m.date=100;
|
||||
m.lineup[0].assign(12,modern::kAlmanacNone);m.lineup[0][0]=0;m.lineup[0][11]=1;m.lineup[1]={2};
|
||||
using K=modern::AlmanacEventKind;
|
||||
m.events={{K::Substitution,45,0,0,1,modern::kAlmanacNone},{K::Goal,60,0,0,0,1},{K::YellowCard,70,0,0,0,modern::kAlmanacNone},{K::SecondYellow,80,0,0,0,modern::kAlmanacNone},{K::RedCard,85,1,0,2,modern::kAlmanacNone},{K::ShootoutKick,121,0,1,0,modern::kAlmanacNone}};
|
||||
s.matches.push_back(m);
|
||||
auto second=m;second.home=1;second.away=0;second.date=130;second.home_goals=1;second.away_goals=1;second.lineup[0]={0,2};second.lineup[1]={1};second.events={{K::Goal,50,0,0,0,2},{K::Goal,55,1,0,1,modern::kAlmanacNone}};s.matches.push_back(second);
|
||||
auto cup=m;cup.type=1;cup.league=0xff;s.matches.push_back(cup);
|
||||
const auto read=[&](int scope){return modern::query_rankings(g,0,O{{"kind","player-rankings"},{"leagueId","league:0"},{"scope",scope}});};
|
||||
const auto all=read(0);const auto &cats=*at(all,"categories").array();check(cats.size()==4&&cats[0].array()->size()==2,"rankings categories missing");
|
||||
const auto &leader=cats[0].array()->at(0);check(*at(at(leader,"player"),"id").string()=="player:a"&&n(at(leader,"value"))==2,"goals include cup/shootout or lost league goal");check(*at(at(leader,"club"),"id").string()=="club:1","last recorded club not retained");check(n(at(leader,"appearances"))==2,"appearances changed");check(n(at(cats[1].array()->at(0),"value"))==1,"assist missing");check(cats[3].array()->size()==2&&n(at(cats[3].array()->at(0),"rank"))==1&&n(at(cats[3].array()->at(1),"rank"))==1,"red plus second-yellow tied rank changed");
|
||||
const auto own=read(1);const auto &own_goals=*at(own,"categories").array()->at(0).array();check(own_goals.size()==2&&n(at(own_goals[0],"value"))==1&&n(at(own_goals[1],"value"))==1,"own scope counted other club contributions");for(const auto &r:own_goals)check(*at(at(r,"club"),"id").string()=="club:0","own scope has foreign club");
|
||||
const auto fair=modern::query_rankings(g,0,O{{"kind","fairplay"}});check(n(at(fair,"recordedMatches"))==2,"fairplay counted cup");const auto &rows=*at(fair,"rows").array();check(rows.size()==size_t(kLeagueSizes[0]),"zero-card clubs missing");int total=0;for(const auto &r:rows)total+=n(at(r,"points"));check(total==9,"fairplay weighting or card side changed");check(n(at(rows.back(),"yellow"))==1&&n(at(rows.back(),"red"))==1&&n(at(rows.back(),"points"))==5,"second yellow counted incorrectly");
|
||||
s.start_year=2025;const auto empty=read(0);for(const auto &cat:*at(empty,"categories").array())check(cat.array()->empty(),"previous season counted as current");s.start_year=2026;
|
||||
check(!std::get<bool>(at(read(2),"ok").value),"invalid scope accepted");
|
||||
modern::UiContext context;context.manager=0;context.state_revision=9;const auto wrapped=modern::ui_read(g,context,O{{"kind","player-rankings"},{"leagueId","league:0"},{"scope",0}});check(*at(wrapped,"messageType").string()=="snapshot"&&*at(at(wrapped,"meta"),"stateRevision").string()=="9","runtime envelope missing");
|
||||
check(s.matches.size()==3&&s.matches[0].events.size()==6,"read changed archive");
|
||||
std::cout<<"current season, own-club transfers, tied ranks, appearances, cards and pure reads passed\n";return 0;
|
||||
} catch(const std::exception& e){std::cerr<<e.what()<<'\n';return 1;}
|
||||
Reference in new issue
Block a user