diff --git a/MODULES.md b/MODULES.md index fd79b985..eb11dd51 100644 --- a/MODULES.md +++ b/MODULES.md @@ -354,12 +354,15 @@ Die Bubble callt nie eine Hand, die Cash foldet. Öffnen und Shoven verschiebt d - Es gibt kein Squeeze und keine kalte 4-Bet. Die CFR-Abstraktion kennt nur zwei Verteidiger (die Blinds), Spieler dazwischen callen nur, und nach einer 3-Bet gibt es keinen Call. - Die Mehrweg-Equity ist eine grobe Näherung aus der schwächsten Paar-Equity, mit Fehlern bis 0,14. Mehrgegner-Tabellen gibt es nur für NLHE. -**Vertragsfeld für Turniere** (nur ein Vorschlag, VERTRAG.md bleibt unverändert): -- optionales `"tournament": {"payouts": [..], "stacks": [..], "heroIndex": n, "ante": a, "level": l, "playersLeft": n, "paidPlaces": n}` -- Die Stacks sind in Chips angegeben, für alle noch lebenden Spieler. +**Feld `tournament`** (Erweiterung wie `history`; VERTRAG.md bleibt unverändert; gelesen seit 2026-10-30 in `wire/decode_tournament.rs`): +- optionales `"tournament": {"payouts": [..], "stacks": [..], "heroIndex": n, "ante": a, "level": l}`. Feld und bezahlte Plätze sind die Längen von `stacks` und `payouts`. +- Die Stacks sind in Chips angegeben, für alle noch lebenden Spieler, bei Handbeginn. Die Hülle setzt uns an Index 0. +- Absent oder `null` heißt Cash und gibt bitgleich die alte Antwort. Falsche Typen ergeben "invalid request", eine nicht bepreisbare Lage ergibt ABSTAIN. +- Harville exakt bis 10 Spieler; darüber per Stichprobe (`sampled_equities`: Exponential-Rennen, 20 000 Läufe, fester Startwert, also deterministisch), bis 2 000 Spieler. Kosten je Anfrage: 18 Spieler 0,02 s, 95 Spieler 0,08 s, 2 000 Spieler 1,35 s. +- `tests/pipeline_tournament.rs` über `respond`: 10 BB, 4 am Tisch, 50/30/20: Cash 26, Bubble 17 Calls von 169. 18 Spieler, 14 bezahlt (echte Staffel), 8 BB: Cash 28, Bubble 23. - Der Bestand hat nur ein Turnier, ohne eigene Hände. -## Tests (`cargo test`, 848) +## Tests (`cargo test`, 859) - **Komponenten:** je Modul, darunter `read_*` (Texturen, gemachte Hände, Draws, Outs), `range_model_*`, `position_*` (alle Sitze, alle Tischgrößen, beide Zählweisen), `short_deck_*` - **Equity-Referenzen** (Quelle steht im Test): @@ -375,7 +378,7 @@ Die Bubble callt nie eine Hand, die Cash foldet. Öffnen und Shoven verschiebt d - `pipeline_bluff` mit Referenzszenarien: weniger Bluffs gegen die Calling Station, mehr gegen den Nit, breitere Steals gegen Nits, Bluff-Catch gegen den Maniac, Fold gegen den Nit - **CFR:** `cfr_kuhn`, `cfr_games`, `cfr_equity`, `cfr_hand_class`, `cfr_three_way`, `cfr_nash`, `generated_charts_*`, `preflop_cfr_advice`, `cfr_multi` (Mehrere Verteidiger: Identität mit den alten Spielen, Auszahlungssummen, Gegenprobe exakt und gesampelt, Reproduktion), `short_deck_charts` (Vollständigkeit, Randhände, direkte Showdowns), `preflop_multi_advice` (Rat nach Gegnerzahl: BTN Q8o öffnet gegen einen und foldet gegen zwei Verteidiger, EP KTo foldet am vollen Tisch; Rückfälle) - **PLO4:** `pipeline_plo4` (echte Anfrage wird beantwortet, 2/3/5 Karten werden abgelehnt, Omaha-Regel mit Gegenprobe zur Hold'em-Wertung, Doppel-Board-Begründung, Pot-Limit-Deckel; Boards der echten Hand 166344000006) und `preflop_plo4` (Tabelle reproduziert aus allen 270 725 Händen, Rangkorrelation mit gesampelter Equity > 0,85) -- **Größen und Turnier:** `engine_size_policy` (Commitment-Leiter, Bänder, Pot-Kontrolle, Stapelbänder), `icm_bubble` (Harville, Bubble enger als Cash, ohne Lage bitgleich) +- **Größen und Turnier:** `engine_size_policy` (Commitment-Leiter, Bänder, Pot-Kontrolle, Stapelbänder), `icm_bubble` (Harville, Bubble enger als Cash, ohne Lage bitgleich), `pipeline_tournament` (Feld `tournament` über `respond`, kaputte und unbepreisbare Lagen, Feld über 10 Spieler per Stichprobe) - **Vertrag:** `pipeline_contract` mit dem Beispiel aus VERTRAG.md - **Spielstärke:** `sim_strength` (Gegner, Tischmechanik und Chip-Bilanz bei 2, 3 und 6 Spielern, Determinismus, Gewinnrate heads-up gegen jeden Gegner; langer Lauf mit 6-max hinter `--ignored`) - **Zusatzfelder:** `pipeline_double_board` (benannte Referenzen: Set auf einem Board ≥ 0,80, Unterpaar auf dem anderen ≤ 0,45; ein Board verbessert, das andere nicht), `pipeline_run_twice`, `pipeline_extras_neutral` (ohne die Felder bitgleich zur Pipeline davor) diff --git a/src/icm/harville.rs b/src/icm/harville.rs index e130b94b..3845ca4b 100644 --- a/src/icm/harville.rs +++ b/src/icm/harville.rs @@ -1,7 +1,16 @@ //! Malmuth-Harville equities: expected prize of every player. -/// Largest field the exact expansion is run for. +use crate::rng::Rng; + +/// Largest field the exact expansion is run for; larger fields are sampled. pub const MAX_PLAYERS: usize = 10; +/// Largest field priced at all (sampling cost grows with the field). +pub const MAX_FIELD: usize = 2_000; +/// Finishing orders drawn for a sampled field. +pub const SAMPLES: u32 = 20_000; +/// Fixed, so the same field gives the same equities and two fields are compared on the same +/// draws (common random numbers keep the difference of two evaluations smooth). +const SAMPLE_SEED: u64 = 0x1C4_5EED; fn expand(stacks: &[f64], taken: &mut Vec, probability: f64, payouts: &[f64], out: &mut [f64]) { let place = taken.len(); @@ -26,9 +35,41 @@ fn expand(stacks: &[f64], taken: &mut Vec, probability: f64, payouts: &[f /// Expected prize per player. Places beyond the paid ones pay nothing; more payouts than /// players are cut to the field. The sum of the result is the sum of the paid prizes. +/// Exact up to `MAX_PLAYERS`, sampled above. pub fn equities(stacks: &[f64], payouts: &[f64]) -> Vec { + if stacks.len() > MAX_PLAYERS { + return sampled_equities(stacks, payouts); + } let mut out = vec![0.0; stacks.len()]; let paid = &payouts[..payouts.len().min(stacks.len())]; expand(stacks, &mut Vec::new(), 1.0, paid, &mut out); out } + + +/// Harville by sampling: the finishing order of an exponential race with rate `stack` has +/// exactly the Harville law (first is `stack / sum`, then again among the rest). Every stack +/// must be positive. Deterministic; the sum of the result is the sum of the paid prizes. +pub fn sampled_equities(stacks: &[f64], payouts: &[f64]) -> Vec { + let paid = &payouts[..payouts.len().min(stacks.len())]; + let by_time = |a: &(f64, usize), b: &(f64, usize)| a.0.total_cmp(&b.0); + let mut out = vec![0.0; stacks.len()]; + let mut times: Vec<(f64, usize)> = Vec::with_capacity(stacks.len()); + let mut rng = Rng::seeded(SAMPLE_SEED); + for _ in 0..SAMPLES { + times.clear(); + for (i, stack) in stacks.iter().enumerate() { + let (u, next) = rng.unit(); + rng = next; + times.push((-(1.0 - u).ln() / stack, i)); + } + if paid.len() < times.len() { + times.select_nth_unstable_by(paid.len(), by_time); + } + times[..paid.len()].sort_unstable_by(by_time); + for ((_, player), prize) in times.iter().zip(paid) { + out[*player] += prize; + } + } + out.iter().map(|x| x / f64::from(SAMPLES)).collect() +} diff --git a/src/icm/lage.rs b/src/icm/lage.rs index dcef7fbe..5aae146e 100644 --- a/src/icm/lage.rs +++ b/src/icm/lage.rs @@ -20,11 +20,11 @@ impl Turnierlage { } /// Every number finite, stacks positive, payouts non-negative with a positive sum, hero - /// inside the field, field small enough for the exact expansion. + /// inside the field, field no larger than `harville::MAX_FIELD`. pub fn is_usable(&self) -> bool { !self.payouts.is_empty() && self.hero < self.stacks.len() - && self.stacks.len() <= super::harville::MAX_PLAYERS + && self.stacks.len() <= super::harville::MAX_FIELD && self.stacks.iter().all(|s| s.is_finite() && *s > 0.0) && self.payouts.iter().all(|p| p.is_finite() && *p >= 0.0) && self.payouts.iter().sum::() > 0.0 diff --git a/src/icm/mod.rs b/src/icm/mod.rs index a1afa403..14643317 100644 --- a/src/icm/mod.rs +++ b/src/icm/mod.rs @@ -2,7 +2,8 @@ //! //! An APPROXIMATION, like the multiway equity. Assumptions: //! * Malmuth-Harville: a player finishes next with probability `stack / sum of stacks` -//! among those still unplaced (`harville`). Only the paid places are expanded. +//! among those still unplaced (`harville`). Only the paid places are expanded; fields +//! above `harville::MAX_PLAYERS` are sampled (deterministically) instead of expanded. //! * A call is a heads-up showdown for the whole `min(to_call, stacks)`; the pot is won or //! lost as one piece, the rest of the field does not act (`risk`). //! * The opponent is the last aggressor of the hand (largest live stack when unknown), @@ -11,10 +12,10 @@ //! moved by the pay structure; chip EV stays in force there. //! * Without a `Turnierlage` nothing changes: cash is bit-identical. //! * A `Turnierlage` that does not make sense (no stacks, no payouts, hero not in the field, -//! non-positive stacks, more than `harville::MAX_PLAYERS` players) is not guessed at: +//! non-positive stacks, more than `harville::MAX_FIELD` players) is not guessed at: //! the engine answers ABSTAIN. //! -//! Wire proposal for a later optional contract field (not in VERTRAG.md): +//! Optional request field (an extension, not in VERTRAG.md; read in `wire::decode_tournament`): //! `"tournament": {"payouts": [..], "stacks": [..], "heroIndex": n, "ante": a, "level": l}`. pub mod harville; diff --git a/src/wire/decode_extras.rs b/src/wire/decode_extras.rs index fab295b1..3932b6f1 100644 --- a/src/wire/decode_extras.rs +++ b/src/wire/decode_extras.rs @@ -1,6 +1,8 @@ use super::decode_board::board_double; +use super::decode_tournament::tournament; use crate::card::Card; use crate::fault::Fault; +use crate::icm::lage::Turnierlage; use crate::json::field::optional; use crate::json::scalar::flag; use crate::json::Value; @@ -13,6 +15,8 @@ pub struct Extras { pub board_double: Option>, /// `ritOffered`: the table offers to run it twice; absent or `null` means no. pub rit_offered: bool, + /// `tournament`: the situation to price the decision in money; absent means cash. + pub tournament: Option, } /// Read after the `Spot` checks, so faults of contract fields keep their precedence. @@ -21,5 +25,5 @@ pub fn extras(root: &Value) -> Result { Some(value) => flag(value, "ritOffered")?, None => false, }; - Ok(Extras { board_double: board_double(root)?, rit_offered }) + Ok(Extras { board_double: board_double(root)?, rit_offered, tournament: tournament(root)? }) } diff --git a/src/wire/decode_tournament.rs b/src/wire/decode_tournament.rs new file mode 100644 index 00000000..1af01d9c --- /dev/null +++ b/src/wire/decode_tournament.rs @@ -0,0 +1,47 @@ +use crate::fault::Fault; +use crate::icm::lage::Turnierlage; +use crate::json::field::{at, join, optional, required}; +use crate::json::member::{items_member, opt_number_member, opt_u64_member}; +use crate::json::scalar::{number, whole_u64}; +use crate::json::Value; + +const PATH: &str = "tournament"; + +fn numbers(object: &Value, key: &str) -> Result, Fault> { + let path = join(PATH, key); + items_member(object, PATH, key)?.iter().enumerate().map(|(i, v)| number(v, &at(&path, i))).collect() +} + +fn whole>(n: u64, key: &str) -> Result { + T::try_from(n).map_err(|_| Fault::Invalid { field: join(PATH, key), detail: format!("{n} is out of range") }) +} + +/// Extension field `tournament`: the tournament situation the answer is priced in (ICM-lite). +/// +/// ```text +/// "tournament": {"payouts": [27.76, 18.27, ...], "stacks": [8000, 12500, ...], +/// "heroIndex": 0, "ante": 250, "level": 18} +/// ``` +/// +/// - `payouts`: prize of place 1, 2, ... (paid places only), any money unit. +/// - `stacks`: chips of every player still in the tournament at hand start, hero included, +/// in the unit of the request's amounts. +/// - `heroIndex`: hero's index in `stacks`. +/// - `ante`, `level` (optional, default 0): informational. +/// +/// Absent or `null` means cash. Wrong types are a `Fault`; values that are well-formed but +/// cannot be priced (no payouts, hero outside the field, a stack of 0) make the engine +/// abstain (`Turnierlage::is_usable`). +pub fn tournament(root: &Value) -> Result, Fault> { + let Some(object) = optional(root, "", PATH)? else { + return Ok(None); + }; + let hero = whole_u64(required(object, PATH, "heroIndex")?, &join(PATH, "heroIndex"))?; + Ok(Some(Turnierlage { + payouts: numbers(object, "payouts")?, + stacks: numbers(object, "stacks")?, + hero: whole(hero, "heroIndex")?, + ante: opt_number_member(object, PATH, "ante")?.unwrap_or(0.0), + level: opt_u64_member(object, PATH, "level")?.map(|n| whole(n, "level")).transpose()?.unwrap_or(0), + })) +} diff --git a/src/wire/mod.rs b/src/wire/mod.rs index 7bb43907..98674d02 100644 --- a/src/wire/mod.rs +++ b/src/wire/mod.rs @@ -7,6 +7,7 @@ pub mod decode_extras; pub mod decode_history; pub mod decode_legal; pub mod decode_name; +pub mod decode_tournament; pub mod decode_villain; pub mod encode; pub mod respond; diff --git a/src/wire/respond.rs b/src/wire/respond.rs index 97cb537d..a6cd17e7 100644 --- a/src/wire/respond.rs +++ b/src/wire/respond.rs @@ -1,7 +1,7 @@ use super::decode::decode; use super::decode_extras::extras; use super::encode::{encode, encode_value}; -use crate::engine::decide::decide; +use crate::engine::decide::{decide, decide_with}; use crate::engine::double_board::decide_double; use crate::engine::run_twice::{run_twice, RunTwice}; use crate::fault::Fault; @@ -16,7 +16,10 @@ fn pipeline(line: &str) -> Result<(Decision, Option<(RunTwice, String)>), Fault> let extras = extras(&value)?; let decision = match &extras.board_double { Some(second) => decide_double(&spot, second), - None => enforce(&spot, decide(&spot)), + None => match &extras.tournament { + Some(lage) => decide_with(&spot, Some(lage)), + None => enforce(&spot, decide(&spot)), + }, }; let rit = extras.rit_offered.then(|| run_twice(&spot, &decision)); Ok((decision, rit)) diff --git a/tests/pipeline_tournament.rs b/tests/pipeline_tournament.rs new file mode 100644 index 00000000..16fcfe06 --- /dev/null +++ b/tests/pipeline_tournament.rs @@ -0,0 +1,182 @@ +//! Optional request field `tournament` (not in VERTRAG.md, proposed in `icm`): +//! `{"payouts": [..], "stacks": [..], "heroIndex": n, "ante": a, "level": l}`. +//! With it the answer is priced in money (ICM-lite), without it cash is unchanged. + +mod support; + +use pokerfreak::icm::harville::{equities, MAX_PLAYERS}; +use pokerfreak::wire::respond::respond; +use support::field; + +const RANKS: &str = "AKQJT98765432"; + +fn card(rank: char, suit: char) -> String { + let rank = match rank { + 'A' => "ACE", 'K' => "KING", 'Q' => "QUEEN", 'J' => "JACK", 'T' => "TEN", '9' => "NINE", + '8' => "EIGHT", '7' => "SEVEN", '6' => "SIX", '5' => "FIVE", '4' => "FOUR", '3' => "THREE", + _ => "TWO", + }; + let suit = if suit == 's' { "SPADES" } else { "HEARTS" }; + format!(r#"{{"rank":"{rank}","suit":"{suit}"}}"#) +} + +/// The 169 starting hands, one combination each (spades first card, suited or hearts second). +fn holes() -> Vec { + let r: Vec = RANKS.chars().collect(); + let mut out = Vec::new(); + for (i, a) in r.iter().enumerate() { + for b in &r[i..] { + if a == b { + out.push(format!("[{},{}]", card(*a, 's'), card(*b, 'h'))); + } else { + out.push(format!("[{},{}]", card(*a, 's'), card(*b, 's'))); + out.push(format!("[{},{}]", card(*a, 's'), card(*b, 'h'))); + } + } + } + out +} + +/// Hero in the big blind (seat 1) faces the small blind's (seat 2) jam of `depth` bb; `extra` +/// is appended to the request object as is. +fn facing_jam(hole: &str, depth: f64, extra: &str) -> String { + format!( + r#"{{"variant":"NLHE","bigBlind":1.0,"seats":2,"heroSeat":1,"buttonSeat":2,"heroCards":{hole},"board":{{"FLOP":null,"TURN":null,"RIVER":null}},"street":"PREFLOP","pot":{pot},"toCall":{call},"heroStack":{call},"legalActions":["FOLD","CALL"],"villains":[{{"seat":2,"stack":{depth},"folded":false}}],"seed":7,"history":[{{"street":"PREFLOP","seat":2,"action":"POST_SB","amount":0.5}},{{"street":"PREFLOP","seat":1,"action":"POST_BB","amount":1.0}},{{"street":"PREFLOP","seat":2,"action":"ALL_IN","amount":{depth}}}]{extra}}}"#, + pot = depth + 1.0, + call = depth - 1.0, + ) +} + +fn action(response: &str) -> &str { + field(response, "action").expect("action").trim_matches('"') +} + +/// How many of the 169 hands call the jam, with `extra` added to each request. +fn calls(depth: f64, extra: &str) -> usize { + holes().iter().filter(|h| action(&respond(&facing_jam(h, depth, extra))) == "CALL").count() +} + +fn tournament(payouts: &[f64], stacks: &[f64]) -> String { + let list = |xs: &[f64]| xs.iter().map(|x| format!("{x:?}")).collect::>().join(","); + format!( + r#","tournament":{{"payouts":[{}],"stacks":[{}],"heroIndex":0,"ante":0.0,"level":3}}"#, + list(payouts), + list(stacks) + ) +} + +#[test] +fn a_bubble_on_the_wire_calls_fewer_jams_than_cash() { + let depth = 10.0; + let bubble = tournament(&[50.0, 30.0, 20.0], &[depth, depth, 2.0 * depth, 2.0 * depth]); + let (cash, money) = (calls(depth, ""), calls(depth, &bubble)); + println!("{depth} bb ueber respond: Cash {cash} von 169, Bubble {money}"); + assert!(money < cash, "bubble {money} >= cash {cash}"); +} + +#[test] +fn a_null_tournament_is_cash() { + for hole in holes().iter().take(12) { + assert_eq!(respond(&facing_jam(hole, 12.0, r#","tournament":null"#)), respond(&facing_jam(hole, 12.0, ""))); + } +} + +#[test] +fn winner_takes_all_is_cash_on_the_wire() { + // Money is linear in chips when one place is paid: nothing may tighten. + let depth = 10.0; + let wta = tournament(&[100.0], &[depth, depth, 2.0 * depth, 2.0 * depth]); + assert_eq!(calls(depth, &wta), calls(depth, "")); +} + +#[test] +fn a_malformed_tournament_is_an_invalid_request() { + let hole = &holes()[0]; + for bad in [ + r#","tournament":{"payouts":[50,30,20],"stacks":[10,10,20],"heroIndex":"x","ante":0,"level":1}"#, + r#","tournament":{"stacks":[10,10,20],"heroIndex":0,"ante":0,"level":1}"#, + r#","tournament":{"payouts":[50,30,20],"stacks":"many","heroIndex":0,"ante":0,"level":1}"#, + r#","tournament":[1,2,3]"#, + ] { + let answer = respond(&facing_jam(hole, 10.0, bad)); + assert_eq!(action(&answer), "ABSTAIN", "{bad}: {answer}"); + assert!(answer.contains("invalid request"), "{bad}: {answer}"); + } +} + +#[test] +fn a_tournament_that_cannot_be_priced_abstains_instead_of_guessing() { + let hole = &holes()[0]; + for bad in [ + r#","tournament":{"payouts":[],"stacks":[10,10,20],"heroIndex":0,"ante":0,"level":1}"#, + r#","tournament":{"payouts":[50,30,20],"stacks":[10,10,20],"heroIndex":7,"ante":0,"level":1}"#, + r#","tournament":{"payouts":[50,30,20],"stacks":[10,0,20],"heroIndex":0,"ante":0,"level":1}"#, + r#","tournament":{"payouts":[50,30,20],"stacks":[10,10,20],"heroIndex":3,"ante":0,"level":1}"#, + r#","tournament":{"payouts":[-5,30,20],"stacks":[10,10,20],"heroIndex":0,"ante":0,"level":1}"#, + r#","tournament":{"payouts":[0,0,0],"stacks":[10,10,20],"heroIndex":0,"ante":0,"level":1}"#, + ] { + assert_eq!(action(&respond(&facing_jam(hole, 10.0, bad))), "ABSTAIN", "{bad}"); + } +} + +/// The real field of the stock tournament on its bubble: 18 left, 14 paid (shape of +/// `Comm_Tournament_117632`, payouts in percent of the pool). +const PAID_14: [f64; 14] = + [28.38, 18.68, 12.49, 8.56, 6.09, 4.55, 3.57, 2.95, 2.95, 2.53, 2.53, 2.24, 2.24, 2.24]; + +#[test] +fn a_field_larger_than_the_exact_expansion_is_still_priced() { + let depth = 8.0; + let mut stacks = vec![depth, depth]; + stacks.extend([20.0, 25.0, 30.0, 12.0, 40.0, 18.0, 22.0, 35.0, 15.0, 28.0, 33.0, 26.0, 19.0, 24.0, 31.0, 21.0]); + assert!(stacks.len() > MAX_PLAYERS); + let line = tournament(&PAID_14, &stacks); + let (cash, money) = (calls(depth, ""), calls(depth, &line)); + println!("18 Spieler, 14 bezahlt, {depth} bb: Cash {cash} von 169, Bubble {money}"); + assert!(money < cash, "bubble {money} >= cash {cash}"); + assert_eq!(calls(depth, &line), money, "same request, same answer"); +} + +#[test] +fn sampled_equities_pay_out_the_pool_and_follow_the_stacks() { + let stacks: Vec = (1..=16).map(|i| i as f64 * 5.0).collect(); + let e = equities(&stacks, &PAID_14); + let pool: f64 = PAID_14.iter().sum(); + assert!((e.iter().sum::() - pool).abs() < 1e-6, "{e:?}"); + assert!(e.first() < e.last(), "{e:?}"); + assert_eq!(e, equities(&stacks, &PAID_14), "deterministic"); +} + +#[test] +fn sampled_equities_agree_with_the_exact_expansion() { + // Where both can run (10 players): the sample stays within 0.6 % of the pool of the exact value. + let stacks = [3.0, 5.0, 8.0, 9.0, 11.0, 12.0, 14.0, 17.0, 20.0, 25.0]; + let payouts = [40.0, 25.0, 15.0, 10.0, 6.0, 4.0]; + let exact = equities(&stacks, &payouts); + let sampled = pokerfreak::icm::harville::sampled_equities(&stacks, &payouts); + for (x, s) in exact.iter().zip(&sampled) { + assert!((x - s).abs() < 0.6, "exact {exact:?} sampled {sampled:?}"); + } +} + +#[test] +fn a_field_beyond_the_largest_priced_one_abstains() { + let stacks = vec![10.0; pokerfreak::icm::harville::MAX_FIELD + 1]; + let answer = respond(&facing_jam(&holes()[0], 10.0, &tournament(&PAID_14, &stacks))); + assert_eq!(action(&answer), "ABSTAIN", "{answer}"); +} + +#[test] +fn up_to_the_exact_limit_the_expansion_is_exact() { + // Equal stacks share the pool exactly; a sample would miss by its noise. + let e = equities(&[7.0; MAX_PLAYERS], &[50.0, 30.0, 20.0]); + assert!(e.iter().all(|x| (x - 10.0).abs() < 1e-9), "{e:?}"); +} + +#[test] +fn a_sampled_field_may_pay_every_place() { + let stacks: Vec = (1..=12).map(f64::from).collect(); + let payouts: Vec = (1..=12).rev().map(f64::from).collect(); + let e = equities(&stacks, &payouts); + assert!((e.iter().sum::() - payouts.iter().sum::()).abs() < 1e-6, "{e:?}"); +}