pub struct Range { /* private fields */ }Expand description
A weighted preflop range, keyed by canonical hand notation.
Parse one from text with str::parse (or Range::parse); its
Display form parses back to the same range.
use native_solver::{Card, CardSet, Range};
let range: Range = "AA, AKs, QJo:0.5".parse()?;
assert_eq!(range.weight("AKs"), 1.0);
assert_eq!(range.weight("JQo"), 0.5); // any rank order and case
assert_eq!(range.to_string(), "AA,AKs,QJo:0.5");
// Expand into combos, dropping those that use a dead card.
let dead = CardSet::from_cards(&["As".parse::<Card>()?]);
assert_eq!(range.combos(dead).len(), 3 + 3 + 12);Implementations§
Source§impl Range
impl Range
Sourcepub fn parse(spec: &str) -> Result<Self, RangeError>
pub fn parse(spec: &str) -> Result<Self, RangeError>
Parses a comma-separated range, e.g. "AA,AKs,AQo:0.5,72o".
A hand without a :weight suffix gets weight 1.0. Same as
spec.parse::<Range>().
§Errors
Returns a RangeError for a hand that is not canonical notation
(two ranks, plus s or o when they differ) or a weight that is not
a number in 0.0..=1.0.
Sourcepub fn set_weight(&mut self, hand: &str, weight: f64) -> Result<(), RangeError>
pub fn set_weight(&mut self, hand: &str, weight: f64) -> Result<(), RangeError>
Sets the weight of a hand in canonical notation.
The hand is written like “AA”, “AKs”, or “72o”, in any rank order and
case. A weight of 0.0 removes the hand.
§Errors
Returns a RangeError if hand is not canonical notation or
weight is not in 0.0..=1.0.
Sourcepub fn weight(&self, hand: &str) -> f64
pub fn weight(&self, hand: &str) -> f64
The weight of a hand in canonical notation.
Returns 0.0 if the hand is not in the range or the notation is
invalid.
Sourcepub fn combos(&self, dead: CardSet) -> Vec<Combo>
pub fn combos(&self, dead: CardSet) -> Vec<Combo>
Expands the range into combos, dropping any that use a card in dead.
Pass the board as dead. Removing other cards too breaks suit
symmetry, which Trainer::new requires with
suit isomorphism or flop and turn buckets.
Combos are ordered by their lower card, then their higher card, so the order, and every solver result that sums over it, is the same on every run however the range was built.
Trait Implementations§
Source§impl FromStr for Range
impl FromStr for Range
Source§fn from_str(spec: &str) -> Result<Range, RangeError>
fn from_str(spec: &str) -> Result<Range, RangeError>
See Range::parse.
Source§type Err = RangeError
type Err = RangeError
impl StructuralPartialEq for Range
Auto Trait Implementations§
impl Forget for Range
impl Freeze for Range
impl Move for Range
impl RefUnwindSafe for Range
impl Send for Range
impl Sync for Range
impl Unpin for Range
impl UnsafeUnpin for Range
impl UnwindSafe for Range
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more