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

+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