55 lines
1.8 KiB
Rust
55 lines
1.8 KiB
Rust
use crate::game::{ActionKind, Choice, Spot};
|
|
use crate::sizing::fit::fit;
|
|
use crate::variant::ActionShape;
|
|
|
|
/// What became of a choice: kept as is, changed (with a note), or unsalvageable.
|
|
#[derive(Clone, Debug, PartialEq)]
|
|
pub enum Repair {
|
|
Kept(Choice),
|
|
Changed(Choice, String),
|
|
Refused(String),
|
|
}
|
|
|
|
fn raise(spot: &Spot, to: f64) -> Repair {
|
|
if spot.hero_stack <= 0.0 {
|
|
return Repair::Refused("RAISE impossible: no chips behind".to_string());
|
|
}
|
|
match fit(spot, to) {
|
|
Some(size) if size == to => Repair::Kept(Choice::Raise { to }),
|
|
Some(size) => Repair::Changed(
|
|
Choice::Raise { to: size },
|
|
format!("raise size {to} adjusted to {size}"),
|
|
),
|
|
None => Repair::Refused(format!("RAISE size {to} cannot be made legal")),
|
|
}
|
|
}
|
|
|
|
fn binary_call(spot: &Spot) -> Repair {
|
|
if spot.to_call >= spot.hero_stack {
|
|
Repair::Kept(Choice::Call)
|
|
} else {
|
|
Repair::Refused("CALL is neither give-up nor all-in in a binary game".to_string())
|
|
}
|
|
}
|
|
|
|
/// Brings a choice into legal shape for `spot`, or refuses it.
|
|
pub fn repair(spot: &Spot, choice: Choice) -> Repair {
|
|
let check_free = spot.is_legal(ActionKind::Check);
|
|
match choice {
|
|
Choice::Abstain => Repair::Kept(Choice::Abstain),
|
|
Choice::Fold if check_free => {
|
|
Repair::Changed(Choice::Check, "FOLD replaced by free CHECK".to_string())
|
|
}
|
|
other => match other.kind() {
|
|
Some(kind) if !spot.is_legal(kind) => {
|
|
Repair::Refused(format!("{} is not in legalActions", kind.name()))
|
|
}
|
|
_ => match other {
|
|
Choice::Raise { to } => raise(spot, to),
|
|
Choice::Call if spot.rules().shape == ActionShape::Binary => binary_call(spot),
|
|
kept => Repair::Kept(kept),
|
|
},
|
|
},
|
|
}
|
|
}
|