Joining the two logics together slowly.
This commit is contained in:
@ -4,11 +4,15 @@
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "match.h"
|
||||
|
||||
void pokerMatchInit(poker_t *poker, engine_t *engine) {
|
||||
void _pokerActionMatchOnStart(queue_t *queue, queueaction_t *action, uint8_t i){
|
||||
poker_t *poker;
|
||||
uint8_t x;
|
||||
|
||||
poker = (poker_t *)action->data;
|
||||
|
||||
// Reset the main game state. This does not init the round.
|
||||
pokerBetInit(&poker->bet);
|
||||
poker->roundDealer = POKER_PLAYER_COUNT-2;
|
||||
@ -19,8 +23,13 @@ void pokerMatchInit(poker_t *poker, engine_t *engine) {
|
||||
poker->players[x].chips = POKER_BET_PLAYER_CHIPS_DEFAULT;
|
||||
}
|
||||
printf("Match Start\n");
|
||||
pokerStartInit(poker);
|
||||
queueNext(queue);
|
||||
}
|
||||
|
||||
void pokerMatchUpdate(poker_t *poker, engine_t *engine) {
|
||||
queueaction_t * pokerActionMatchAdd(queue_t *queue, poker_t *poker) {
|
||||
queueaction_t *action;
|
||||
action = queueAdd(queue);
|
||||
action->data = (void *)poker;
|
||||
action->onStart = &_pokerActionMatchOnStart;
|
||||
return action;
|
||||
}
|
20
src/poker/actions/match.h
Normal file
20
src/poker/actions/match.h
Normal file
@ -0,0 +1,20 @@
|
||||
// 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 "../../display/animation/queue.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);
|
@ -5,12 +5,15 @@
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "start.h"
|
||||
#include "round.h"
|
||||
|
||||
void pokerStartInit(poker_t *poker) {
|
||||
uint8_t i, indexDealer, indexSmallBlind, indexBigBlind;
|
||||
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;
|
||||
|
||||
poker->round = POKER_ROUND_START;
|
||||
|
||||
@ -28,23 +31,23 @@ void pokerStartInit(poker_t *poker) {
|
||||
poker->roundDealer = (poker->roundDealer+1) % POKER_PLAYER_COUNT;
|
||||
|
||||
// Find the players.
|
||||
i = poker->roundDealer;
|
||||
j = poker->roundDealer;
|
||||
foundDealer = false;
|
||||
foundSmallBlind = false;
|
||||
while(true) {
|
||||
player = poker->players + i;
|
||||
player = poker->players + j;
|
||||
if(!pokerPlayerIsAlive(player)) continue;
|
||||
if(!foundDealer) {
|
||||
indexDealer = i;
|
||||
indexDealer = j;
|
||||
foundDealer = true;
|
||||
} else if(!foundSmallBlind) {
|
||||
indexSmallBlind = i;
|
||||
indexSmallBlind = j;
|
||||
foundSmallBlind = true;
|
||||
} else {
|
||||
indexBigBlind = i;
|
||||
indexBigBlind = j;
|
||||
break;
|
||||
}
|
||||
i = (i + 1) % POKER_PLAYER_COUNT;
|
||||
j = (j + 1) % POKER_PLAYER_COUNT;
|
||||
}
|
||||
|
||||
// Update players for the round.
|
||||
@ -53,5 +56,13 @@ void pokerStartInit(poker_t *poker) {
|
||||
poker->roundSmallBlind = indexSmallBlind;
|
||||
|
||||
printf("Round Start\n");
|
||||
pokerBlindsInit(poker);
|
||||
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;
|
||||
}
|
25
src/poker/actions/round.h
Normal file
25
src/poker/actions/round.h
Normal file
@ -0,0 +1,25 @@
|
||||
/**
|
||||
* 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 "../../display/animation/queue.h"
|
||||
#include "../bet.h"
|
||||
#include "../player.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);
|
@ -6,27 +6,3 @@
|
||||
*/
|
||||
|
||||
#include "poker.h"
|
||||
|
||||
void pokerInit(poker_t *poker) {
|
||||
|
||||
}
|
||||
|
||||
void pokerUpdate(poker_t *poker, engine_t *engine) {
|
||||
// Game Logic
|
||||
switch(poker->round) {
|
||||
case POKER_ROUND_MATCH:
|
||||
pokerMatchUpdate(poker, engine);
|
||||
break;
|
||||
case POKER_ROUND_BET0:
|
||||
case POKER_ROUND_BET1:
|
||||
case POKER_ROUND_BET2:
|
||||
case POKER_ROUND_BET3:
|
||||
pokerRoundBetUpdate(poker);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void pokerDispose(poker_t * poker) {
|
||||
}
|
@ -6,24 +6,4 @@
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <dawn/dawn.h>
|
||||
#include "round/match.h"
|
||||
|
||||
/**
|
||||
* Initializes the poker context for the first time.
|
||||
* @param poker Poker context to initialize.
|
||||
*/
|
||||
void pokerInit(poker_t *poker);
|
||||
|
||||
/**
|
||||
* Updates the poker context.
|
||||
* @param poker Poker game context.
|
||||
* @param engine Engine that is running the game.
|
||||
*/
|
||||
void pokerUpdate(poker_t *poker, engine_t *engine);
|
||||
|
||||
/**
|
||||
* Cleans an existing poker game instance.
|
||||
* @param poker Poker instance to cleanup
|
||||
*/
|
||||
void pokerDispose(poker_t *poker);
|
||||
#include <dawn/dawn.h>
|
@ -1,75 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "bet.h"
|
||||
|
||||
void pokerRoundBetPlayerNext(poker_t *poker) {
|
||||
// Go to next player, keep contained.
|
||||
poker->bet.better = (poker->bet.better + 1) % POKER_PLAYER_COUNT;
|
||||
|
||||
// Did we go full circle?
|
||||
if(poker->bet.better == poker->roundSmallBlind) {
|
||||
if(poker->round == POKER_ROUND_BET3) {
|
||||
pokerWinnerInit(poker);
|
||||
return;
|
||||
}
|
||||
|
||||
pokerFlopInit(poker);
|
||||
return;
|
||||
}
|
||||
|
||||
// Init the next player
|
||||
pokerRoundBetPlayerInit(poker, poker->players + poker->bet.better);
|
||||
}
|
||||
|
||||
|
||||
void pokerRoundBetPlayerInit(poker_t *poker, pokerplayer_t *player) {
|
||||
// Check the player state (to see if we even can init, e.g. folded/not)
|
||||
if(!pokerPlayerIsAlive(player)) {
|
||||
pokerRoundBetPlayerNext(poker);
|
||||
return;
|
||||
}
|
||||
|
||||
printf("Betting round player %u\n", poker->bet.better);
|
||||
if(pokerPlayerIsHuman(poker, player)) {
|
||||
pokerRoundBetPlayerNext(poker);
|
||||
return;
|
||||
}
|
||||
|
||||
pokerRoundBetPlayerNext(poker);
|
||||
}
|
||||
|
||||
void pokerRoundBetPlayerUpdate(poker_t *poker, pokerplayer_t *player) {
|
||||
|
||||
}
|
||||
|
||||
void pokerRoundBetInit(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->bet.better = poker->roundSmallBlind;
|
||||
pokerRoundBetPlayerInit(poker, poker->players + poker->bet.better);
|
||||
}
|
||||
|
||||
void pokerRoundBetUpdate(poker_t *poker) {
|
||||
// Take the current player
|
||||
pokerRoundBetPlayerUpdate(poker, poker->players + poker->bet.better);
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
/**
|
||||
* 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"
|
||||
#include "../player.h"
|
||||
|
||||
void pokerRoundBetPlayerNext(poker_t *poker);
|
||||
void pokerRoundBetPlayerInit(poker_t *poker, pokerplayer_t *player);
|
||||
void pokerRoundBetPlayerUpdate(poker_t *poker, pokerplayer_t *player);
|
||||
|
||||
void pokerRoundBetInit(poker_t *poker);
|
||||
void pokerRoundBetUpdate(poker_t *poker);
|
@ -1,19 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "blinds.h"
|
||||
|
||||
void pokerBlindsInit(poker_t *poker) {
|
||||
poker->round = POKER_ROUND_BLINDS;
|
||||
|
||||
// Now take blinds
|
||||
pokerBetTakeBlinds(poker);
|
||||
|
||||
printf("Blinds Taken\n");
|
||||
pokerDealInit(poker);
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include <dawn/dawn.h>
|
||||
#include "deal.h"
|
||||
#include "../bet.h"
|
||||
|
||||
/**
|
||||
* Initializes the blinds round.
|
||||
* @param poker The poker game conetxt.
|
||||
*/
|
||||
void pokerBlindsInit(poker_t *poker);
|
@ -1,23 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
#include "deal.h"
|
||||
|
||||
void pokerDealInit(poker_t *poker) {
|
||||
poker->round = POKER_ROUND_DEAL;
|
||||
|
||||
// Shuffle the deck
|
||||
cardShuffle(poker->dealer.deck, CARD_DECK_SIZE);
|
||||
|
||||
// Deal 2 card to each player
|
||||
pokerDealerDealAll(poker, POKER_DEAL_CARD_EACH);
|
||||
|
||||
// Deal 2 card to each player
|
||||
pokerDealerDealAll(poker, POKER_DEAL_CARD_EACH);
|
||||
|
||||
printf("Cards Dealt\n");
|
||||
pokerRoundBetInit(poker);
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
/**
|
||||
* 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 "../../util/array.h"
|
||||
#include "../dealer.h"
|
||||
#include "../card.h"
|
||||
#include "bet.h"
|
||||
|
||||
/**
|
||||
* Resets a poker game for the new round.
|
||||
* @param poker Poker game to reset to a new round.
|
||||
*/
|
||||
void pokerDealInit(poker_t *poker);
|
@ -1,32 +0,0 @@
|
||||
/**
|
||||
* 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;
|
||||
|
||||
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 and flop.
|
||||
pokerDealerBurn(&poker->dealer, 1);
|
||||
pokerDealerTurn(&poker->dealer, count);
|
||||
|
||||
pokerRoundBetInit(poker);
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
/**
|
||||
* 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 "../dealer.h"
|
||||
#include "../card.h"
|
||||
#include "bet.h"
|
||||
|
||||
void pokerFlopInit(poker_t *poker);
|
@ -1,23 +0,0 @@
|
||||
/**
|
||||
* 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 "start.h"
|
||||
|
||||
/**
|
||||
* Init the poker match round.
|
||||
* @param poker The poker game context.
|
||||
* @param engine The engine context.
|
||||
*/
|
||||
void pokerMatchInit(poker_t *poker, engine_t *engine);
|
||||
|
||||
/**
|
||||
* Update the poker match round.
|
||||
* @param poker The poker match to update for.
|
||||
*/
|
||||
void pokerMatchUpdate(poker_t *poker, engine_t *engine);
|
@ -1,14 +0,0 @@
|
||||
/**
|
||||
* 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"
|
||||
#include "../bet.h"
|
||||
#include "../player.h"
|
||||
|
||||
void pokerStartInit(poker_t *poker);
|
@ -1,12 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
#include "winner.h"
|
||||
|
||||
void pokerWinnerInit(poker_t *poker) {
|
||||
pokerWinnerCalculate(poker);
|
||||
printf("Winner Count %u\n", poker->winner.winnerCount);
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
/**
|
||||
* 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 "../player.h"
|
||||
#include "../winner.h"
|
||||
|
||||
void pokerWinnerInit(poker_t *poker);
|
Reference in New Issue
Block a user