This commit is contained in:
2026-06-06 14:18:39 +02:00
parent 0a5171db84
commit ee246cf08e
3 changed files with 105 additions and 84 deletions
+45 -19
View File
@@ -5,12 +5,12 @@ import "core:math/rand"
VALUES :: []u8{1, 1, 1, 2, 2, 3, 3, 4, 4, 5}
COLORS :: enum u8 {
RED,
GREEN,
WHITE,
BLUE,
YELLOW,
RAINBOW,
RED = 0b000001,
GREEN = 0b000010,
WHITE = 0b000100,
BLUE = 0b001000,
YELLOW = 0b010000,
RAINBOW = 0b100000,
}
Card :: bit_field u8 {
@@ -26,14 +26,24 @@ Hand :: distinct []Card
// player can only place card of value `played[color]+1`.
Played_Card_Piles :: distinct [6]u8
Belief_State :: []bit_field u16 {
// `11111` can be any value 1-5.
// `00010` must be value 4.
value: u8 | 5,
// `111111` can be any color.
// `100001` can be red or rainbow.
color: u8 | 6,
}
Game :: struct {
num_players: int,
num_hints: int,
num_lives: int,
hand_size: int,
player_hands: [dynamic]Hand,
deck: [dynamic]Card,
played: Played_Card_Piles,
num_players: int,
num_hints: int,
num_lives: int,
hand_size: int,
played: Played_Card_Piles,
player_hands: []Hand,
player_beliefs: []Belief_State,
deck: [dynamic]Card,
}
create_deck :: proc() -> (deck: [dynamic]Card) {
@@ -48,18 +58,33 @@ create_deck :: proc() -> (deck: [dynamic]Card) {
deal_hands :: proc(
deck: ^[dynamic]Card,
num_players: int,
hand_size: int,
) -> (
player_hands: [dynamic]Hand,
) {
num_players, hand_size: int,
allocator := context.allocator,
) -> []Hand {
player_hands: [dynamic]Hand
for i in 0 ..< num_players {
start := len(deck) - hand_size
hand := Hand(deck[start:])
append(&player_hands, hand)
resize(deck, start)
}
return
return player_hands[:]
}
init_beliefs :: proc(
num_players, hand_size: int,
allocator := context.allocator,
) -> []Belief_State {
player_beliefs: [dynamic]Belief_State
for p in 0 ..< num_players {
bs: Belief_State
for c in 0 ..< hand_size {
bs[c].value = 0b11111
bs[c].color = 0b111111
}
append(&player_beliefs, bs)
}
return player_beliefs[:]
}
create_game :: proc(hint_tokens, lives_left, num_players: int) -> (s: Game) {
@@ -70,6 +95,7 @@ create_game :: proc(hint_tokens, lives_left, num_players: int) -> (s: Game) {
s.hand_size = num_players <= 3 ? 5 : 4
s.deck = create_deck()
s.player_hands = deal_hands(&s.deck, num_players, s.hand_size)
s.player_beliefs = init_beliefs(num_players, s.hand_size)
return
}