From 06b6ddcdef879a0c4f9243dc2f73d06552d5371b Mon Sep 17 00:00:00 2001 From: vx-clutch Date: Sat, 8 Nov 2025 17:43:05 -0500 Subject: [PATCH] update libpike --- libpike/casino/casino.odin | 149 ++++++++++++++++++++++++++++++++++++ libpike/poker/poker.odin | 152 +------------------------------------ main.odin | 9 +-- 3 files changed, 155 insertions(+), 155 deletions(-) create mode 100644 libpike/casino/casino.odin diff --git a/libpike/casino/casino.odin b/libpike/casino/casino.odin new file mode 100644 index 0000000..429b820 --- /dev/null +++ b/libpike/casino/casino.odin @@ -0,0 +1,149 @@ +// SPDX-License-Identifer: MIT +/* casino.odin + * + * Routines for handling card games + * + * Written by vx-clutch +*/ +package casino + +import "core:fmt" +import "core:math/rand" + +/* +Type represeting a suit +*/ +Suit :: enum { + CRUBS, + DIAMONDS, + HEARTS, + SPADES, +} + +/* +Type represeting a card +*/ +Card :: struct { + rank: int, + suit: Suit, +} + +/* +Type represeting a deck of cards +*/ +Deck :: struct { + cards: [52]Card, + top_index: int, +} + +/* +Creates a well-ordered deck +*/ +create_deck :: proc() -> Deck { + deck: Deck + deck.top_index = 0 + for suit in Suit { + for rank in 1 ..= 13 { + deck.cards[deck.top_index] = Card{rank, suit} + deck.top_index += 1 + } + } + deck.top_index = 0 + return deck +} + +CRUB :: "♣" +DIAMOND :: "♦" +HEART :: "♥️" +SPADE :: "♠" + +/* +Pretty print a card +*/ +print_card :: proc(card: Card) { + switch card.suit { + case .CRUBS: + switch card.rank { + case 1: + fmt.printf("A%s", CRUB) + case 11: + fmt.printf("J%s", CRUB) + case 12: + fmt.printf("Q%s", CRUB) + case 13: + fmt.printf("K%s", CRUB) + case: + fmt.printf("%d%s", card.rank, CRUB) + } + case .DIAMONDS: + switch card.rank { + case 1: + fmt.printf("A%s", DIAMOND) + case 11: + fmt.printf("J%s", DIAMOND) + case 12: + fmt.printf("Q%s", DIAMOND) + case 13: + fmt.printf("K%s", DIAMOND) + case: + fmt.printf("%d%s", card.rank, DIAMOND) + } + case .HEARTS: + switch card.rank { + case 1: + fmt.printf("A%s", HEART) + case 11: + fmt.printf("J%s", HEART) + case 12: + fmt.printf("Q%s", HEART) + case 13: + fmt.printf("K%s", HEART) + case: + fmt.printf("%d%s", card.rank, HEART) + } + case .SPADES: + switch card.rank { + case 1: + fmt.printf("A%s", SPADE) + case 11: + fmt.printf("J%s", SPADE) + case 12: + fmt.printf("Q%s", SPADE) + case 13: + fmt.printf("K%s", SPADE) + case: + fmt.printf("%d%s", card.rank, SPADE) + } + } +} + +/* +Pretty print out the deck +*/ +print_deck :: proc(deck: Deck) { + i := 0 + for card in deck.cards { + if i >= 13 { + fmt.println("") + i = 0 + } + print_card(card) + fmt.print(" ") + i += 1 + } + fmt.println("") +} + +/* +Shuffles the deck +*/ +shuffle :: proc(deck: ^Deck) { + rand.shuffle(deck^.cards[:]) +} + +/* +Deal one card from the top of the deck +*/ +deal_card :: proc(deck: ^Deck) -> Card { + return deck^.cards[deck^.top_index] +} diff --git a/libpike/poker/poker.odin b/libpike/poker/poker.odin index 6e0f3ee..f9ecc87 100644 --- a/libpike/poker/poker.odin +++ b/libpike/poker/poker.odin @@ -7,20 +7,8 @@ */ package poker -import "core:fmt" -import "core:math/rand" - import "../log" - -/* -Type represeting a suit -*/ -Suit :: enum { - CRUBS, - DIAMONDS, - HEARTS, - SPADES, -} +import "../casino" /* Type represeting a hand's rank @@ -38,147 +26,11 @@ HandRank :: enum { ROYAL, } -/* -Type represeting a card -*/ -Card :: struct { - rank: int, - suit: Suit, -} - /* Type represeting a poker hand */ Hand :: struct { - _: [5]Card, -} - -/* -Type represeting a deck of cards -*/ -Deck :: struct { - cards: [52]Card, - top_index: int, -} - -/* -Creates a well-ordered deck -*/ -create_deck :: proc() -> Deck { - deck: Deck - deck.top_index = 0 - for suit in Suit { - for rank in 1 ..= 13 { - deck.cards[deck.top_index] = Card{rank, suit} - deck.top_index += 1 - } - } - deck.top_index = 0 - return deck -} - -CRUB :: "♣" -DIAMOND :: "♦" -HEART :: "♥️" -SPADE :: "♠" - -/* -Pretty print a card -*/ -print_card :: proc(card: Card) { - switch card.suit { - case .CRUBS: - switch card.rank { - case 1: - fmt.printf("A%s", CRUB) - case 11: - fmt.printf("J%s", CRUB) - case 12: - fmt.printf("Q%s", CRUB) - case 13: - fmt.printf("K%s", CRUB) - case: - fmt.printf("%d%s", card.rank, CRUB) - } - case .DIAMONDS: - switch card.rank { - case 1: - fmt.printf("A%s", DIAMOND) - case 11: - fmt.printf("J%s", DIAMOND) - case 12: - fmt.printf("Q%s", DIAMOND) - case 13: - fmt.printf("K%s", DIAMOND) - case: - fmt.printf("%d%s", card.rank, DIAMOND) - } - case .HEARTS: - switch card.rank { - case 1: - fmt.printf("A%s", HEART) - case 11: - fmt.printf("J%s", HEART) - case 12: - fmt.printf("Q%s", HEART) - case 13: - fmt.printf("K%s", HEART) - case: - fmt.printf("%d%s", card.rank, HEART) - } - case .SPADES: - switch card.rank { - case 1: - fmt.printf("A%s", SPADE) - case 11: - fmt.printf("J%s", SPADE) - case 12: - fmt.printf("Q%s", SPADE) - case 13: - fmt.printf("K%s", SPADE) - case: - fmt.printf("%d%s", card.rank, SPADE) - } - } -} - -/* -Pretty print out the deck -*/ -print_deck :: proc(deck: Deck) { - i := 0 - for card in deck.cards { - if i >= 13 { - fmt.println("") - i = 0 - } - print_card(card) - fmt.print(" ") - i += 1 - } - fmt.println("") -} - -/* -Shuffles the deck -*/ -shuffle :: proc(deck: ^Deck) { - rand.shuffle(deck^.cards[:]) -} - -/* -Deal one card from the top of the deck -*/ -deal_card :: proc(deck: ^Deck) -> Card { - return deck^.cards[deck^.top_index] -} - -/* -Deal a hand of size n -*/ -deal_hand :: proc(d: Deck, n: int) -> Card { - log.printl("%s is NOT implemented", #procedure) - return Card{} + _: [5]casino.Card, } /* diff --git a/main.odin b/main.odin index c4e72f2..66662e7 100644 --- a/main.odin +++ b/main.odin @@ -13,17 +13,16 @@ package main -import "core:fmt" import "libpike/log" -import "libpike/poker" +import "libpike/casino" main :: proc() { log.printl("pike init") - deck := poker.create_deck() + deck := casino.create_deck() - // poker.shuffle(&deck) + casino.shuffle(&deck) - poker.print_deck(deck) + casino.print_deck(deck) }