use super::passive::{cheapest_continue, give_up}; use crate::game::{ActionKind, Choice, Decision, Spot}; use crate::preflop::commit_guard::{raise_commitment, RaiseVerdict}; use crate::preflop::plan::{ChartAction, PreflopPlan}; use crate::sizing::{all_in::all_in, preflop::raise_size}; /// Below this chart certainty, a plan that would put chips in is not trusted. pub const MIN_CERTAINTY: f64 = 0.15; fn aggressive(spot: &Spot, size: Option) -> Option { spot.is_legal(ActionKind::Raise) .then_some(size) .flatten() .map(|to| Choice::Raise { to }) .or_else(|| cheapest_continue(spot)) .or_else(|| give_up(spot)) } fn wanted(spot: &Spot, action: ChartAction) -> Option { match action { ChartAction::Jam => aggressive(spot, all_in(spot)), ChartAction::Raise => aggressive(spot, raise_size(spot)), ChartAction::Call => cheapest_continue(spot).or_else(|| give_up(spot)), ChartAction::Fold => give_up(spot), } } /// Maps a chart action through sizing and legality. /// Jam is all-in, Raise the standard preflop size (both fall back to calling when a /// raise is impossible), Call calls or checks when free, Fold folds or checks when /// free. A certainty under [`MIN_CERTAINTY`] turns chip-committing plans into ABSTAIN. /// A charted `Raise` that sizing capped to (near) all-in is a commitment: it must clear the same /// price cut-off as a jam, or it steps down to a call (price paid) / fold (commit_guard). A `Raise` /// well below all-in, and every non-Raise plan, pass through unchanged (the Jam already passed the /// jam ceiling in `preflop::advise`). fn commit_begrenzt(spot: &Spot, plan: &PreflopPlan, choice: Option) -> Option { match choice { Some(Choice::Raise { to }) if plan.action == ChartAction::Raise => { let jam = all_in(spot).unwrap_or(to); let out = match raise_commitment(plan.percentile, to, jam, spot.to_call, spot.pot) { RaiseVerdict::Keep => Some(Choice::Raise { to }), RaiseVerdict::Downgrade => cheapest_continue(spot).or_else(|| give_up(spot)), RaiseVerdict::Fold => give_up(spot), }; match out { Some(Choice::Raise { .. }) => { if crate::preflop::vorflop_pop::ziel(spot).is_some() { super::vermerk::notiere(format!("VORFLOP_POP: Groesse nach NL2-Population, raise to {to:.2}")); } } Some(c) => super::vermerk::notiere(format!( "Commit-Riegel: raise to {to:.2} bindet den Stack -> {}", super::vermerk::aktion(&c) )), None => {} } out } other => other, } } pub fn from_plan(spot: &Spot, plan: &PreflopPlan) -> Decision { match commit_begrenzt(spot, plan, wanted(spot, plan.action)) { None => Decision::abstain(format!("{}: no legal way to follow the chart", plan.reason)), Some(choice @ (Choice::Call | Choice::Raise { .. })) if plan.certainty < MIN_CERTAINTY => { Decision::abstain(format!( "{}: certainty {:.2} too low to {}", plan.reason, plan.certainty, choice.name().to_lowercase() )) } Some(choice) => Decision::new( choice, plan.certainty, format!("{} -> {}", plan.reason, choice.name().to_lowercase()), ), } }