Bruh? 😳
This commit is contained in:
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--];
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user