Working on the poker game stuff.

This commit is contained in:
2022-01-09 20:15:16 -08:00
parent 29215a3b6f
commit cc9e50c4ab
7 changed files with 265 additions and 31 deletions

View File

@@ -8,18 +8,22 @@
#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;
uint8_t POKER_PLAYER_BETTER;
uint16_t POKER_GAME_BLINDS_CURRENT;
uint16_t POKER_GAME_POT;
pokerpot_t POKER_POTS[POKER_POT_COUNT_MAX];
uint8_t POKER_POT_CURRENT;
uint8_t POKER_POT_COUNT;
void pokerInit() {
uint8_t i;
@@ -33,8 +37,6 @@ void pokerInit() {
// Set up the initial state.
// TODO: Should this be randomized?
POKER_PLAYER_DEALER = 0;
POKER_GAME_POT = 0;
POKER_GAME_BLINDS_CURRENT = 10;
// Reset the round state (For the first round)
@@ -47,6 +49,15 @@ void pokerNewRound() {
// Reset round state
POKER_COMMUNITY_SIZE = 0;
POKER_POT_COUNT = 0;
POKER_POT_CURRENT = 0;
// Reset the pots.
for(i = 0; i < POKER_POT_COUNT_MAX; i++) {
POKER_POTS[i].chips = 0;
POKER_POTS[i].call = 0;
POKER_POTS[i].playersCount = 0;
}
// Fill deck
for(i = 0; i < CARD_DECK_SIZE; i++) POKER_DECK[i] = i;
@@ -91,11 +102,13 @@ void pokerNewRound() {
POKER_PLAYERS[i].hand[j] = POKER_DECK[POKER_DECK_SIZE--];
}
}
}
void pokerTakeBlinds() {
// Take blinds
// TODO: I need to make sure the blind players even have the chips to blind.
POKER_PLAYERS[POKER_PLAYER_SMALL_BLIND].chips -= POKER_GAME_BLINDS_CURRENT;
POKER_PLAYERS[POKER_PLAYER_BIG_BLIND].chips -= (POKER_GAME_BLINDS_CURRENT*2);
POKER_GAME_POT += POKER_GAME_BLINDS_CURRENT * 3;
POKER_POT_BET(POKER_PLAYER_SMALL_BLIND, POKER_GAME_BLINDS_CURRENT);
POKER_POT_BET(POKER_PLAYER_BIG_BLIND, (POKER_GAME_BLINDS_CURRENT*2));
// Set the initial better, we set this to the BIG BLIND player because we will
// cycle to the "next better" as soon as the game starts.
POKER_PLAYER_BETTER = POKER_PLAYER_BIG_BLIND;
}

View File

@@ -9,24 +9,27 @@
#include "../libs.h"
#include "card.h"
#include "player.h"
#include "pot.h"
#define POKER_COMMUNITY_SIZE_MAX 5
#define POKER_HUMAN_INDEX 0x00
#define POKER_COUNT_FLOP 0x03
#define POKER_COUNT_TURN 0x01
#define POKER_COUNT_RIVER 0x01
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;
extern uint8_t POKER_PLAYER_BETTER;
extern uint16_t POKER_GAME_BLINDS_CURRENT;
extern uint16_t POKER_GAME_POT;
void pokerInit();
void pokerNewRound();
void pokerTakeBlinds();
void pokerNewRound();

43
src/poker/pot.h Normal file
View File

@@ -0,0 +1,43 @@
/**
* Copyright (c) 2022 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "../libs.h"
#include "player.h"
#define POKER_POT_COUNT_MAX POKER_PLAYER_COUNT_MAX
typedef struct {
/** Current pot of chips */
uint16_t chips;
/** Current call value for this pot */
uint16_t call;
/** Players who are participating in the pot */
uint8_t players[POKER_PLAYER_COUNT_MAX];
uint8_t playersCount;
} pokerpot_t;
extern pokerpot_t POKER_POTS[];
extern uint8_t POKER_POT_CURRENT;
extern uint8_t POKER_POT_COUNT;
// TODO: This may become a function because if a player doesn't have enough
// chips to bet to the active pot, then the pot needs to autosplit, take those
// who have bet into the pot up to the amount that the player betting can bet,
// and push them into a new pot.
// There also needs to be a limit on this, for example;
// player 0 has $1200, and bets $1000, he can't bet more than that ever.
// player 1 has $1000, and bets all of it. The remanin
// player 2 has $700, and bets all o it. A new $300 sidepot auto creates
// player 3 has $500 and bets all of it, Another sidepot with $200 is auto made.
#define POKER_POT_BET(player, amount) \
POKER_PLAYERS[player].chips -= amount;\
POKER_POTS[POKER_POT_CURRENT].chips += amount;\
POKER_POTS[POKER_POT_CURRENT].call = amount;