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 Vec
s 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
impl RefUnwindSafe for Evaluator
impl Send for Evaluator
impl Sync for Evaluator
impl Unpin for Evaluator
impl UnwindSafe for Evaluator
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,