Files
Dreierpack-Manager/tests/modern_assembly_tests.cpp
MichaelandClaude Fable 5.2 a2b9770d81 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>
2026-11-17 12:58:36 +01:00

146 lines
6.4 KiB
C++

// 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;
}