Started merging new poker code in.

This commit is contained in:
2021-10-09 15:43:26 -07:00
parent aff317b904
commit 131c59fbf6
41 changed files with 1380 additions and 1083 deletions

View File

@ -0,0 +1,31 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "blinds.h"
void _pokerActionBlindsOnStart(queue_t *queue,queueaction_t *action,uint8_t i) {
poker_t *poker;
poker = (poker_t *)action->data;
poker->state = POKER_STATE_TAKING_BLINDS;
pokerBetTakeBlinds(
&poker->bet,
poker->players,
poker->roundSmallBlind,
poker->roundBigBlind
);
printf("Taken Blinds\n");
queueNext(queue);
}
queueaction_t * pokerActionBlindsAdd(queue_t *queue, poker_t *poker) {
queueaction_t *action;
action = queueAdd(queue);
action->data = (void *)poker;
action->onStart = &_pokerActionBlindsOnStart;
return action;
}

View File

@ -0,0 +1,24 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "../bet.h"
#include "../poker.h"
#include "../../libs.h"
#include "../../display/animation/queue.h"
/** Callback for the blinds action */
void _pokerActionBlindsOnStart(queue_t *queue,queueaction_t *action,uint8_t i);
/**
* Adds a blinds action onto the specified queue.
*
* @param queue Queue to add to.
* @param poker Poker game instance to deal.
* @return The queued action.
*/
queueaction_t * pokerActionBlindsAdd(queue_t *queue, poker_t *poker);

View File

@ -0,0 +1,30 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "deal.h"
void _pokerActionDealOnStart(queue_t *queue, queueaction_t *action, uint8_t i) {
poker_t *poker;
poker = (poker_t *)action->data;
// Shuffle the deck
poker->state = POKER_STATE_DEALING;
cardShuffle(poker->dealer.deck, CARD_DECK_SIZE);
// Deal 2 card to each player
pokerDealerDealAll(&poker->dealer, poker->players, POKER_DEAL_CARD_EACH);
queueNext(queue);
}
queueaction_t * pokerActionDealAdd(queue_t *queue, poker_t *poker) {
queueaction_t *action;
action = queueAdd(queue);
action->data = (void *)poker;
action->onStart = &_pokerActionDealOnStart;
return action;
}

View File

@ -0,0 +1,24 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "../../libs.h"
#include "../../display/animation/queue.h"
#include "../dealer.h"
#include "../poker.h"
/** Callback for the deal action */
void _pokerActionDealOnStart(queue_t *queue, queueaction_t *action, uint8_t i);
/**
* Adds a deal action onto the specified queue.
*
* @param queue Queue to add to.
* @param poker Poker game instance to deal.
* @return The queued action.
*/
queueaction_t * pokerActionDealAdd(queue_t *queue, poker_t *poker);

View File

@ -0,0 +1,73 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "flop.h"
void _pokerActionFlopDo(queue_t *queue, queueaction_t *action, uint8_t count) {
poker_t *poker;
poker = (poker_t *)action->data;
poker->state = POKER_STATE_CARDS_FLOPPING;
pokerDealerBurn(&poker->dealer, POKER_FLOP_BURN_COUNT);
pokerDealerTurn(&poker->dealer, count);
printf("Turned %u cards\n", count);
queueNext(queue);
}
void _pokerActionFlopOnStart(queue_t *queue, queueaction_t *action, uint8_t i) {
_pokerActionFlopDo(queue, action, POKER_FLOP_CARD_COUNT);
}
void _pokerActionTurnOnStart(queue_t *queue, queueaction_t *action, uint8_t i) {
_pokerActionFlopDo(queue, action, POKER_TURN_CARD_COUNT);
}
void _pokerActionRiverOnStart(queue_t *queue, queueaction_t *action, uint8_t i) {
_pokerActionFlopDo(queue, action, POKER_RIVER_CARD_COUNT);
}
queueaction_t * pokerActionFlopAdd(queue_t *queue, poker_t *poker) {
queueaction_t *action;
action = queueAdd(queue);
action->data = (void *)poker;
action->onStart = &_pokerActionFlopOnStart;
return action;
}
queueaction_t * pokerActionTurnAdd(queue_t *queue, poker_t *poker) {
queueaction_t *action;
action = queueAdd(queue);
action->data = (void *)poker;
action->onStart = &_pokerActionTurnOnStart;
return action;
}
queueaction_t * pokerActionRiverAdd(queue_t *queue, poker_t *poker) {
queueaction_t *action;
action = queueAdd(queue);
action->data = (void *)poker;
action->onStart = &_pokerActionRiverOnStart;
return action;
}
queueaction_t * pokerActionNextFlopAdd(queue_t *queue, poker_t *poker) {
switch(poker->dealer.cardsFacing) {
case 0:
return pokerActionFlopAdd(queue, poker);
case POKER_FLOP_CARD_COUNT:
return pokerActionTurnAdd(queue, poker);
case POKER_FLOP_CARD_COUNT+POKER_TURN_CARD_COUNT:
return pokerActionRiverAdd(queue, poker);
default:
return NULL;
}
}

View File

