Bruh? 😳
This commit is contained in:
107
src/poker/card.h
Normal file
107
src/poker/card.h
Normal file
@@ -0,0 +1,107 @@
|
||||
/**
|
||||
* Copyright (c) 2022 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "../libs.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Cards
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Aces
|
||||
#define CARD_CLUBS_TWO 0x00
|
||||
#define CARD_CLUBS_THREE 0x01
|
||||
#define CARD_CLUBS_FOUR 0x02
|
||||
#define CARD_CLUBS_FIVE 0x03
|
||||
#define CARD_CLUBS_SIX 0x04
|
||||
#define CARD_CLUBS_SEVEN 0x05
|
||||
#define CARD_CLUBS_EIGHT 0x06
|
||||
#define CARD_CLUBS_NINE 0x07
|
||||
#define CARD_CLUBS_TEN 0x08
|
||||
#define CARD_CLUBS_JACK 0x09
|
||||
#define CARD_CLUBS_QUEEN 0x0A
|
||||
#define CARD_CLUBS_KING 0x0B
|
||||
#define CARD_CLUBS_ACE 0x0C
|
||||
|
||||
// Diamonds
|
||||
#define CARD_DIAMONDS_TWO 0x0D
|
||||
#define CARD_DIAMONDS_THREE 0x0E
|
||||
#define CARD_DIAMONDS_FOUR 0x0F
|
||||
#define CARD_DIAMONDS_FIVE 0x10
|
||||
#define CARD_DIAMONDS_SIX 0x11
|
||||
#define CARD_DIAMONDS_SEVEN 0x12
|
||||
#define CARD_DIAMONDS_EIGHT 0x13
|
||||
#define CARD_DIAMONDS_NINE 0x14
|
||||
#define CARD_DIAMONDS_TEN 0x15
|
||||
#define CARD_DIAMONDS_JACK 0x16
|
||||
#define CARD_DIAMONDS_QUEEN 0x17
|
||||
#define CARD_DIAMONDS_KING 0x18
|
||||
#define CARD_DIAMONDS_ACE 0x19
|
||||
|
||||
// Hearts
|
||||
#define CARD_HEARTS_TWO 0x1A
|
||||
#define CARD_HEARTS_THREE 0x1B
|
||||
#define CARD_HEARTS_FOUR 0x1C
|
||||
#define CARD_HEARTS_FIVE 0x1D
|
||||
#define CARD_HEARTS_SIX 0x1E
|
||||
#define CARD_HEARTS_SEVEN 0x1F
|
||||
#define CARD_HEARTS_EIGHT 0x20
|
||||
#define CARD_HEARTS_NINE 0x21
|
||||
#define CARD_HEARTS_TEN 0x22
|
||||
#define CARD_HEARTS_JACK 0x23
|
||||
#define CARD_HEARTS_QUEEN 0x24
|
||||
#define CARD_HEARTS_KING 0x25
|
||||
#define CARD_HEARTS_ACE 0x26
|
||||
|
||||
// Spades
|
||||
#define CARD_SPADES_TWO 0x27
|
||||
#define CARD_SPADES_THREE 0x28
|
||||
#define CARD_SPADES_FOUR 0x29
|
||||
#define CARD_SPADES_FIVE 0x2A
|
||||
#define CARD_SPADES_SIX 0x2B
|
||||
#define CARD_SPADES_SEVEN 0x2C
|
||||
#define CARD_SPADES_EIGHT 0x2D
|
||||
#define CARD_SPADES_NINE 0x2E
|
||||
#define CARD_SPADES_TEN 0x2F
|
||||
#define CARD_SPADES_JACK 0x30
|
||||
#define CARD_SPADES_QUEEN 0x31
|
||||
#define CARD_SPADES_KING 0x32
|
||||
#define CARD_SPADES_ACE 0x33
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Suits
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#define CARD_SUIT_CLUBS 0x00
|
||||
#define CARD_SUIT_DIAMONDS 0x01
|
||||
#define CARD_SUIT_HEARTS 0x02
|
||||
#define CARD_SUIT_SPADES 0x03
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Card numbers
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#define CARD_TWO 0x00
|
||||
#define CARD_THREE 0x01
|
||||
#define CARD_FOUR 0x02
|
||||
#define CARD_FIVE 0x03
|
||||
#define CARD_SIX 0x04
|
||||
#define CARD_SEVEN 0x05
|
||||
#define CARD_EIGHT 0x06
|
||||
#define CARD_NINE 0x07
|
||||
#define CARD_TEN 0x08
|
||||
#define CARD_JACK 0x09
|
||||
#define CARD_QUEEN 0x0A
|
||||
#define CARD_KING 0x0B
|
||||
#define CARD_ACE 0x0C
|
||||
|
||||
/** Count of cards in each suit */
|
||||
#define CARD_COUNT_PER_SUIT 13
|
||||
|
||||
/** Count of suits */
|
||||
#define CARD_SUIT_COUNT 4
|
||||
|
||||
/** Standard Card Deck Size */
|
||||
#define CARD_DECK_SIZE 52
|
29
src/poker/player.h
Normal file
29
src/poker/player.h
Normal file
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* Copyright (c) 2022 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "../libs.h"
|
||||
#include "card.h"
|
||||
|
||||
#define POKER_PLAYER_COUNT_MAX 4
|
||||
#define POKER_PLAYER_HAND_SIZE_MAX 2
|
||||
|
||||
#define POKER_PLAYER_STATE_FOLDED 1 << 0
|
||||
#define POKER_PLAYER_STATE_OUT 1 << 1
|
||||
#define POKER_PLAYER_STATE_HAS_BET_THIS_ROUND 1 << 2
|
||||
// #define POKER_PLAYER_STATE_SHOWING 1 << 3
|
||||
|
||||
typedef struct {
|
||||
uint16_t chips;
|
||||
uint8_t hand[POKER_PLAYER_HAND_SIZE_MAX];
|
||||
uint8_t state;
|
||||
|
||||
// int32_t currentBet;
|
||||
// uint8_t timesRaised;
|
||||
} pokerplayer_t;
|
||||
|
||||
extern pokerplayer_t POKER_PLAYERS[];
|
88
src/poker/poker.c
Normal file
88
src/poker/poker.c
Normal file
@@ -0,0 +1,88 @@
|
||||
/**
|
||||
* Copyright (c) 2022 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "poker.h"
|
||||
|
||||
pokerplayer_t POKER_PLAYERS[POKER_PLAYER_COUNT_MAX];
|
||||
uint8_t POKER_DECK[CARD_DECK_SIZE];
|
||||
uint8_t POKER_DECK_SIZE;
|
||||
|
||||
uint8_t POKER_COMMUNITY[POKER_COMMUNITY_SIZE_MAX];
|
||||
uint8_t POKER_COMMUNITY_SIZE;
|
||||
|
||||
uint8_t POKER_PLAYER_DEALER;
|
||||
uint8_t POKER_PLAYER_SMALL_BLIND;
|
||||
uint8_t POKER_PLAYER_BIG_BLIND;
|
||||
|
||||
void pokerInit() {
|
||||
uint8_t i;
|
||||
|
||||
// Set up players
|
||||
for(i = 0; i < POKER_PLAYER_COUNT_MAX; i++) {
|
||||
POKER_PLAYERS[i].chips = 10000;
|
||||
POKER_PLAYERS[i].state = 0;
|
||||
}
|
||||
|
||||
// Set up the initial state.
|
||||
// TODO: Should this be randomized?
|
||||
POKER_PLAYER_DEALER = 0;
|
||||
|
||||
// Reset the round state (For the first round)
|
||||
pokerNewRound();
|
||||
}
|
||||
|
||||
void pokerNewRound() {
|
||||
uint8_t i, j, k;
|
||||
uint8_t found;
|
||||
|
||||
// Reset round state
|
||||
POKER_COMMUNITY_SIZE = 0;
|
||||
|
||||
// Fill deck
|
||||
for(i = 0; i < CARD_DECK_SIZE; i++) POKER_DECK[i] = i;
|
||||
POKER_DECK_SIZE = CARD_DECK_SIZE;
|
||||
|
||||
// Shuffle Deck
|
||||
for(i = CARD_DECK_SIZE-1; i > 0; i--) {
|
||||
k = POKER_DECK[i];
|
||||
j = rand() % (i+1);
|
||||
POKER_DECK[i] = POKER_DECK[j];
|
||||
POKER_DECK[j] = k;
|
||||
}
|
||||
|
||||
// Reset Players and decide new blinds.
|
||||
found = 0;
|
||||
POKER_PLAYER_DEALER++;
|
||||
|
||||
for(i = 0; i < POKER_PLAYER_COUNT_MAX; i++) {
|
||||
POKER_PLAYERS[i].state &= ~(
|
||||
POKER_PLAYER_STATE_FOLDED |
|
||||
POKER_PLAYER_STATE_HAS_BET_THIS_ROUND
|
||||
);
|
||||
|
||||
// Have we found the dealer, small blind, and big blind players?
|
||||
if(found != 3 && (POKER_PLAYERS[i].state & POKER_PLAYER_STATE_OUT) == 0){
|
||||
k = (POKER_PLAYER_DEALER + i) % POKER_PLAYER_COUNT_MAX;
|
||||
|
||||
if(found == 0) {// Have we found the dealer?
|
||||
POKER_PLAYER_DEALER = i;
|
||||
found++;
|
||||
} else if(found == 1) {// Have we found the small blind?
|
||||
POKER_PLAYER_SMALL_BLIND = i;
|
||||
found++;
|
||||
} else if(found == 2) {// Have we found the big blind?
|
||||
POKER_PLAYER_BIG_BLIND = i;
|
||||
found++;
|
||||
}
|
||||
}
|
||||
|
||||
// Deal two cards to the player.
|
||||
for(j = 0; j < POKER_PLAYER_HAND_SIZE_MAX; j++) {
|
||||
POKER_PLAYERS[i].hand[j] = POKER_DECK[POKER_DECK_SIZE--];
|
||||
}
|
||||
}
|
||||
}
|
27
src/poker/poker.h
Normal file
27
src/poker/poker.h
Normal file
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* Copyright (c) 2022 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "../libs.h"
|
||||
#include "card.h"
|
||||
#include "player.h"
|
||||
|
||||
#define POKER_COMMUNITY_SIZE_MAX 5
|
||||
|
||||
extern uint8_t POKER_DECK[];
|
||||
extern uint8_t POKER_DECK_SIZE;
|
||||
|
||||
extern uint8_t POKER_COMMUNITY[];
|
||||
extern uint8_t POKER_COMMUNITY_SIZE;
|
||||
|
||||
extern uint8_t POKER_PLAYER_DEALER;
|
||||
extern uint8_t POKER_PLAYER_SMALL_BLIND;
|
||||
extern uint8_t POKER_PLAYER_BIG_BLIND;
|
||||
|
||||
void pokerInit();
|
||||
|
||||
void pokerNewRound();
|
Reference in New Issue
Block a user