Struct poker::Evaluator[][src]

pub struct Evaluator(_);

This structure does all the heavy lifting of evaluating poker hands.

Example

use poker::{cards, Evaluator, EvalClass, Rank};

let eval = Evaluator::new();

let hand = cards!(
    Four of Clubs,
    Four of Spades,
    Jack of Diamonds,
    Jack of Clubs,
    Jack of Hearts,
);

let result = eval.evaluate(&hand).expect("couldn't evaluate poker hand");
assert!(matches!(
    result.class(),
    EvalClass::FullHouse { pair: Rank::Four, trips: Rank::Jack }
));
assert_eq!(
    result.to_string(),
    "Full house, jacks over fours"
);

Implementations

impl Evaluator[src]

pub fn new() -> Self[src]

Create a new Evaluator. Try to call this method only once and share the instance as much as possible.

pub fn evaluate<C: AsRef<[Card]>>(&self, cards: C) -> Result<Eval, EvalError>[src]

Evaluate a hand. This function takes anything that implements AsRef<[Card]>, so owned or borrowed slices of Vecs work fine here!

If you need to evaluate a hand in the context of a board (for example, in Texas Holdem), you just need to combine both slices (such as with box_cards!) and pass it to this method. See the exaples for more.

Errors

This function will fail if the total number of cards is less than five, or if not all the cards passed in are unique. See EvalError for more.

Performance

Optimal performance is achieved with a set of 5, 6, or 7 cards. Hands are evaulated using combinatorics to find the best 5-card combination, so the more cards you pass to this method, the longer it will take to evaluate.

Example

use poker::{cards, Card, Evaluator};

const ROYAL_FLUSH: [Card; 5] = cards!(
    Ten of Clubs,
    Jack of Clubs,
    Queen of Clubs,
    King of Clubs,
    Ace of Clubs,
);
let mut results = Vec::new();
let eval = Evaluator::new();
// Pass a slice
results.push(eval.evaluate(&ROYAL_FLUSH).expect("couldn't evaluate hand"));
// Pass an owned vector
results.push(
    eval.evaluate(ROYAL_FLUSH.to_vec())
        .expect("couldn't evaluate hand"),
);
assert!(results.into_iter().all(|result| result.is_royal_flush()));

With a hand and a board:

use poker::{box_cards, cards, Card, EvalClass, Evaluator};

let eval = Evaluator::new();
let board: Vec<Card> = cards!("3c 5c As Jc Qh")
    .try_collect()
    .expect("couldn't parse cards");
let hand: Vec<Card> = cards!("Tc Ac").try_collect().expect("couldn't parse cards");

let result = eval
    .evaluate(box_cards!(board, hand))
    .expect("couldn't evaluate hand");
assert!(matches!(result.class(), EvalClass::Flush { .. }));

Trait Implementations

impl Clone for Evaluator[src]

impl Debug for Evaluator[src]

impl Default for Evaluator[src]

impl Eq for Evaluator[src]

impl PartialEq<Evaluator> for Evaluator[src]

impl StructuralEq for Evaluator[src]

impl StructuralPartialEq for Evaluator[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,