diff --git a/libpike/blackjack/blackjack.odin b/libpike/blackjack/blackjack.odin new file mode 100644 index 0000000..52fe241 --- /dev/null +++ b/libpike/blackjack/blackjack.odin @@ -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 + } +} + diff --git a/libpike/casino/casino.odin b/libpike/casino/casino.odin index 429b820..5c5869c 100644 --- a/libpike/casino/casino.odin +++ b/libpike/casino/casino.odin @@ -3,7 +3,7 @@ * * Routines for handling card games * - * Written by vx-clutch + * Written by vx-clutch and TiredWithJoy */ package casino @@ -20,6 +20,15 @@ Suit :: enum { SPADES, } +/* +Type representing hand comparison +*/ +Hand :: enum { + WIN, + LOSE, + TIE, +} + /* Type represeting a card */ @@ -147,3 +156,4 @@ Deal one card from the top of the deck deal_card :: proc(deck: ^Deck) -> Card { return deck^.cards[deck^.top_index] } +