use serde::{Deserialize, Serialize};
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
-#[derive(Debug, Default, Clone, Hash, PartialEq)]
+#[derive(Debug, Default, Clone, PartialEq)]
pub struct Cards(Vec<Card>);
impl Cards {
) -> Result<Vec<Cards>, ParseCardError> {
(0..player_nb)
.into_iter()
- .map(|_| Ok(self.deal_with_rules(rules)?))
+ .map(|_| self.deal_with_rules(rules))
.collect()
}
}
#[cfg(feature = "rand")]
- pub fn shuffle<'a>(&'a mut self) -> &'a mut Deck {
+ pub fn shuffle(&mut self) -> &mut Self {
use rand::prelude::*;
let mut rng = thread_rng();
self.0 .0.shuffle(&mut rng);
}
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
-#[derive(Debug, Clone, Copy, Hash)]
+#[derive(Debug, Clone, Copy)]
#[repr(transparent)]
pub struct Card(u32);
self
}
- pub fn hands<'a>(&'a mut self, hands: &Vec<Cards>) -> &'a mut Evaluator {
+ pub fn hands<'a>(&'a mut self, hands: &[Cards]) -> &'a mut Evaluator {
self.hands.extend_from_slice(hands);
self
}
Ok(())
}
- parse_args(&self)?;
+ parse_args(self)?;
let hands: Vec<Vec<u32>> = self.hands.iter().map(|h| h.clone().into()).collect();
let table: Vec<u32> = self.table.clone().into();
pub fn eval_7hand(cards: &[u32]) -> Result<u16, EvaluateCardError> {
let mut subhand: [u32; 5] = [0; 5];
let mut best = 9999;
-
- for i in 0..21 {
- for j in 0..5 {
- subhand[j] = cards[..][PERM7[i][j] as usize];
+ for perm in &PERM7 {
+ for (i, card) in subhand.iter_mut().enumerate() {
+ *card = cards[..][perm[i] as usize];
}
let q = Evaluator::eval_5hand(&subhand)?;
if q < best {
}
pub fn report(result: &HashMap<usize, u16>) -> (&usize, &u16) {
- for (p, s) in result.into_iter() {
+ for (p, s) in result.iter() {
println!("Player {}: Score {}", p, s);
println!("Hand value: {}", VALUE_STR[hand_rank(*s) as usize]);
println!();
}
- let winner = result.iter().min_by(|a, b| a.1.cmp(&b.1)).unwrap().clone();
+ let winner = result.iter().min_by(|a, b| a.1.cmp(b.1)).unwrap();
println!("Winner: Player {} with score {}", winner.0, winner.1);
winner
}