Working on poker logic.
This commit is contained in:
24
src/poker/card.c
Normal file
24
src/poker/card.c
Normal file
@ -0,0 +1,24 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
#include "card.h"
|
||||
|
||||
void cardDeal(card_t *source, uint8_t *sourceSize, card_t *dest,
|
||||
uint8_t *destSize
|
||||
) {
|
||||
card_t card;
|
||||
uint8_t i;
|
||||
|
||||
// Take Card
|
||||
i = *sourceSize - 1;
|
||||
card = source[i];
|
||||
*sourceSize = i;
|
||||
|
||||
// Put card
|
||||
i = *destSize;
|
||||
dest[i] = card;
|
||||
*destSize = i+1;
|
||||
}
|
21
src/poker/card.h
Normal file
21
src/poker/card.h
Normal file
@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
#pragma once
|
||||
#include <dawn/dawn.h>
|
||||
|
||||
/**
|
||||
* Deals a card from an array source to an array destination. Pointers to array
|
||||
* lengths will be updated.
|
||||
*
|
||||
* @param source Array source.
|
||||
* @param sourceSize Pointer to where the count of cards is being stored.
|
||||
* @param dest Array destination.
|
||||
* @param destSize Pointer to the size of the destination array.
|
||||
*/
|
||||
void cardDeal(card_t *source, uint8_t *sourceSize, card_t *dest,
|
||||
uint8_t *destSize
|
||||
);
|
14
src/poker/player.c
Normal file
14
src/poker/player.c
Normal file
@ -0,0 +1,14 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "player.h"
|
||||
|
||||
void pokerPlayerBet(poker_t *poker, pokerplayer_t *player, int32_t chips) {
|
||||
poker->pot += chips;
|
||||
player->chips -= chips;
|
||||
player->currentBet += chips;
|
||||
}
|
17
src/poker/player.h
Normal file
17
src/poker/player.h
Normal file
@ -0,0 +1,17 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include <dawn/dawn.h>
|
||||
|
||||
/**
|
||||
* Let a player bet chips into the pot.
|
||||
*
|
||||
* @param poker Poker game instance.
|
||||
* @param player Poker player instance.
|
||||
* @param chips Chips to bet.
|
||||
*/
|
||||
void pokerPlayerBet(poker_t *poker, pokerplayer_t *player, int32_t chips);
|
@ -33,13 +33,19 @@ void pokerUpdate(poker_t *poker, engine_t *engine) {
|
||||
case POKER_ROUND_MATCH:
|
||||
pokerMatchUpdate(poker);
|
||||
break;
|
||||
case POKER_ROUND_BET0:
|
||||
case POKER_ROUND_BET1:
|
||||
case POKER_ROUND_BET2:
|
||||
case POKER_ROUND_BET3:
|
||||
pokerBetUpdate(poker);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// Rendering
|
||||
shaderUse(&poker->shader);
|
||||
pokerFrameWorld(poker, &engine->render);
|
||||
|
||||
pokerWorldRender(poker);
|
||||
for(uint8_t pi = 0; pi < POKER_PLAYER_COUNT; pi++) {
|
||||
uint8_t seat = pokerPlayerGetSeatForPlayer(pi);
|
||||
|
@ -48,13 +48,16 @@ void pokerTalkRender(poker_t *poker, input_t *input) {
|
||||
shaderUseTexture(&poker->shader, &poker->font.texture);
|
||||
primitiveDraw(&poker->talkPrimitive, 0, -1);
|
||||
|
||||
if(inputIsPressed(input, INPUT_ACCEPT)) poker->talkText = NULL;
|
||||
if(inputIsPressed(input, INPUT_ACCEPT)) {
|
||||
poker->talkText = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void pokerTalk(poker_t *poker, char *text) {
|
||||
poker->talkText = text;
|
||||
poker->roundTextCounter++;
|
||||
}
|
||||
|
||||
bool pokerTalkIsTalking(poker_t *poker) {
|
||||
return poker->talkTextInfo != NULL;
|
||||
return poker->talkText != NULL || poker->talkTextInfo != NULL;
|
||||
}
|
68
src/poker/round/bet.c
Normal file
68
src/poker/round/bet.c
Normal file
@ -0,0 +1,68 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "bet.h"
|
||||
|
||||
void pokerBetPlayerNext(poker_t *poker) {
|
||||
// Go to next player, keep contained.
|
||||
poker->roundBetCurrent = (poker->roundBetCurrent + 1) % POKER_PLAYER_COUNT;
|
||||
|
||||
// Did we go full circle?
|
||||
if(poker->roundBetCurrent == poker->roundSmallBlind) {
|
||||
if(poker->round == POKER_ROUND_BET3) {
|
||||
pokerWinnerInit(poker);
|
||||
return;
|
||||
}
|
||||
|
||||
pokerFlopInit(poker);
|
||||
return;
|
||||
}
|
||||
|
||||
// Init the next player
|
||||
pokerBetPlayerInit(poker, poker->players + poker->roundBetCurrent);
|
||||
}
|
||||
|
||||
void pokerBetPlayerUpdate(poker_t *poker, pokerplayer_t *player) {
|
||||
pokerBetPlayerNext(poker);
|
||||
}
|
||||
|
||||
void pokerBetPlayerInit(poker_t *poker, pokerplayer_t *player) {
|
||||
// Check the player state (to see if we even can init, e.g. folded/not)
|
||||
if(player->state & (POKER_PLAYER_STATE_FOLDED|POKER_PLAYER_STATE_OUT)) {
|
||||
pokerBetPlayerNext(poker);
|
||||
return;
|
||||
}
|
||||
|
||||
printf("Betting round player %u\n", poker->roundBetCurrent);
|
||||
}
|
||||
|
||||
void pokerBetInit(poker_t *poker) {
|
||||
printf("Betting round start\n");
|
||||
|
||||
if(poker->round == POKER_ROUND_DEAL) {
|
||||
poker->round = POKER_ROUND_BET0;
|
||||
printf("Betting 0\n");
|
||||
} else if(poker->round == POKER_ROUND_FLOP) {
|
||||
poker->round = POKER_ROUND_BET1;
|
||||
printf("Betting 1\n");
|
||||
} else if(poker->round == POKER_ROUND_TURN) {
|
||||
poker->round = POKER_ROUND_BET2;
|
||||
printf("Betting 2\n");
|
||||
} else if(poker->round == POKER_ROUND_RIVER) {
|
||||
poker->round = POKER_ROUND_BET3;
|
||||
printf("Betting 3\n");
|
||||
}
|
||||
|
||||
// Set the inital player
|
||||
poker->roundBetCurrent = poker->roundSmallBlind;
|
||||
pokerBetPlayerInit(poker, poker->players+poker->roundBetCurrent);
|
||||
}
|
||||
|
||||
void pokerBetUpdate(poker_t *poker) {
|
||||
// Take the current player
|
||||
pokerBetPlayerUpdate(poker, poker->players + poker->roundBetCurrent);
|
||||
}
|
18
src/poker/round/bet.h
Normal file
18
src/poker/round/bet.h
Normal file
@ -0,0 +1,18 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <dawn/dawn.h>
|
||||
#include "flop.h"
|
||||
#include "winner.h"
|
||||
|
||||
void pokerBetPlayerNext(poker_t *poker);
|
||||
void pokerBetPlayerInit(poker_t *poker, pokerplayer_t *player);
|
||||
void pokerBetPlayerUpdate(poker_t *poker, pokerplayer_t *player);
|
||||
|
||||
void pokerBetInit(poker_t *poker);
|
||||
void pokerBetUpdate(poker_t *poker);
|
@ -10,4 +10,11 @@
|
||||
|
||||
void pokerBlindsInit(poker_t *poker) {
|
||||
poker->round = POKER_ROUND_BLINDS;
|
||||
|
||||
// Now take blinds
|
||||
pokerPlayerBet(poker,poker->players+poker->roundSmallBlind, poker->blindSmall);
|
||||
pokerPlayerBet(poker,poker->players+poker->roundBigBlind, poker->blindBig);
|
||||
|
||||
printf("Blinds Taken\n");
|
||||
pokerDealInit(poker);
|
||||
}
|
@ -6,6 +6,8 @@
|
||||
*/
|
||||
|
||||
#include <dawn/dawn.h>
|
||||
#include "deal.h"
|
||||
#include "../player.h"
|
||||
|
||||
/**
|
||||
* Initializes the blinds round.
|
||||
|
@ -9,27 +9,9 @@
|
||||
void pokerDealInit(poker_t *poker) {
|
||||
uint8_t x, y;
|
||||
card_t temporary;
|
||||
|
||||
// Prepare the initial game state
|
||||
pokerplayer_t *player;
|
||||
|
||||
poker->round = POKER_ROUND_DEAL;
|
||||
poker->pot = 0;
|
||||
poker->roundBet = 0;
|
||||
poker->graveSize = 0;
|
||||
poker->cardsFacing = 0;
|
||||
poker->deckSize = CARD_DECK_SIZE;
|
||||
for(x = 0; x < CARD_DECK_SIZE; x++) poker->deck[x] = x;
|
||||
|
||||
// Reset the players
|
||||
for(x = 0; x < POKER_PLAYER_COUNT; x++) {
|
||||
poker->players[x].cardCount = 0;
|
||||
poker->players[x].currentBet = 0;
|
||||
|
||||
// Invert then bitwise AND to turn off.
|
||||
poker->players[x].state &= ~(
|
||||
POKER_PLAYER_STATE_FOLDED |
|
||||
POKER_PLAYER_STATE_SHOWING
|
||||
);
|
||||
}
|
||||
|
||||
// Hard look at the dealer
|
||||
pokerLookAtPlayer(&poker->cameraWorld, POKER_SEAT_DEALER);
|
||||
@ -42,5 +24,18 @@ void pokerDealInit(poker_t *poker) {
|
||||
poker->deck[y] = poker->deck[x];// Move my card there
|
||||
poker->deck[x] = temporary;// Put other card here.
|
||||
}
|
||||
printf("Deal\n");
|
||||
|
||||
// Deal 2 card to each player
|
||||
for(y = 0; y < POKER_DEAL_CARD_EACH; y++) {
|
||||
for(x = 0; x < POKER_PLAYER_COUNT; x++) {
|
||||
player = poker->players + x;
|
||||
cardDeal(
|
||||
poker->deck, &poker->deckSize,
|
||||
player->cards, &player->cardCount
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
printf("Cards Dealt\n");
|
||||
pokerBetInit(poker);
|
||||
}
|
@ -7,8 +7,10 @@
|
||||
|
||||
#pragma once
|
||||
#include <dawn/dawn.h>
|
||||
#include "blinds.h"
|
||||
#include "../render/look.h"
|
||||
#include "../player.h"
|
||||
#include "../card.h"
|
||||
#include "bet.h"
|
||||
|
||||
/**
|
||||
* Resets a poker game for the new round.
|
||||
|
39
src/poker/round/flop.c
Normal file
39
src/poker/round/flop.c
Normal file
@ -0,0 +1,39 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "flop.h"
|
||||
|
||||
void pokerFlopInit(poker_t *poker) {
|
||||
uint8_t count, i;
|
||||
|
||||
if(poker->round == POKER_ROUND_BET0) {
|
||||
printf("Poker Flop Start\n");
|
||||
poker->round = POKER_ROUND_FLOP;
|
||||
count = POKER_FLOP_CARD_COUNT;
|
||||
} else if(poker->round == POKER_ROUND_BET1) {
|
||||
printf("Poker Turn\n");
|
||||
poker->round = POKER_ROUND_TURN;
|
||||
count = POKER_TURN_CARD_COUNT;
|
||||
} else if(poker->round == POKER_ROUND_BET2) {
|
||||
printf("Poker River\n");
|
||||
poker->round = POKER_ROUND_RIVER;
|
||||
count = POKER_RIVER_CARD_COUNT;
|
||||
}
|
||||
|
||||
// Burn a card
|
||||
poker->deckSize--;
|
||||
|
||||
// Flops
|
||||
for(i = 0; i < count; i++) {
|
||||
cardDeal(
|
||||
poker->deck, &poker->deckSize,
|
||||
poker->cards, &poker->cardsFacing
|
||||
);
|
||||
}
|
||||
|
||||
pokerBetInit(poker);
|
||||
}
|
13
src/poker/round/flop.h
Normal file
13
src/poker/round/flop.h
Normal file
@ -0,0 +1,13 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <dawn/dawn.h>
|
||||
#include "bet.h"
|
||||
#include "../card.h"
|
||||
|
||||
void pokerFlopInit(poker_t *poker);
|
@ -16,16 +16,16 @@ void pokerMatchInit(poker_t *poker) {
|
||||
poker->blindBig = POKER_BLIND_BIG_DEFAULT;
|
||||
poker->blindSmall = POKER_BLIND_SMALL_DEFAULT;
|
||||
poker->roundDealer = 0x00;
|
||||
poker->roundTextCounter = 0;
|
||||
poker->round = POKER_ROUND_MATCH;
|
||||
|
||||
for(x = 0; x < POKER_PLAYER_COUNT; x++) {
|
||||
poker->players[x].state = 0x00;
|
||||
poker->players[x].chips = POKER_PLAYER_CHIPS_DEFAULT;
|
||||
}
|
||||
|
||||
pokerTalk(poker, POKER_TALK_MATCH_START);
|
||||
printf("Match Start\n");
|
||||
pokerStartInit(poker);
|
||||
}
|
||||
|
||||
void pokerMatchUpdate(poker_t *poker) {
|
||||
if(pokerTalkIsTalking(poker)) return;
|
||||
pokerDealInit(poker);
|
||||
}
|
@ -7,7 +7,7 @@
|
||||
|
||||
#pragma once
|
||||
#include <dawn/dawn.h>
|
||||
#include "deal.h"
|
||||
#include "start.h"
|
||||
#include "../render/look.h"
|
||||
#include "../render/talk.h"
|
||||
|
||||
|
67
src/poker/round/start.c
Normal file
67
src/poker/round/start.c
Normal file
@ -0,0 +1,67 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "start.h"
|
||||
|
||||
void pokerStartInit(poker_t *poker) {
|
||||
uint8_t i, indexDealer, indexSmallBlind, indexBigBlind;
|
||||
bool foundDealer, foundSmallBlind;
|
||||
pokerplayer_t *player;
|
||||
|
||||
poker->round = POKER_ROUND_START;
|
||||
|
||||
// Prepare the initial game state
|
||||
poker->round = POKER_ROUND_DEAL;
|
||||
poker->pot = 0;
|
||||
poker->graveSize = 0;
|
||||
poker->cardsFacing = 0;
|
||||
poker->deckSize = CARD_DECK_SIZE;
|
||||
for(i = 0; i < CARD_DECK_SIZE; i++) poker->deck[i] = i;
|
||||
|
||||
// Reset the players
|
||||
for(i = 0; i < POKER_PLAYER_COUNT; i++) {
|
||||
poker->players[i].cardCount = 0;
|
||||
poker->players[i].currentBet = 0;
|
||||
|
||||
// Invert then bitwise AND to turn off.
|
||||
poker->players[i].state &= ~(
|
||||
POKER_PLAYER_STATE_FOLDED |
|
||||
POKER_PLAYER_STATE_SHOWING
|
||||
);
|
||||
}
|
||||
|
||||
// Decide on the dealer
|
||||
poker->roundDealer++;
|
||||
|
||||
// Find the players.
|
||||
i = poker->roundDealer;
|
||||
foundDealer = false;
|
||||
foundSmallBlind = false;
|
||||
while(true) {
|
||||
player = poker->players + i;
|
||||
if(player->state & POKER_PLAYER_STATE_FOLDED) continue;
|
||||
if(player->state & POKER_PLAYER_STATE_OUT) continue;
|
||||
if(!foundDealer) {
|
||||
indexDealer = i;
|
||||
foundDealer = true;
|
||||
} else if(!foundSmallBlind) {
|
||||
indexSmallBlind = i;
|
||||
foundSmallBlind = true;
|
||||
} else {
|
||||
indexBigBlind = i;
|
||||
break;
|
||||
}
|
||||
i = (i + 1) % POKER_PLAYER_COUNT;
|
||||
}
|
||||
|
||||
// Update players for the round.
|
||||
poker->roundBigBlind = indexBigBlind;
|
||||
poker->roundSmallBlind = indexSmallBlind;
|
||||
|
||||
printf("Round Start\n");
|
||||
pokerBlindsInit(poker);
|
||||
}
|
12
src/poker/round/start.h
Normal file
12
src/poker/round/start.h
Normal file
@ -0,0 +1,12 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <dawn/dawn.h>
|
||||
#include "blinds.h"
|
||||
|
||||
void pokerStartInit(poker_t *poker);
|
14
src/poker/round/winner.c
Normal file
14
src/poker/round/winner.c
Normal file
@ -0,0 +1,14 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "winner.h"
|
||||
|
||||
void pokerWinnerInit(poker_t *poker) {
|
||||
poker->round = POKER_ROUND_WINNER;
|
||||
printf("Winner Winner Chicken Dinner\n");
|
||||
}
|
11
src/poker/round/winner.h
Normal file
11
src/poker/round/winner.h
Normal file
@ -0,0 +1,11 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <dawn/dawn.h>
|
||||
|
||||
void pokerWinnerInit(poker_t *poker);
|
Reference in New Issue
Block a user