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:
1 parent
4639fe5a91
commit
0aa0ed68ca
14 files changed
+357
-10
No files matched your search
@@ -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",
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
Reference in new issue
Block a user