Struct twentyone::game::Dealer [−][src]
Describes a blackjack dealer
Implementations
impl Dealer<'_>
[src]
pub fn new<'a>(
shoe: Vec<[char; 2]>,
game_config: GameConfig,
callback: &'a dyn Fn(DealerRequest, Option<&Player>, &Dealer<'_>) -> PlayerAction
) -> Dealer<'_>
[src]
shoe: Vec<[char; 2]>,
game_config: GameConfig,
callback: &'a dyn Fn(DealerRequest, Option<&Player>, &Dealer<'_>) -> PlayerAction
) -> Dealer<'_>
Returns a new Dealer
Arguments
shoe
- The shoe (or deck) to draw fromcallback
- A function to handle player turns
callback
is passed a DealerRequest
and an Option<&Player>
.
The option will always have a player if it applies to the event (eg. betting),
but will not have a player for dealer updates (eg. up card, dealer hits).
Callback
The callback function will always return a PlayerAction
,
but it should return different things based on the DealerRequest
:
DealerRequest | PlayerAction |
---|---|
DealerRequest::Bet | PlayerAction::Bet(i32) |
DealerRequest::Play | One of PlayerAction::Hit , PlayerAction::Stand , PlayerAction::DoubleDown , PlayerAction::Split |
DealerRequest::Error(PlayerActionError) | PlayerAction::None and handle the returned error |
DealerRequest::UpCard([char; 2]) | PlayerAction::None |
DealerRequest::HitCard([char; 2]) | PlayerAction::None |
DealerRequest::DealerHand(Vec<[char; 2]>) | PlayerAction::None |
If an unexpected return value is given, the callback will be called
again with a request of DealerAction::Error(PlayerActionError::UnexpectedAction)
along with the index of the affected hand (if applicable)
and the request that was invalid.
After an error is provided, the dealer will request the same action that caused the error. If nothing changes, the dealer will infinitely loop.
Examples
Example code is available in the Quick Start from the main page.
pub fn hand(&self) -> &Vec<[char; 2]>
[src]
Returns a reference to the dealer’s hand
pub fn shoe(&self) -> &Vec<[char; 2]>
[src]
Returns a reference to the dealer’s shoe
pub fn players(&self) -> &Vec<Player>
[src]
Returns a reference to the dealer’s players
pub fn hand_mut(&mut self) -> &mut Vec<[char; 2]>
[src]
Returns a mutable reference to the dealer’s hand
pub fn shoe_mut(&mut self) -> &mut Vec<[char; 2]>
[src]
Returns a mutable reference to the dealer’s shoe
pub fn players_mut(&mut self) -> &mut Vec<Player>
[src]
Returns a mutable reference to the dealer’s players
pub fn clear_table(&mut self)
[src]
Clear the dealer’s and all players’ hands
pub fn deal_hands(&mut self)
[src]
Deal a hand to all players
pub fn hit_card(&mut self, player: usize, hand: usize)
[src]
Hit a card to a player
Arguments
player
- The index of the player to hithand
- The index of the player’s hand (used for split hands)
pub fn play_round(&mut self, clear_table: bool)
[src]
Play a round of blackjack
Calls callback
to get player bets/actions.
Arguments
clear_table
- Clear the table at the beginning of the round
Auto Trait Implementations
impl<'a> !RefUnwindSafe for Dealer<'a>
impl<'a> !Send for Dealer<'a>
impl<'a> !Sync for Dealer<'a>
impl<'a> Unpin for Dealer<'a>
impl<'a> !UnwindSafe for Dealer<'a>
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, 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>,