added blackjack (not tested)

This commit is contained in:
2025-11-08 18:24:09 -05:00
parent 06b6ddcdef
commit d8c8a2d27c
2 changed files with 66 additions and 1 deletions

View File

@@ -0,0 +1,55 @@
// SPDX-License-Identifer: MIT
/* poker.odin
*
* Routines for handling poker related features
*
* Written by TiredWithJoy
*/
package blackjack
import "../log"
import "../casino"
/*
Type represeting a poker hand
*/
Hand :: struct {
_: [11]casino.Card,
}
/*
Determine the rank of the hand
*/
evaluate_hand :: proc(hand: Hand) -> int {
toal:int
aces: [dynamic]int
for x, i in hand {
total = total + x.rank
if x.rank = 1 {
total = total + 11
append(&aces, i)
}
if total > 21 {
if len(aces) > 0 {
total = total - 10
pop(&aces)
}
}
}
return total
}
/*
Compare two hands and return true if the
first one is better than the second one
*/
compare_hands :: proc(player: Hand, other: Hand) -> casino.Hand {
if evaluate_hand(player) > evaluate_hand(other) {
return .WIN
}else if evaluate_hand(player) < evaluate_hand(other) {
return .LOSE
} else {
return .TIE
}
}

View File

@@ -3,7 +3,7 @@
* *
* Routines for handling card games * Routines for handling card games
* *
* Written by vx-clutch * Written by vx-clutch and TiredWithJoy
*/ */
package casino package casino
@@ -20,6 +20,15 @@ Suit :: enum {
SPADES, SPADES,
} }
/*
Type representing hand comparison
*/
Hand :: enum {
WIN,
LOSE,
TIE,
}
/* /*
Type represeting a card Type represeting a card
*/ */
@@ -147,3 +156,4 @@ Deal one card from the top of the deck
deal_card :: proc(deck: ^Deck) -> Card { deal_card :: proc(deck: ^Deck) -> Card {
return deck^.cards[deck^.top_index] return deck^.cards[deck^.top_index]
} }