Annual general meeting and change of club

At the end of a season three groups of members vote on a human manager.
Below half of the votes he has to take over one of up to seven interested
clubs; the same list lets a manager leave on his own from the manager page.
The meeting is shown as a needle that swings between red and green and
comes to rest on the result.

Engine: assembly_vote, club_offers, change_club; read "assembly", command
manager.clubChange, field assembly of session.advance; saved in
state/modern.json. Dismissals are always on until the options offer them.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
MichaelandClaude Fable 5.2 committed 2026-11-17 12:58:36 +01:00
1 parent 811edfa900
commit a2b9770d81
24 files changed
+1016 -7

No files matched your search

+145
View File
@@ -0,0 +1,145 @@
// SPDX-License-Identifier: GPL-3.0-only
// The annual general meeting and the interested clubs (docs/new_engine/hauptversammlung.md) on a
// synthetic world: the three groups' approval, the dismissal, and the list of clubs.
#include <cstdio>
#include <set>
#include "game/schedule.hpp"
#include "modern/game/assembly.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;
}
}
void put16(std::vector<uint8_t>& v, size_t at, uint16_t x) { v[at] = uint8_t(x), v[at + 1] = uint8_t(x >> 8); }
void put32(std::vector<uint8_t>& v, size_t at, uint32_t x) {
for (int i = 0; i < 4; ++i) v[at + size_t(i)] = uint8_t(x >> (8 * i));
}
// Manager 0 runs club 0. Every German club fields eleven players of one strength: `own` for his
// club, 30 for the others.
ModernState world(int own) {
ModernState g;
g.career_id = "career:test";
g.level = 2;
g.manager_teams = {0};
g.manager_records.assign(5 * 0xb0c, 0);
g.manager_records[0x211] = 50, g.manager_records[0x26f] = 50; // prestige, standing with the bank
for (size_t i = 0; i < 6; ++i) put16(g.manager_records, 0x8aa + 2 * i, 550);
put32(g.manager_records, 0x314, 500000);
put16(g.manager_records, 4 * 0xb0c + 0x290, 0xffff);
g.team_morale.assign(419, 50);
g.stocks.assign(12 * 0x5c, 0);
g.squad_slots.assign(3150, kEmptySlot);
for (int team = 0; team < german_clubs(); ++team) {
const SquadRange range = squad_range(team);
const uint32_t skill = uint32_t(team == 0 ? own : 30);
for (int i = 0; i < 11; ++i) {
Player p;
p.w35c = 50u | skill << 7 | skill << 14; // form, technique, condition
p.w364 = uint32_t(i == 0 ? 0 : 1 + (i - 1) % 3); // position
g.squad_slots[range.first + size_t(i)] = uint16_t(g.players.size()) | kSlotInLineup;
g.players.push_back(p);
}
}
return g;
}
} // namespace
int main() {
// a manager with everything in the middle and nothing to compare with
{
const ModernState g = world(60);
const AssemblyVote v = assembly_vote(g, 0);
check(v.sport == 54 && v.finance == 60 && v.supporters == 46, "the neutral manager: 54 / 60 / 46");
check(v.yes == 53 && v.confirmed, "the neutral manager is confirmed");
check(v.assets == 500000 && v.place == league_first_team(0) + 9, "what the next meeting compares with");
}
// nine places lost and a million and a half gone: voted out
{
ModernState g = world(60);
g.assembly = {{2000000, league_first_team(0), 0}};
const AssemblyVote v = assembly_vote(g, 0);
check(v.sport == 38, "nine places lost cost the sporting side 16 points");
check(v.finance == 10, "assets lost: the treasurers' approval is at its floor");
check(v.yes == 31 && !v.confirmed, "voted out");
assembly_remember(g, 0, v);
check(g.assembly[0].assets == v.assets && g.assembly[0].place == v.place && g.assembly[0].voted_season == g.season,
"the vote becomes the base of the next");
}
// hoarded cash costs approval, assets are capped at two million
{
ModernState g = world(60);
put32(g.manager_records, 0x314, 9000000);
put32(g.manager_records, 0x318, 5000000);
g.assembly = {{0, league_first_team(0) + 9, 0}};
const AssemblyVote v = assembly_vote(g, 0);
check(v.assets == 2000000, "assets count up to two million");
check(v.finance == 95, "hoarded cash: 85 % of the approval, then the ten points of every group");
}
// the baseline of a manager who has just taken the club
{
ModernState g = world(60);
assembly_baseline(g, 0);
check(g.assembly.size() == 1 && g.assembly[0].assets == 500000 && g.assembly[0].place == league_first_team(0) + 9 &&
g.assembly[0].voted_season == -1,
"baseline: his assets now, the middle of the league, no vote yet");
}
// the interested clubs
{
const ModernState g = world(80);
const auto offers = club_offers(g, 0);
check(!offers.empty() && offers.size() <= 7, "one to seven clubs");
check(offers.front().team >= german_clubs() - 10 && offers.front().team < german_clubs(), "the first is one of the last ten clubs");
std::set<int> teams;
bool sound = true;
for (const ClubOffer& o : offers) {
sound = sound && o.team > 0 && o.team < german_clubs() && teams.insert(o.team).second && o.cash >= -3000000 && o.cash <= 4500000;
}
check(sound, "German clubs no human manages, each once, with a start cash in range");
const auto again = club_offers(g, 0);
bool same = again.size() == offers.size();
for (size_t i = 0; same && i < offers.size(); ++i) same = again[i].team == offers[i].team && again[i].cash == offers[i].cash;
check(same, "looking at the list does not change it");
// over many fortnights a strong eleven gets more than the one certain offer
ModernState later = g;
size_t most = 0;
std::set<int> firsts;
for (uint32_t fortnight = 0; fortnight < 40; ++fortnight) {
later.date = fortnight * 14;
const auto list = club_offers(later, 0);
most = std::max(most, list.size());
firsts.insert(list.front().team);
}
check(most > 1 && firsts.size() > 1, "the list changes with the fortnight and can hold several clubs");
}
// a weak eleven: only the one certain offer
{
ModernState g = world(30);
bool only_one = true;
for (uint32_t fortnight = 0; fortnight < 40; ++fortnight) {
g.date = fortnight * 14;
only_one = only_one && club_offers(g, 0).size() == 1;
}
check(only_one, "no club is interested in a manager whose eleven is no stronger than theirs, except the certain one");
}
// the easiest level: every club brings fifty million
{
ModernState g = world(80);
g.level = 0;
const auto offers = club_offers(g, 0);
bool rich = !offers.empty();
for (const ClubOffer& o : offers) rich = rich && o.cash == 50000000;
check(rich, "level 0: fifty million");
}
if (failures) return 1;
std::puts("modern_assembly_tests: ok");
return 0;
}
+39
View File
@@ -948,6 +948,45 @@ int main(int argc, char** argv) {
const J curves = session.read_statistics_screen(O{{"section", 2}});
check(!club_desk || (at(curves, "series").array() && at(curves, "series").array()->size() == 6), "the six curves of the original");
}
// the annual general meeting and the interested clubs: the read, then a change of club
{
const J meeting = at(session.ui_read(O{{"kind", "assembly"}}, rev), "data");
if (truth(at(meeting, "available"))) {
const J& vote = at(meeting, "vote");
check(vote.object() && at(vote, "yes").integer() && *at(vote, "yes").integer() >= 0 && *at(vote, "yes").integer() <= 100 &&
!truth(at(meeting, "due")) && truth(at(meeting, "dismissals")),
"assembly: a vote, not due in the season, dismissals on");
const auto* offers = at(meeting, "offers").array();
check(offers && !offers->empty() && offers->size() <= 7, "assembly: one to seven interested clubs");
const std::string own = s(at(at(meeting, "club"), "teamId"));
check(cli::dump_json(at(session.ui_read(O{{"kind", "assembly"}}, rev), "data")) == cli::dump_json(meeting), "assembly: reading changes nothing");
const auto change = [&](const std::string& id, J payload) {
return session.ui_command(cmd(id, "manager.clubChange", std::move(payload)), rev);
};
const uint64_t before = rev;
check(s(at(change("request:cc1", O{{"teamId", own}}), "code")) == "confirmation_required", "club change needs the confirmation");
check(s(at(change("request:cc2", O{{"teamId", own}, {"confirmed", true}}), "code")) == "club_change_refused" && rev == before,
"a club that is not interested is refused, nothing changes");
if (offers && !offers->empty()) {
const std::string to = s(at(offers->front(), "teamId"));
const std::string cash = cli::dump_json(at(offers->front(), "cash"));
const J done = change("request:cc3", O{{"teamId", to}, {"confirmed", true}});
if (s(at(done, "messageType")) != "command_result") std::fprintf(stderr, "club change: %s\n",cli::dump_json(done).c_str());
check(s(at(done, "messageType")) == "command_result" && rev == before + 1, "club change accepted");
const J after = at(session.ui_read(O{{"kind", "assembly"}}, rev), "data");
check(s(at(at(after, "club"), "teamId")) == to, "the manager runs the new club");
const J bank = at(session.ui_read(O{{"kind", "bank"}}, rev), "data");
check(cli::dump_json(bank).find(cash) != std::string::npos, "he starts with the cash the club offered");
const J lineup = at(session.ui_read(O{{"kind", "lineup"}}, rev), "data");
check(lineup.object() != nullptr, "the new club has a line-up to read");
for (int k = 0; k < 3; ++k) {
const J next = session.ui_command(cmd("request:cc-go" + std::to_string(k), "session.advance", O{}), rev);
if (s(at(next, "messageType")) != "command_result") std::fprintf(stderr, "advance after change: %s\n",cli::dump_json(next).c_str());
check(s(at(next, "messageType")) == "command_result", "the game goes on at the new club");
}
}
}
}
// resigning: needs the confirmation; the last human manager ends the career
{
const auto resign = [&](const std::string& id, J payload) {