Toto with up to six columns (Modern)

Each column costs the stake (10,000-400,000) and is settled on its own
with the original quotas; all columns stake 400,000 at most, every
column beyond the first adds a 10 % fee, no two columns alike. Column 1
stays on the original coupon; columns 2-6 and the last settlement live
in ModernState::pools and are saved. Session action
dispatch_pools_columns, read query {kind: "toto"}, unit test
modern_toto_tests, SIM_TOTO=<columns> in the season sim.

Measured over two seasons: 1 column returns 30-71 %, 6 columns 12-49 %
of the stakes; more columns win more often, never on average.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ClaudeandClaude Opus 5.5 committed 2026-10-24 11:06:57 +02:00
1 parent 4639fe5a91
commit 0aa0ed68ca
14 files changed
+357 -10

No files matched your search

+3
View File
@@ -1172,6 +1172,9 @@ add_test(NAME modern_camp_tests COMMAND modern_camp_tests)
add_executable(modern_almanac_tests tests/modern_almanac_tests.cpp)
target_link_libraries(modern_almanac_tests PRIVATE bmh_season_modern)
add_test(NAME modern_almanac_tests COMMAND modern_almanac_tests)
add_executable(modern_toto_tests tests/modern_toto_tests.cpp)
target_link_libraries(modern_toto_tests PRIVATE bmh_season_modern)
add_test(NAME modern_toto_tests COMMAND modern_toto_tests)
add_executable(modern_calendar_tests tests/modern_calendar_tests.cpp)
target_link_libraries(modern_calendar_tests PRIVATE bmh_season_modern)
+1
View File
@@ -36,6 +36,7 @@ describe deliberate changes; they are not a list of every known compatibility li
- [src/modern/game/career.hpp](../src/modern/game/career.hpp): uses the supported player-generation ranges and excludes reserved calendar positions when assigning managers.
- [src/modern/game/desk_actions.cpp](../src/modern/game/desk_actions.cpp): uses the supported transfer-fee arithmetic and designated set-piece fields.
- [src/modern/game/desk_actions.cpp](../src/modern/game/desk_actions.cpp): Modern training camps have grades up to six stars with a capped step, a higher limit and recovery extras.
- [src/modern/game/desk_actions.cpp](../src/modern/game/desk_actions.cpp): the Modern Toto takes up to six columns (one in the original), each at the stake plus a 10 % fee per extra column, 400,000 at most in all.
- [src/modern/game/desk_actions.hpp](../src/modern/game/desk_actions.hpp): supports designated set-piece records and the supported transfer-editor rules.
- [src/modern/game/environment.hpp](../src/modern/game/environment.hpp): uses six monthly environment budgets across data editions while retaining the shared staff prices and academy player-generation strength bands.
- [src/modern/game/highscore.cpp](../src/modern/game/highscore.cpp): reads the supported edition-specific high-score format from the loaded image.
+37
View File
@@ -0,0 +1,37 @@
# Toto mit mehreren Spalten (Modern)
Michaels Wunsch: Man kann mehr als eine Spalte spielen (bis zu 6); die Regel soll das Gewinnen nicht zu einfach machen. Regel abgestimmt am 24.10.2026.
## Original (Classic, unverändert)
- Ein Tippschein mit 11 Spielen zwischen etwa gleich starken Vereinen, je Spiel 1 (Heimsieg), 0 (Unentschieden) oder 2 (Auswärtssieg).
- Einsatz 10.000–400.000 €, abgebucht am Ende des Spieltags.
- Feste Quoten auf den Einsatz: 9 Richtige ×10, 10 Richtige ×20, 11 Richtige ×50.
## Modern
1. Bis zu **6 Spalten**; jede Spalte kostet den Einsatz und wird einzeln mit den Original-Quoten ausgewertet.
2. Einsatz **je Spalte** 10.000–400.000 €, alle Spalten zusammen höchstens **400.000 €**.
3. Jede Spalte ab der zweiten kostet **10 % ihres Einsatzes** als Bearbeitungsgebühr.
4. **Keine zwei gleichen Spalten.**
5. Kosten: `Einsatz × Spalten + Einsatz / 10 × (Spalten − 1)` (`pools_cost`). Reicht das Geld nicht, gilt der ganze Tippschein als nicht abgegeben (Meldung wie im Original).
Warum das nicht zu leicht ist: Die Quoten sind fest, also bringt jede Spalte für sich denselben Erwartungswert, egal wie die Spalten zusammenhängen. Mehr Spalten erhöhen nur die Chance auf irgendeinen Gewinn, nicht den Rückfluss; die Gebühr macht das Absichern über mehrere Spalten zusätzlich teurer.
**Messung** (`SIM_TOTO=<Spalten> SIM_CONTRACTS=1 SIM_ADVERTISING=1 modern_season_sim <welt.obw> 100 0 <seed>`, zwei Saisons, 400.000 € je Spieltag, Tipp: der stärkere Verein gewinnt, Zusatzspalten tippen je ein Unentschieden):
| Spalten | Rückfluss (Seeds 1, 2) | Spalten mit 9+ Richtigen je Tippschein |
|---|---|---|
| 1 | 30 % / 71 % | etwa 3–5 % |
| 3 | 30 % / 64 % | etwa 3–4 % je Spalte, 7–10 % je Tippschein |
| 6 | 12 % / 49 % | etwa 8–18 % je Tippschein |
Toto bleibt im Schnitt ein Verlustgeschäft; mit mehr Spalten gewinnt man öfter etwas, aber nicht mehr.
## Umsetzung
- Spalte 1 liegt im Original-Tippschein (`Coupon + Manager × 0x14`), damit alle bestehenden Abläufe unverändert bleiben; die Spalten 2–6 und die letzte Abrechnung (Treffer je Spalte, bezahlt, gewonnen) in `ModernState::pools`, gespeichert in `state/modern.json` (`pools`).
- Abgabe: `submit_pools_columns` (`desk_actions.hpp`), in der Session `dispatch_pools_columns(manager, stake, columns, revision, error)`; Fehler `too_many_columns`, `stake_out_of_range`, `total_stake_too_high`, `duplicate_column`, `toto_coupon_requires_eleven_matches`, `invalid_toto_coupon`. Die alte Einspalten-Aktion (`dispatch_toto`) verwirft frühere Zusatzspalten.
- Abrechnung: `settle_pools_coupon` (`matchday_setup.cpp`).
- Lesen: `{kind: "toto"}` über `ModernSession::read` ([UI-Abfragen](ui-abfragen.md)): `open`, `matches [{home, away}]`, `stake`, `cost`, `columns`, `rules`, `last {paid, won, hits}`.
- Tests: `modern_toto_tests` (Regeln, Kosten); Spielstand-Rundreise im Sim prüft die Spalten mit.
+1
View File
@@ -23,6 +23,7 @@ Michaels Entscheidung: Die neue Oberfläche wird **je Menü** an die Modern-Engi
| `{kind: "leagues"}` | `leagues: [{index, id, name, clubs, matchdays, played}]` |
| `{kind: "table", league}` | `league`, `played`, `rows: [{rank, club, played, won, drawn, lost, goals_for, goals_against, points}]` (aktueller Stand, mit Punktabzug) |
| `{kind: "fixtures", league, matchday?}` | `league`, `matchday`, `matches: [{home, away, result: [h, a] \| null, status: open \| played \| postponed}]`; ohne `matchday` der nächste |
| `{kind: "toto"}` | Tippschein des Spieltags und eigene Spalten, siehe [Toto](toto.md) |
| `{kind: "squad", club?}` | `club`, `players: [{slot, player, nation, position (gk/def/mid/fwd), age, technique, condition, form, strength, skills {teamplay, speed, shooting, passing, tackling, free_kick, corner}, lineup (start/bench/none), injured_weeks, banned_weeks}]`; ohne `club` der eigene Verein, sonst Welt-ID oder Laufzeitindex |
| `competitions`, `winners`, `player_stats` | siehe [Spielstatistik](statistik.md) |
+21 -1
View File
@@ -8582,13 +8582,33 @@ bool ModernSession::dispatch_toto(const ui::TotoRequest& request, uint64_t& revi
error = "stale_manager_or_revision"; return false;
}
if (g_.memory.u8(::bmh::layout::CareerSession_DispatchToto_RuntimeField) != 11) { error = "toto_coupon_requires_eleven_matches"; return false; }
if (!modern::submit_pools_coupon(g_, request.manager_slot, request.stake, request.tips)) {
// one column: the original coupon; earlier extra columns of this manager are dropped
if (modern::submit_pools_columns(g_, request.manager_slot, request.stake, {request.tips}) != PoolsColumnsResult::ok) {
error = "invalid_toto_coupon"; return false;
}
++revision;
return true;
}
bool ModernSession::dispatch_pools_columns(int manager, uint32_t stake, const std::vector<std::array<uint8_t, 11>>& columns,
uint64_t& revision, std::string& error) {
const int active = int(g_.memory.u8(::bmh::layout::ActiveManager));
if (manager != active || manager < 0 || size_t(manager) >= g_.manager_teams.size()) {
error = "stale_manager_or_revision"; return false;
}
if (g_.memory.u8(::bmh::layout::CareerSession_DispatchToto_RuntimeField) != 11) { error = "toto_coupon_requires_eleven_matches"; return false; }
switch (modern::submit_pools_columns(g_, manager, stake, columns)) {
case PoolsColumnsResult::ok: ++revision; return true;
case PoolsColumnsResult::too_many_columns: error = "too_many_columns"; return false;
case PoolsColumnsResult::stake_out_of_range: error = "stake_out_of_range"; return false;
case PoolsColumnsResult::total_too_high: error = "total_stake_too_high"; return false;
case PoolsColumnsResult::duplicate_column: error = "duplicate_column"; return false;
case PoolsColumnsResult::invalid: break;
}
error = "invalid_toto_coupon";
return false;
}
} // namespace bmh::modern::app
namespace bmh::modern::app {
+5
View File
@@ -601,6 +601,11 @@ public:
}
bool stadium_tip_deadline_expired() const;
bool dispatch_toto(const ui::TotoRequest&, uint64_t& revision, std::string& error);
// Modern Toto with up to six columns for the manager at the desk (docs/new_engine/toto.md).
// Errors: too_many_columns, stake_out_of_range, total_stake_too_high, duplicate_column,
// toto_coupon_requires_eleven_matches, invalid_toto_coupon, stale_manager_or_revision.
bool dispatch_pools_columns(int manager, uint32_t stake, const std::vector<std::array<uint8_t, 11>>& columns,
uint64_t& revision, std::string& error);
bool dispatch_tactics(const ui::TacticsRequest&, uint64_t& revision, std::string& error);
bool dispatch_lineup(const ui::LineupRequest&, uint64_t& revision, std::string& error);
// Source PitchScreen live-match path: apply one user-picked field/bench
+46
View File
@@ -10,7 +10,9 @@
#include "game/schedule.hpp"
#include "game/table.hpp"
#include "modern/content/statistics.hpp"
#include "formats/executable_layout.hpp"
#include "modern/game/almanac.hpp"
#include "modern/game/desk_actions.hpp"
#include "modern/game/matchday.hpp"
namespace bmh::modern {
@@ -201,6 +203,49 @@ J squad(const ModernState& g, int team) {
return O{{"ok", true}, {"club", club_json(g, team)}, {"players", std::move(players)}};
}
// The Toto coupon of the matchday and the manager's columns (docs/new_engine/toto.md).
J toto(const ModernState& g, int manager) {
if (manager < 0 || size_t(manager) >= g.manager_teams.size()) return error("invalid_manager");
const StaticMemory& mem = g.memory;
const uint32_t matches_at = ::bmh::layout::DeskActions_SubmitPoolsCoupon_RuntimeField;
const int count = mem.has(::bmh::layout::CareerSession_DispatchToto_RuntimeField) ? mem.u8(::bmh::layout::CareerSession_DispatchToto_RuntimeField) : 0;
A matches;
for (int k = 0; k < count && k < 11 && mem.has(matches_at + uint32_t(k) * 4 + 3); ++k)
matches.push_back(O{{"home", club_json(g, mem.u16(matches_at + uint32_t(k) * 4))},
{"away", club_json(g, mem.u16(matches_at + uint32_t(k) * 4 + 2))}});
const uint32_t at = ::bmh::layout::Coupon + uint32_t(manager) * 0x14;
uint32_t stake = 0;
A columns;
if (mem.has(at + 0x13)) {
stake = mem.u32(at) & 0x7fffffff;
if (stake != 0) {
A first;
for (uint32_t i = 0; i < 11; ++i) first.push_back(int(mem.u8(at + 8 + i)));
columns.push_back(std::move(first));
if (size_t(manager) < g.pools.size())
for (const auto& column : g.pools[size_t(manager)].extra) {
A tips;
for (uint8_t t : column) tips.push_back(int(t));
columns.push_back(std::move(tips));
}
}
}
const int64_t cost = int64_t(pools_cost(stake, columns.size()));
O last{{"paid", 0}, {"won", 0}, {"hits", A{}}};
if (size_t(manager) < g.pools.size()) {
const auto& p = g.pools[size_t(manager)];
A hits;
for (uint8_t h : p.hits) hits.push_back(int(h));
last = O{{"paid", int64_t(p.paid)}, {"won", int64_t(p.won)}, {"hits", std::move(hits)}};
}
return O{{"ok", true}, {"open", count == 11}, {"matches", std::move(matches)}, {"stake", int64_t(stake)},
{"cost", cost}, {"columns", std::move(columns)},
{"rules", O{{"max_columns", kPoolsMaxColumns}, {"stake_min", 10000}, {"stake_max", 400000},
{"total_max", int64_t(kPoolsMaxTotalStake)}, {"extra_column_fee_percent", 10},
{"quota", O{{"9", 10}, {"10", 20}, {"11", 50}}}}},
{"last", std::move(last)}};
}
} // namespace
cli::Json query_projection(const ModernState& g, int manager, const cli::Json& request) {
@@ -209,6 +254,7 @@ cli::Json query_projection(const ModernState& g, int manager, const cli::Json& r
const std::string& k = *kind->string();
try {
if (k == "status") return status(g, manager);
if (k == "toto") return toto(g, manager);
if (k == "leagues") return leagues(g);
if (k == "table" || k == "fixtures") {
const int league = league_of_request(g, field(request, "league"));
+40 -1
View File
@@ -44,6 +44,43 @@ std::vector<std::string> strings(const J& value) {
}
std::string world_identity(const World& world) { return world.id + "@" + world.data_revision; }
// The Toto columns 2-6 and the last settlement per manager (docs/new_engine/toto.md).
J pools_json(const std::vector<ModernState::PoolsColumns>& pools) {
A out;
for (const auto& p : pools) {
A extra, hits;
for (const auto& column : p.extra) {
A tips;
for (uint8_t t : column) tips.push_back(int(t));
extra.push_back(std::move(tips));
}
for (uint8_t h : p.hits) hits.push_back(int(h));
out.push_back(O{{"extra", std::move(extra)}, {"hits", std::move(hits)}, {"paid", int64_t(p.paid)}, {"won", int64_t(p.won)}});
}
return out;
}
std::vector<ModernState::PoolsColumns> pools_json(const J& value) {
std::vector<ModernState::PoolsColumns> out;
for (const J& row : arr(value)) {
ModernState::PoolsColumns p;
for (const J& column : arr(get(row, "extra"))) {
const A& tips = arr(column);
if (tips.size() != 11) fail("invalid Toto column");
std::array<uint8_t, 11> c{};
for (size_t i = 0; i < 11; ++i) {
const int64_t t = num(tips[i]);
if (t < 0 || t > 2) fail("invalid Toto tip");
c[i] = uint8_t(t);
}
p.extra.push_back(c);
}
for (const J& h : arr(get(row, "hits"))) p.hits.push_back(uint8_t(num(h)));
p.paid = uint32_t(num(get(row, "paid"))), p.won = uint32_t(num(get(row, "won")));
out.push_back(std::move(p));
}
return out;
}
} // namespace
void save_world_career(const std::filesystem::path& path, const World& world, const ModernState& state,
@@ -69,7 +106,8 @@ void save_world_career(const std::filesystem::path& path, const World& world, co
{"player_nations", strings(state.player_nation)},
{"league_ids", strings(state.world_league_id)},
{"league_names", strings(state.world_league_name)},
{"generated_players", int64_t(state.almanac.generated_players)}});
{"generated_players", int64_t(state.almanac.generated_players)},
{"pools", pools_json(state.pools)}});
// The almanac: finished seasons unchanged, the running one encoded now.
for (const auto& [name, bytes] : state.almanac.finished) docs[name] = bytes;
if (state.almanac.current.season >= 0) docs["history/current.bin"] = encode_almanac_season(state.almanac.current);
@@ -117,6 +155,7 @@ SavedWorldCareer load_world_career(const std::filesystem::path& path, const Worl
out.state.world_league_id = strings(get(modern, "league_ids"));
out.state.world_league_name = strings(get(modern, "league_names"));
out.state.almanac.generated_players = uint32_t(num(get(modern, "generated_players")));
out.state.pools = pools_json(get(modern, "pools"));
for (const auto& [name, bytes] : docs) {
if (!name.starts_with("history/season-")) continue;
decode_almanac_season(bytes); // a damaged season fails here, not in the almanac screen
+23
View File
@@ -1867,6 +1867,29 @@ bool submit_pools_coupon(ModernState& g, int manager, uint32_t stake,
return true;
}
// OpenBMH deviates from the original: the Modern Toto takes up to six columns (one in the original), each at the stake plus a 10 % fee per extra column, 400,000 at most in all.
PoolsColumnsResult submit_pools_columns(ModernState& g, int manager, uint32_t stake,
const std::vector<std::array<uint8_t, 11>>& columns) {
if (manager < 0 || size_t(manager) >= g.manager_teams.size()) return PoolsColumnsResult::invalid;
if (g.pools.size() < g.manager_teams.size()) g.pools.resize(g.manager_teams.size());
if (stake == 0) { // clears the coupon
if (!modern::submit_pools_coupon(g, manager, 0, columns.empty() ? std::array<uint8_t, 11>{} : columns[0]))
return PoolsColumnsResult::invalid;
g.pools[size_t(manager)].extra.clear();
return PoolsColumnsResult::ok;
}
if (columns.empty()) return PoolsColumnsResult::invalid;
if (columns.size() > size_t(kPoolsMaxColumns)) return PoolsColumnsResult::too_many_columns;
if (stake < 10'000 || stake > 400'000) return PoolsColumnsResult::stake_out_of_range;
if (uint64_t(stake) * columns.size() > kPoolsMaxTotalStake) return PoolsColumnsResult::total_too_high;
for (size_t a = 0; a < columns.size(); ++a)
for (size_t b = a + 1; b < columns.size(); ++b)
if (columns[a] == columns[b]) return PoolsColumnsResult::duplicate_column;
if (!modern::submit_pools_coupon(g, manager, stake, columns[0])) return PoolsColumnsResult::invalid;
g.pools[size_t(manager)].extra.assign(columns.begin() + 1, columns.end());
return PoolsColumnsResult::ok;
}
} // namespace bmh::modern
namespace bmh::modern {
+14
View File
@@ -270,6 +270,20 @@ bool build_stadium_investment_source(ModernState&, int manager, StadiumInvestmen
bool submit_pools_coupon(ModernState& g, int manager, uint32_t stake,
const std::array<uint8_t, 11>& tips);
// Modern Toto with up to six columns (docs/new_engine/toto.md): each column costs the stake
// (10,000-400,000) and is settled on its own with the original quotas; all columns together
// stake at most 400,000; every column beyond the first adds a fee of 10 % of the stake; no two
// columns alike. Column 1 goes to the original coupon. A stake of 0 clears every column.
constexpr int kPoolsMaxColumns = 6;
constexpr uint32_t kPoolsMaxTotalStake = 400'000;
enum class PoolsColumnsResult { ok, invalid, too_many_columns, stake_out_of_range, total_too_high, duplicate_column };
PoolsColumnsResult submit_pools_columns(ModernState& g, int manager, uint32_t stake,
const std::vector<std::array<uint8_t, 11>>& columns);
// What a coupon of `columns` columns costs at `stake` per column (stakes plus fee).
inline uint32_t pools_cost(uint32_t stake, size_t columns) {
return columns == 0 ? 0 : uint32_t(stake * columns + stake / 10 * (columns - 1));
}
} // namespace bmh::modern
namespace bmh::modern {
+25 -7
View File
@@ -19,6 +19,7 @@
#include "game/schedule.hpp"
#include "game/messages.hpp"
#include "game/table.hpp"
#include "modern/game/desk_actions.hpp"
#include "modern/game/weekly.hpp"
namespace bmh::modern {
@@ -1216,24 +1217,41 @@ void settle_pools_coupon(ModernState& g, const std::vector<MatchGroup>& groups)
if (mem.has(::bmh::layout::CareerSession_DispatchToto_RuntimeField)) mem.set8(::bmh::layout::CareerSession_DispatchToto_RuntimeField, uint8_t(k));
if (k <= 10) return;
static constexpr uint8_t kQuota[12] = {11, 10, 0, 20, 11, 10, 0, 1, 0, 10, 20, 50}; // MatchdaySetupRuntimeField13
if (g.pools.size() < g.manager_teams.size()) g.pools.resize(g.manager_teams.size());
for (size_t m = 0; m < g.manager_teams.size(); m++) {
const uint32_t at = ::bmh::layout::Coupon + uint32_t(m) * 0x14;
if (mem.u8(at + 3) & 0x80) mem.set32(at, 0);
auto& extra = g.pools[m].extra;
if (mem.u8(at + 3) & 0x80) mem.set32(at, 0), extra.clear();
const uint32_t stake = mem.u32(at);
if ((stake & 0x7fffffff) == 0) continue;
if (!modern::book_money(g, int(m), int32_t(stake), false, true)) {
// Modern: every column costs the stake, every one beyond the first 10 % more
// (docs/new_engine/toto.md); with one column this is the original booking.
const uint32_t cost = pools_cost(stake, 1 + extra.size());
if (!modern::book_money(g, int(m), int32_t(cost), false, true)) {
post_composed(g, int(m), message_text(g, ::bmh::layout::MatchdaySetup_SettlePoolsCoupon_TextPointer));
} else {
int hits = 0;
for (uint32_t i = 0; i < 0xb; i++)
if (mem.u8(at + 8 + i) == mem.u8(::bmh::layout::MatchdaySetup_EvaluatePoolsCoupon_RuntimeField + i)) hits++;
uint32_t win = 0;
if (hits > 8) win = stake * kQuota[hits];
auto hits_of = [&](auto tip) {
int hits = 0;
for (uint32_t i = 0; i < 0xb; i++)
if (tip(i) == mem.u8(::bmh::layout::MatchdaySetup_EvaluatePoolsCoupon_RuntimeField + i)) hits++;
return hits;
};
const int hits = hits_of([&](uint32_t i) { return mem.u8(at + 8 + i); });
uint32_t win = hits > 8 ? stake * kQuota[hits] : 0;
std::vector<uint8_t> column_hits{uint8_t(hits)};
for (const auto& column : extra) {
const int h = hits_of([&](uint32_t i) { return column[i]; });
column_hits.push_back(uint8_t(h));
if (h > 8) win += stake * kQuota[h];
}
mem.set32(at + 4, win);
mem.set8(at + 0x13, uint8_t(hits));
g.pools[m].hits = std::move(column_hits);
g.pools[m].paid = cost, g.pools[m].won = win;
modern::book_money(g, int(m), -int32_t(win), true, true);
}
mem.set32(at, 0); // (also clears the "settled" bit 7 of byte 3 just set)
extra.clear();
}
}
+11
View File
@@ -8,7 +8,9 @@
// always prefers the Modern season function over a Classic one of the same name.
// Modern-only data (world layout, UTF-8 names, ...) is added here, never to GameState.
#include <array>
#include <cstddef>
#include <cstdint>
#include <string>
#include <utility>
#include <vector>
@@ -52,6 +54,15 @@ struct ModernState : GameState {
std::vector<TrainingCamp> training_camps;
// The football almanac (docs/new_engine/almanach.md): every match of the career.
Almanac almanac;
// Toto with up to six columns (docs/new_engine/toto.md), per manager. Column 1 is the
// original coupon (Coupon + manager * 0x14); columns 2-6 and the last settlement live here.
struct PoolsColumns {
std::vector<std::array<uint8_t, 11>> extra; // columns 2-6, tips 1 home, 0 draw, 2 away
std::vector<uint8_t> hits; // hits per column of the last settlement
uint32_t paid = 0, won = 0; // stakes and fee, winnings of the last settlement
bool operator==(const PoolsColumns&) const = default;
};
std::vector<PoolsColumns> pools;
// Players whose age the data set gives (birth date); the others carry a placeholder the
// career start replaces as in the original. Needed only while a career starts (not saved).
std::vector<bool> world_age_known;
+56 -1
View File
@@ -92,6 +92,21 @@ int g_high_scores = 0; // matches with 13-15 goals (outside shoot-outs)
int g_human_team = -1, g_human_for = 0, g_human_against = 0, g_human_matches = 0;
int g_league_goals = 0, g_league_matches = 0;
// A club's strength for the Toto tips of SIM_TOTO: mean of technique and condition of its
// first eleven squad slots.
int club_strength(const modern::ModernState& g, int team) {
const SquadRange r = squad_range(team);
int sum = 0, n = 0;
for (size_t s = r.first; s < r.first + std::min<size_t>(11, r.count); ++s) {
const int id = g.squad_slots.at(s) & 0xfff;
if (id == 0xfff) continue;
sum += (g.players.at(size_t(id)).technique() + g.players.at(size_t(id)).condition()) / 2, ++n;
}
return n ? sum / n : 0;
}
uint64_t toto_paid = 0, toto_won = 0;
int toto_coupons = 0, toto_hits[12] = {};
// The almanac of the run (docs/new_engine/almanach.md): size, consistency of the recorded
// goals with the results, and the top scorers over all seasons by stable player id.
void print_almanac(const modern::ModernState& g) {
@@ -476,6 +491,37 @@ int main(int argc, char** argv) {
modern::book_training_camp(g, 0, resort, session.rand()))
++camp_stays;
}
// SIM_TOTO=<columns>: the manager plays the Toto whenever a coupon is open, 400,000 in
// all spread over the columns: the stronger side (team strength) wins, column k > 1
// tips a draw in match k - 1 instead (docs/new_engine/toto.md).
if (const char* toto = std::getenv("SIM_TOTO")) {
auto& pools = g.pools;
if (!pools.empty() && !pools[0].hits.empty()) { // the last settlement
toto_paid += pools[0].paid, toto_won += pools[0].won, ++toto_coupons;
for (uint8_t h : pools[0].hits) toto_hits[std::min<int>(h, 11)]++;
pools[0].hits.clear();
}
const int columns = std::clamp(std::atoi(toto), 1, 6);
if (g.memory.has(::bmh::layout::CareerSession_DispatchToto_RuntimeField) &&
g.memory.u8(::bmh::layout::CareerSession_DispatchToto_RuntimeField) == 11) {
std::array<uint8_t, 11> base{};
for (uint32_t k = 0; k < 11; ++k) {
const int home = g.memory.u16(::bmh::layout::DeskActions_SubmitPoolsCoupon_RuntimeField + k * 4);
const int away = g.memory.u16(::bmh::layout::DeskActions_SubmitPoolsCoupon_RuntimeField + k * 4 + 2);
const int hs = home < modern::league_clubs() ? club_strength(g, home) : 0;
const int as = away < modern::league_clubs() ? club_strength(g, away) : 0;
base[k] = as > hs + 2 ? 2 : 1;
}
std::vector<std::array<uint8_t, 11>> tips{base};
for (int c = 1; c < columns; ++c) {
auto column = base;
column[size_t(c - 1)] = 0;
tips.push_back(column);
}
const uint32_t stake = std::max<uint32_t>(10000, 400000 / uint32_t(columns) / 10000 * 10000);
modern::submit_pools_columns(g, 0, stake, tips);
}
}
if (const char* ads = std::getenv("SIM_ADVERTISING"); ads && std::string(ads) == "1") {
for (int slot = 15; slot >= 0; --slot) {
AdvertisingOfferList list = modern::advertising_offers(g, 0, slot);
@@ -582,7 +628,7 @@ int main(int argc, char** argv) {
h.player_last == g.player_last && h.world_player_id == g.world_player_id;
const bool same_layout = world_layout().league_teams == layout.league_teams &&
world_layout().total_slots == layout.total_slots;
const bool same_almanac = h.almanac == g.almanac && h.world_league_id == g.world_league_id;
const bool same_almanac = h.almanac == g.almanac && h.world_league_id == g.world_league_id && h.pools == g.pools;
std::printf("save check at turn %d: state %s, names %s, layout %s, almanac %s, %ju bytes\n", played,
same_state ? "same" : "DIFFERS", same_names ? "same" : "DIFFER",
same_layout ? "same" : "DIFFERS", same_almanac ? "same" : "DIFFERS",
@@ -621,6 +667,15 @@ int main(int argc, char** argv) {
}
if (std::getenv("SIM_ADVERTISING")) std::printf("%d advertising contracts accepted (SIM_ADVERTISING=1)\n", ad_contracts);
if (std::getenv("SIM_CAMP")) std::printf("%d training camp stays (SIM_CAMP=%s)\n", camp_stays, std::getenv("SIM_CAMP"));
if (std::getenv("SIM_TOTO")) {
int won_coupons = 0;
std::printf("toto (SIM_TOTO=%s): %d coupons, paid %llu, won %llu, return %.1f %%; hits per column:", std::getenv("SIM_TOTO"),
toto_coupons, (unsigned long long)toto_paid, (unsigned long long)toto_won,
toto_paid ? 100.0 * double(toto_won) / double(toto_paid) : 0.0);
for (int h = 0; h <= 11; ++h) std::printf(" %d:%d", h, toto_hits[h]);
for (int h = 9; h <= 11; ++h) won_coupons += toto_hits[h];
std::printf(" (winning columns %d)\n", won_coupons);
}
if (std::getenv("SIM_INTERVENE")) std::printf("%d interventions (substitution at minute 30, re-rated)\n", interventions);
if (sim_contracts_env && std::string(sim_contracts_env) == "1")
std::printf("contract expiry policy: %d decisions, %d renewals, %d rejected offers/releases, %d no-demand releases, %d errors (SIM_CONTRACTS=1)\n",
+74
View File
@@ -0,0 +1,74 @@
// SPDX-License-Identifier: GPL-3.0-only
// The Modern Toto with up to six columns (docs/new_engine/toto.md): the rules of a coupon
// (columns, stakes, total, duplicates) and its cost, on a synthetic coupon block.
#include <cstdio>
#include "formats/executable_layout.hpp"
#include "modern/game/desk_actions.hpp"
#include "modern/game/modern_state.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;
}
}
// One manager, an open coupon of eleven matches.
ModernState coupon() {
ModernState g;
g.manager_teams = {0};
g.manager_records.assign(0xb0c, 0);
g.memory.add_block(::bmh::layout::Coupon, 5 * 0x14);
g.memory.add_block(::bmh::layout::DeskActions_SubmitPoolsCoupon_RuntimeField, 44);
g.memory.add_block(::bmh::layout::CareerSession_DispatchToto_RuntimeField, 1);
g.memory.set8(::bmh::layout::CareerSession_DispatchToto_RuntimeField, 11);
return g;
}
std::array<uint8_t, 11> column(uint8_t first) {
std::array<uint8_t, 11> c{};
c.fill(1);
c[0] = first;
return c;
}
} // namespace
int main() {
{
ModernState g = coupon();
check(submit_pools_columns(g, 0, 50000, {column(1), column(0), column(2)}) == PoolsColumnsResult::ok, "three columns");
check(g.memory.u32(::bmh::layout::Coupon) == 50000 && g.pools.at(0).extra.size() == 2, "column 1 on the coupon, 2-3 extra");
check(submit_pools_columns(g, 0, 50000, {column(1), column(1)}) == PoolsColumnsResult::duplicate_column, "no two columns alike");
check(submit_pools_columns(g, 0, 100000, {column(0), column(1), column(2), std::array<uint8_t, 11>{}}) == PoolsColumnsResult::ok,
"four columns of 100,000: 400,000 in all");
check(submit_pools_columns(g, 0, 100000, {column(0), column(1), column(2), std::array<uint8_t, 11>{}, column(2)}) ==
PoolsColumnsResult::total_too_high, "five columns of 100,000 exceed 400,000");
std::vector<std::array<uint8_t, 11>> seven;
for (int i = 0; i < 7; ++i) {
auto c = column(1);
c[1] = uint8_t(i % 3), c[2] = uint8_t(i / 3);
seven.push_back(c);
}
check(submit_pools_columns(g, 0, 10000, seven) == PoolsColumnsResult::too_many_columns, "at most six columns");
check(submit_pools_columns(g, 0, 90000, {seven[0], seven[1], seven[2], seven[3], seven[4]}) == PoolsColumnsResult::total_too_high,
"five columns of 90,000 exceed 400,000");
check(submit_pools_columns(g, 0, 5000, {column(1)}) == PoolsColumnsResult::stake_out_of_range, "stake at least 10,000");
check(submit_pools_columns(g, 0, 0, {}) == PoolsColumnsResult::ok && g.memory.u32(::bmh::layout::Coupon) == 0 &&
g.pools.at(0).extra.empty(), "a stake of 0 clears every column");
g.memory.set8(::bmh::layout::CareerSession_DispatchToto_RuntimeField, 9);
check(submit_pools_columns(g, 0, 50000, {column(1)}) == PoolsColumnsResult::invalid, "only with eleven matches");
}
// the cost: the stake per column, 10 % more for every column beyond the first
check(pools_cost(100000, 1) == 100000, "one column costs the stake");
check(pools_cost(100000, 4) == 430000, "four columns of 100,000 cost 430,000");
check(pools_cost(60000, 6) == 390000, "six columns of 60,000 cost 390,000");
if (failures) return 1;
std::puts("modern toto checks passed");
return 0;
}