Skip to main content

Range

Struct Range 

Source
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

Source

pub fn new() -> Self

An empty range: every hand has weight 0.0.

Source

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.

Source

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.

Source

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.

Source

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 Clone for Range

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Range

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Range

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for Range

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

The hands in all_canonical_hands order, comma-separated, with a :weight suffix unless the weight is 1.

Source§

impl FromStr for Range

Source§

fn from_str(spec: &str) -> Result<Range, RangeError>

Source§

type Err = RangeError

The associated error which can be returned from parsing.
Source§

impl PartialEq for Range

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Range

Auto Trait Implementations§

§

impl Freeze 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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.