Files
pokerfreak/src/wire/respond.rs
T
mmintelandClaude Opus 5.5 643fed5f0a Tournament field on the wire: ICM-lite priced from the request, sampled above 10 players
The shell can now send the optional `tournament` field (payouts, stacks,
heroIndex, ante, level). The core read none of it, and the exact Harville
expansion could not price the real bubble (15-18 players). Fields above
MAX_PLAYERS are now priced by an exponential race sample with a fixed seed,
so the same request always gets the same answer; beyond MAX_FIELD the core
abstains. Malformed fields are an invalid request, unpriceable ones abstain.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-30 09:49:49 +01:00

44 lines
1.7 KiB
Rust

use super::decode::decode;
use super::decode_extras::extras;
use super::encode::{encode, encode_value};
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;
use crate::game::{Decision, Spot};
use crate::guard::enforce::enforce;
use crate::guard::validate::check;
use crate::json::{parse, render, Value};
fn pipeline(line: &str) -> Result<(Decision, Option<(RunTwice, String)>), Fault> {
let value = parse(line)?;
let spot: Spot = check(decode(&value)?)?;
let extras = extras(&value)?;
let decision = match &extras.board_double {
Some(second) => decide_double(&spot, second),
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))
}
/// One request line in, one response line out (without trailing newline). Never panics.
/// With `ritOffered` the answer carries `rit` and `ritReason` after the contract keys.
pub fn respond(line: &str) -> String {
match pipeline(line) {
Ok((decision, None)) => encode(&decision),
Ok((decision, Some((answer, reason)))) => {
let Value::Object(mut felder) = encode_value(&decision) else {
return encode(&decision);
};
felder.push(("rit".to_string(), Value::String(answer.name().to_string())));
felder.push(("ritReason".to_string(), Value::String(reason)));
render(&Value::Object(felder))
}
Err(fault) => encode(&Decision::abstain(format!("invalid request: {fault}"))),
}
}