Die Welt soll nichts verraten. Woerter, die ein Gegenueber implizieren (echt vs. unecht, live, Mensch), sind aus Prosa, Kommentaren und Docstrings raus; Namen (mensch_ruhe_s, echte_chops) und der Altwert "echt" im Spielplan bleiben. Nur Kommentare und Docstrings angefasst, damit keine Einrueckung faellt.
121 lines
4.2 KiB
Rust
121 lines
4.2 KiB
Rust
use super::preflop_role::PreflopRole;
|
|
use crate::game::{ActionRecord, SeenAction, Street};
|
|
|
|
/// The villain last voluntary preflop action and how many raises came before it.
|
|
#[derive(Clone, Copy)]
|
|
enum Last {
|
|
Aggression { raises_before: usize, all_in: bool },
|
|
Call { raises_before: usize },
|
|
Check,
|
|
}
|
|
|
|
#[derive(Clone, Copy, Default)]
|
|
struct Facts {
|
|
raises: usize,
|
|
small_blind: bool,
|
|
big_blind: bool,
|
|
last: Option<Last>,
|
|
}
|
|
|
|
fn own_action(facts: Facts, action: SeenAction) -> Facts {
|
|
match action {
|
|
SeenAction::PostSmallBlind => Facts {
|
|
small_blind: true,
|
|
..facts
|
|
},
|
|
SeenAction::PostBigBlind => Facts {
|
|
big_blind: true,
|
|
..facts
|
|
},
|
|
SeenAction::PostAnte | SeenAction::Fold => facts,
|
|
SeenAction::Check => Facts {
|
|
last: Some(Last::Check),
|
|
..facts
|
|
},
|
|
SeenAction::Call => Facts {
|
|
last: Some(Last::Call {
|
|
raises_before: facts.raises,
|
|
}),
|
|
..facts
|
|
},
|
|
SeenAction::Bet | SeenAction::Raise | SeenAction::AllIn => Facts {
|
|
last: Some(Last::Aggression {
|
|
raises_before: facts.raises,
|
|
all_in: action == SeenAction::AllIn,
|
|
}),
|
|
..facts
|
|
},
|
|
}
|
|
}
|
|
|
|
fn step(facts: Facts, record: &ActionRecord, seat: u8) -> Facts {
|
|
let updated = if record.seat == seat {
|
|
own_action(facts, record.action)
|
|
} else {
|
|
facts
|
|
};
|
|
Facts {
|
|
raises: updated.raises + usize::from(record.action.is_aggressive()),
|
|
..updated
|
|
}
|
|
}
|
|
|
|
fn by_raises_faced(raises: usize) -> PreflopRole {
|
|
match raises {
|
|
0 => PreflopRole::Limper,
|
|
1 => PreflopRole::CallsRaise,
|
|
_ => PreflopRole::CallsThreeBet,
|
|
}
|
|
}
|
|
|
|
/// Role of `seat` from the preflop records, in order (other seats only count as context).
|
|
/// `None` if there is nothing to go on.
|
|
///
|
|
/// - The last call-or-aggression decides. Aggression after no raise: `Opener`, after one:
|
|
/// `ThreeBettor`, after more: `FourBettorPlus`; an all-in is a jam instead.
|
|
/// A call after no raise is a limp (`SmallBlindCompleter` for the small blind, a check
|
|
/// for the big blind), after one raise `CallsRaise`, after more `CallsThreeBet`.
|
|
/// So an opener who then calls a 3-bet is `CallsThreeBet`.
|
|
/// - A big blind whose last act is a check is `BigBlindCheck`.
|
|
/// - A blind with no later action is assumed to have stayed in: no raise at all gives
|
|
/// `BigBlindCheck` / `SmallBlindCompleter`, one raise `CallsRaise`, more `CallsThreeBet`.
|
|
/// - Every all-in counts as a raise for the raises-faced count, even a short call.
|
|
/// - Folds and antes are ignored.
|
|
pub fn role_of(history: &[ActionRecord], seat: u8) -> Option<PreflopRole> {
|
|
let facts = history
|
|
.iter()
|
|
.filter(|r| r.street == Street::Preflop)
|
|
.fold(Facts::default(), |facts, record| step(facts, record, seat));
|
|
match facts.last {
|
|
Some(Last::Aggression {
|
|
raises_before,
|
|
all_in: true,
|
|
}) => Some(if raises_before == 0 {
|
|
PreflopRole::JamOpen
|
|
} else {
|
|
PreflopRole::JamOverRaise
|
|
}),
|
|
Some(Last::Aggression {
|
|
raises_before,
|
|
all_in: false,
|
|
}) => Some(match raises_before {
|
|
0 => PreflopRole::Opener,
|
|
1 => PreflopRole::ThreeBettor,
|
|
_ => PreflopRole::FourBettorPlus,
|
|
}),
|
|
Some(Last::Call { raises_before: 0 }) if facts.big_blind => {
|
|
Some(PreflopRole::BigBlindCheck)
|
|
}
|
|
Some(Last::Call { raises_before: 0 }) if facts.small_blind => {
|
|
Some(PreflopRole::SmallBlindCompleter)
|
|
}
|
|
Some(Last::Call { raises_before }) => Some(by_raises_faced(raises_before)),
|
|
Some(Last::Check) if facts.big_blind => Some(PreflopRole::BigBlindCheck),
|
|
Some(Last::Check) => None,
|
|
None if facts.big_blind && facts.raises == 0 => Some(PreflopRole::BigBlindCheck),
|
|
None if facts.small_blind && facts.raises == 0 => Some(PreflopRole::SmallBlindCompleter),
|
|
None if facts.big_blind || facts.small_blind => Some(by_raises_faced(facts.raises)),
|
|
None => None,
|
|
}
|
|
}
|