use crate::{
card::{Card, Cards},
constants::{FLUSHES, HASH_ADJUST, HASH_VALUES, PERM7, UNIQUE5},
- Algorithm, Rules,
+ Algorithm, MyError, Rules,
};
#[derive(Debug)]
self
}
- pub fn eval(&self) -> HashMap<usize, u16> {
+ pub fn eval(&mut self) -> Result<HashMap<usize, u16>, MyError> {
+ let hands: Vec<Cards> = self
+ .hands
+ .clone()
+ .into_iter()
+ .map(|h| Cards(h.as_ref().0.clone()))
+ .collect();
+ if hands.is_empty() {
+ return Err(MyError::NoHands);
+ }
+ let table = &self.table.as_ref().0.clone();
+ if hands.len() == 5 && matches!(self.rules, Rules::Holdem) {
+ println!("Warning: card number in hands does not match the given Poker rules");
+ println!("Switching rules to classic");
+ self.rules = Rules::Classic;
+ }
+ let hand = &hands.get(0).unwrap().0;
+ if hand.len() == 2 && matches!(self.rules, Rules::Classic) {
+ println!("Warning: card number in hands does not match the given Poker rules");
+ println!("Switching rules to holdem");
+ self.rules = Rules::Holdem;
+ }
+ if matches!(self.rules, Rules::Holdem) && table.len() == 0 {
+ return Err(MyError::NoTable);
+ }
let result = match self.rules {
Rules::Classic => self
.hands
.enumerate()
.collect(),
};
- result
+ Ok(result)
}
pub fn eval_5hand(&self, cards: &[Card; 5]) -> u16 {