moved split check to hand

This commit is contained in:
Niklas Kapelle 2024-05-22 14:07:04 +02:00
parent 6c21eb960f
commit d34a72cf3b
Signed by: niklas
GPG Key ID: 4EB651B36D841D16
2 changed files with 36 additions and 22 deletions

View File

@ -152,12 +152,7 @@ impl BlackjackGame {
return false;
}
if let Some(card_0) = hand.hand.get_card(0) {
if let Some(card_1) = hand.hand.get_card(1) {
if card_0.index.get_blackjack_value(true)
!= card_1.index.get_blackjack_value(true)
{
// Cards are not the same value
if !hand.hand.is_valid_for_bj_split() {
return false;
}
@ -174,8 +169,6 @@ impl BlackjackGame {
player.hands.push(new_hand);
}
}
}
(GameState::PlayerTurn(player_index, hand_index), PlayMoves::DoubleDown) => {
let Some(player) = self.players.get_mut(*player_index) else {
// Player does not exists

View File

@ -40,6 +40,27 @@ impl Hand {
self.cards.len() == 2 && self.get_blackjack_value() == 21
}
/**
* Returns true if this hand could be split in a blackjack game.
*/
pub fn is_valid_for_bj_split(&self) -> bool {
if self.cards.len() != 2 {
return false;
}
if let Some(card_0) = self.get_card(0) {
if let Some(card_1) = self.get_card(1) {
if card_0.index.get_blackjack_value(true) != card_1.index.get_blackjack_value(true)
{
// Cards are not the same value
return false;
}
}
}
true
}
/**
* Put another hand into this.
* Leaves the other hand empty.