use super::card::Card;
use super::hand::Hand;
use super::street::Street;
#[derive(Debug, Clone, Copy)]
pub struct Board(Hand);
impl Board {
pub fn empty() -> Self {
Self(Hand::empty())
}
pub fn add(&mut self, card: Card) {
self.0 = Hand::add(self.0, Hand::from(u64::from(card)));
}
pub fn clear(&mut self) {
self.0 = Hand::empty();
}
pub fn street(&self) -> Street {
match self.0.size() {
0 => Street::Pref,
3 => Street::Flop,
4 => Street::Turn,
5 => Street::Rive,
_ => panic!("Invalid board size"),
}
}
}
impl From<Hand> for Board {
fn from(hand: Hand) -> Self {
Self(hand)
}
}
impl From<Board> for Hand {
fn from(board: Board) -> Self {
assert!(board.0.size() != 1);
assert!(board.0.size() != 2);
assert!(board.0.size() <= 5);
board.0
}
}
impl std::fmt::Display for Board {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(
f,
"{}",
Vec::<Card>::from(self.0)
.into_iter()
.map(|c| format!("{}", c))
.collect::<Vec<String>>()
.join(" ")
)
}
}