Files
pokerfreak/src/engine/from_plan.rs
T
2026-10-28 11:51:24 +01:00

49 lines
1.9 KiB
Rust

use super::passive::{cheapest_continue, give_up};
use crate::game::{ActionKind, Choice, Decision, Spot};
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<f64>) -> Option<Choice> {
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<Choice> {
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.
pub fn from_plan(spot: &Spot, plan: &PreflopPlan) -> Decision {
match 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()),
),
}
}