@ -0,0 +1,68 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "../../libs.h"
#include "../../display/animation/queue.h"
#include "../dealer.h"
#include "../poker.h"
#include "../turn.h"
/** How many cards the dealer should burn before dealing the flop */
#define POKER_FLOP_BURN_COUNT 1
/**
* Shorthand action callback parser. Takes the queue, action and the intended
* turn count to complete the action.
*
* @param queue Queue that fired the action.
* @param action Action that was fired.
* @param count Count of cards to turn over from the deck.
*/
void _pokerActionFlopDo(queue_t *queue, queueaction_t *action, uint8_t count);
/** Callbacks for River, Turn and Flop Actions */
void _pokerActionFlopOnStart(queue_t *queue, queueaction_t *action, uint8_t i);
void _pokerActionTurnOnStart(queue_t *queue, queueaction_t *action, uint8_t i);
void _pokerActionRiverOnStart(queue_t *queue, queueaction_t *action, uint8_t i);
/**
* Queues a flop action onto the queue.
*
* @param queue Queue to add to.
* @param poker Poker game instance to flop.
* @return The queued action.
*/
queueaction_t * pokerActionFlopAdd(queue_t *queue, poker_t *poker);
/**
* Queues a turn action onto the queue.
*
* @param queue Queue to add to.
* @param poker Poker game instance to turn.
* @return The queued action.
*/
queueaction_t * pokerActionTurnAdd(queue_t *queue, poker_t *poker);
/**
* Queues a river action onto the queue.
*
* @param queue Queue to add to.
* @param poker Poker game instance to river.
* @return The queued action.
*/
queueaction_t * pokerActionRiverAdd(queue_t *queue, poker_t *poker);
/**
* Queues the next type of flop action onto the queue. This will automatically
* select River, Flop or Turn depending on what's happened already.
*
* @param queue Queue to add to.
* @param poker Poker game instance
* @return The queued action.
*/
queueaction_t * pokerActionNextFlopAdd(queue_t *queue, poker_t *poker);

View File

@ -0,0 +1,36 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "match.h"
void _pokerActionMatchOnStart(queue_t *queue, queueaction_t *action, uint8_t i){
poker_t *poker;
uint8_t x;
poker = (poker_t *)action->data;
poker->state = POKER_STATE_STARTING_MATCH;
// Reset the main game state. This does not init the round.
pokerBetInit(&poker->bet);
poker->roundDealer = POKER_PLAYER_COUNT-2;
// Reset the players
for(x = 0; x < POKER_PLAYER_COUNT; x++) {
poker->players[x].state = 0x00;
poker->players[x].chips = POKER_BET_PLAYER_CHIPS_DEFAULT;
}
queueNext(queue);
}
queueaction_t * pokerActionMatchAdd(queue_t *queue, poker_t *poker) {
queueaction_t *action;
action = queueAdd(queue);
action->data = (void *)poker;
action->onStart = &_pokerActionMatchOnStart;
return action;
}

View File

@ -0,0 +1,22 @@
// Copyright (c) 2021 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "../../libs.h"
#include "../../display/animation/queue.h"
#include "../bet.h"
#include "../poker.h"
/** Callback for when the poker match aciton starts */
void _pokerActionMatchOnStart(queue_t *queue, queueaction_t *action, uint8_t i);
/**
* Adds a Poker Match Begin Action onto a queue.
*
* @param queue Queue to add to
* @param poker Poker game instance to use.
* @return The queued match start action.
*/
queueaction_t * pokerActionMatchAdd(queue_t *queue, poker_t *poker);

View File

@ -0,0 +1,68 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "round.h"
void _pokerActionRoundOnStart(queue_t *queue, queueaction_t *action ,uint8_t i){
uint8_t j, indexDealer, indexSmallBlind, indexBigBlind;
bool foundDealer, foundSmallBlind;
pokerplayer_t *player;
poker_t *poker;
poker = (poker_t *)action->data;
// Update game state.
poker->state = POKER_STATE_STARTING_ROUND;
// Prepare the initial game state
pokerBetReset(&poker->bet);
pokerDealerInit(&poker->dealer);
// Reset the players
for(i = 0; i < POKER_PLAYER_COUNT; i++) {
pokerPlayerReset(poker->players + i);
}
// Decide on the dealer
poker->roundDealer = (poker->roundDealer+1) % POKER_PLAYER_COUNT;
// Find (and kill) the players.
j = poker->roundDealer;
foundDealer = false;
foundSmallBlind = false;
while(true) {
player = poker->players + j;
if(!pokerPlayerIsInRound(player)) continue;
if(!foundDealer) {
indexDealer = j;
foundDealer = true;
} else if(!foundSmallBlind) {
indexSmallBlind = j;
foundSmallBlind = true;
} else {
indexBigBlind = j;
break;
}
j = (j + 1) % POKER_PLAYER_COUNT;
}
// Update players for the round.
poker->roundDealer = indexDealer;
poker->roundBigBlind = indexBigBlind;
poker->roundSmallBlind = indexSmallBlind;
queueNext(queue);
}
queueaction_t * pokerActionRoundAdd(queue_t *queue, poker_t *poker) {
queueaction_t *action;
action = queueAdd(queue);
action->data = (void *)poker;
action->onStart = &_pokerActionRoundOnStart;
return action;
}

View File

@ -0,0 +1,27 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "../../libs.h"
#include "../../display/animation/queue.h"
#include "../dealer.h"
#include "../bet.h"
#include "../player.h"
#include "../poker.h"
/** Callback for when the poker round start aciton begins. */
void _pokerActionRoundOnStart(queue_t *queue, queueaction_t *action, uint8_t i);
/**
* Queues the round action onto a queue. Round action should be queued at the
* start of every poker round.
*
* @param queue Queue to add to.
* @param poker Poker game instance.
* @return The queued action.
*/
queueaction_t * pokerActionRoundAdd(queue_t *queue, poker_t *poker);