Did a lot of work on the engine
This commit is contained in:
@ -19,7 +19,7 @@ void holdemActionInit() {
|
||||
);
|
||||
}
|
||||
|
||||
void holdemActionAdd(holdemaction_t action) {
|
||||
int32_t holdemActionAdd(holdemaction_t action) {
|
||||
int32_t i = -1;
|
||||
int32_t j = -1;
|
||||
|
||||
@ -28,16 +28,46 @@ void holdemActionAdd(holdemaction_t action) {
|
||||
j = i;
|
||||
break;
|
||||
}
|
||||
if(j == -1) return j;
|
||||
|
||||
HOLDEM_GAME_STATE.actionQueue[j] = action;
|
||||
action.init(j, HOLDEM_GAME_STATE.actionData + j);
|
||||
HOLDEM_GAME_STATE.actionInitState[j] = false;
|
||||
return j;
|
||||
}
|
||||
|
||||
void holdemActionRemove(int32_t index) {
|
||||
if(HOLDEM_GAME_STATE.actionQueue[index].dispose != NULL) {
|
||||
HOLDEM_GAME_STATE.actionQueue[index].dispose(
|
||||
index, HOLDEM_GAME_STATE.actionData + index
|
||||
);
|
||||
}
|
||||
|
||||
memset(HOLDEM_GAME_STATE.actionQueue+index, (int32_t)NULL,
|
||||
sizeof(holdemaction_t)
|
||||
);
|
||||
|
||||
memset(HOLDEM_GAME_STATE.actionData+index, (int32_t)NULL,
|
||||
sizeof(void *) * HOLDEM_GAME_ACTION_DATA_SIZE
|
||||
);
|
||||
}
|
||||
|
||||
void holdemActionUpdate() {
|
||||
int32_t i;
|
||||
void **data;
|
||||
holdemaction_t *action;
|
||||
|
||||
for(i = 0; i < HOLDEM_GAME_ACTION_QUEUE_SIZE; i++) {
|
||||
if(HOLDEM_GAME_STATE.actionQueue[i].update == NULL) continue;
|
||||
HOLDEM_GAME_STATE.actionQueue[i].update(i, HOLDEM_GAME_STATE.actionData+i);
|
||||
action = HOLDEM_GAME_STATE.actionQueue + i;
|
||||
data = HOLDEM_GAME_STATE.actionData + i;
|
||||
|
||||
if(action->init != NULL && !HOLDEM_GAME_STATE.actionInitState[i]) {
|
||||
HOLDEM_GAME_STATE.actionInitState[i] = true;
|
||||
action->init(i, data);
|
||||
}
|
||||
|
||||
if(action->update != NULL) {
|
||||
action->update(i, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,8 +17,16 @@ void holdemActionInit();
|
||||
* Adds an action to the action queue.
|
||||
*
|
||||
* @param action Action to add to the queue.
|
||||
* @returns The index of the action within the queue, or -1 if failure occured.
|
||||
*/
|
||||
void holdemActionAdd(holdemaction_t action);
|
||||
int32_t holdemActionAdd(holdemaction_t action);
|
||||
|
||||
/**
|
||||
* Removes an action from the action queue.
|
||||
*
|
||||
* @param index Action to remove (by index in the queue).
|
||||
*/
|
||||
void holdemActionRemove(int32_t index);
|
||||
|
||||
/**
|
||||
* Updates the action manager, which (in turn) updates all actions that are
|
||||
|
30
src/card/poker/action/ai.c
Normal file
30
src/card/poker/action/ai.c
Normal file
@ -0,0 +1,30 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "ai.h"
|
||||
|
||||
holdemaction_t actionAi() {
|
||||
return (holdemaction_t){
|
||||
.init = &actionAiInit,
|
||||
.update = &actionAiUpdate,
|
||||
.dispose = &actionAiDispose
|
||||
};
|
||||
}
|
||||
|
||||
void actionAiInit(int32_t index, void *data) {
|
||||
holdemActionRemove(index);
|
||||
}
|
||||
|
||||
void actionAiUpdate(int32_t index, void *data) {
|
||||
}
|
||||
|
||||
void actionAiDispose(int32_t index, void *data) {
|
||||
// Do we need to do a flop?
|
||||
if(HOLDEM_GAME_STATE.match.cardsFacing < HOLDEM_DEALER_HAND) {
|
||||
holdemActionAdd(actionFlop());
|
||||
}
|
||||
}
|
17
src/card/poker/action/ai.h
Normal file
17
src/card/poker/action/ai.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
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <dawn/dawn.h>
|
||||
#include "action.h"
|
||||
#include "flop.h"
|
||||
|
||||
holdemaction_t actionAi();
|
||||
|
||||
void actionAiInit(int32_t index, void *data);
|
||||
void actionAiUpdate(int32_t index, void *data);
|
||||
void actionAiDispose(int32_t index, void *data);
|
30
src/card/poker/action/deal.c
Normal file
30
src/card/poker/action/deal.c
Normal 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"
|
||||
|
||||
holdemaction_t actionDeal() {
|
||||
return (holdemaction_t){
|
||||
.init = &actionDealInit,
|
||||
.update = &actionDealUpdate,
|
||||
.dispose = &actionDealDispose
|
||||
};
|
||||
}
|
||||
|
||||
void actionDealInit(int32_t i, void *data) {
|
||||
logText("Dealing Cards");
|
||||
holdemDealAll(&HOLDEM_GAME_STATE.match, HOLDEM_PLAYER_HAND);
|
||||
holdemActionRemove(i);
|
||||
}
|
||||
|
||||
void actionDealUpdate(int32_t i, void *data) {
|
||||
|
||||
}
|
||||
|
||||
void actionDealDispose(int32_t i, void *data) {
|
||||
holdemActionAdd()
|
||||
}
|
17
src/card/poker/action/deal.h
Normal file
17
src/card/poker/action/deal.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
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <dawn/dawn.h>
|
||||
#include "../../../debug/log.h"
|
||||
#include "action.h"
|
||||
|
||||
holdemaction_t actionDeal();
|
||||
|
||||
void actionDealInit(int32_t i, void *data);
|
||||
void actionDealUpdate(int32_t i, void *data);
|
||||
void actionDealDispose(int32_t i, void *data);
|
35
src/card/poker/action/flop.c
Normal file
35
src/card/poker/action/flop.c
Normal file
@ -0,0 +1,35 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "flop.h"
|
||||
|
||||
holdemaction_t actionFlop() {
|
||||
return (holdemaction_t){
|
||||
.init = &actionFlopInit,
|
||||
.update = &actionFlopUpdate,
|
||||
.dispose = &actionFlopDispose
|
||||
};
|
||||
}
|
||||
|
||||
void actionFlopInit(int32_t index, void *data) {
|
||||
// Look at the dealer
|
||||
holdemRenderLookHand(&HOLDEM_GAME_STATE.cameraLeft, HOLDEM_GAME_SEAT_DEALER);
|
||||
|
||||
// Do the flop
|
||||
holdemFlop(&HOLDEM_GAME_STATE.match);
|
||||
|
||||
// Next action
|
||||
holdemActionRemove(index);
|
||||
}
|
||||
|
||||
void actionFlopUpdate(int32_t index, void *data) {
|
||||
|
||||
}
|
||||
|
||||
void actionFlopDispose(int32_t index, void *data) {
|
||||
holdemActionAdd(actionAi());
|
||||
}
|
19
src/card/poker/action/flop.h
Normal file
19
src/card/poker/action/flop.h
Normal file
@ -0,0 +1,19 @@
|
||||
/**
|
||||
* 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 "action.h"
|
||||
#include "../holdem.h"
|
||||
#include "../render/look.h"
|
||||
#include "ai.h"
|
||||
|
||||
holdemaction_t actionFlop();
|
||||
|
||||
void actionFlopInit(int32_t index, void *data);
|
||||
void actionFlopUpdate(int32_t index, void *data);
|
||||
void actionFlopDispose(int32_t index, void *data);
|
64
src/card/poker/action/round.c
Normal file
64
src/card/poker/action/round.c
Normal file
@ -0,0 +1,64 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "round.h"
|
||||
|
||||
holdemaction_t actionRound() {
|
||||
return (holdemaction_t){
|
||||
.init = &actionRoundInit,
|
||||
.update = &actionRoundUpdate,
|
||||
.dispose = &actionRoundDispose
|
||||
};
|
||||
}
|
||||
|
||||
void actionRoundInit(int32_t index, void *data) {
|
||||
uint8_t i;
|
||||
holdemplayer_t *player;
|
||||
holdemmatch_t *match = &HOLDEM_GAME_STATE.match;
|
||||
|
||||
logText("Round Start");
|
||||
|
||||
// Look at the dealer.
|
||||
holdemRenderLookHand(&HOLDEM_GAME_STATE.cameraLeft, HOLDEM_GAME_SEAT_DEALER);
|
||||
|
||||
// Init the round and shuffle the deck
|
||||
cardDeckFill(match->deck);
|
||||
match->deckSize = CARD_DECK_SIZE;
|
||||
match->pot = 0;
|
||||
match->cardsFacing = 0;
|
||||
|
||||
// Reset the players
|
||||
for(i = 0; i < HOLDEM_PLAYER_COUNT; i++) {
|
||||
player = match->players + i;
|
||||
|
||||
// Clear Round State(s)
|
||||
player->state &= ~(
|
||||
HOLDEM_STATE_FOLDED |
|
||||
HOLDEM_STATE_SHOWING
|
||||
);
|
||||
|
||||
player->cardCount = 0;
|
||||
player->currentBet = 0;
|
||||
}
|
||||
|
||||
// Next action
|
||||
holdemActionRemove(index);
|
||||
}
|
||||
|
||||
void actionRoundUpdate(int32_t index, void *data) {
|
||||
}
|
||||
|
||||
void actionRoundAfterShuffle() {
|
||||
logText("Shuffle Done");
|
||||
int32_t i = holdemActionAdd(actionDeal());
|
||||
}
|
||||
|
||||
void actionRoundDispose(int32_t index, void *data) {
|
||||
int32_t newI = holdemActionAdd(actionShuffle());
|
||||
shuffledata_t *newData=(shuffledata_t *)(HOLDEM_GAME_STATE.actionData + newI);
|
||||
newData->done = &actionRoundAfterShuffle;
|
||||
}
|
24
src/card/poker/action/round.h
Normal file
24
src/card/poker/action/round.h
Normal 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 <dawn/dawn.h>
|
||||
#include "../render/holdemrender.h"
|
||||
#include "../../../debug/log.h"
|
||||
#include "../holdem.h"
|
||||
#include "action.h"
|
||||
#include "ai.h"
|
||||
#include "shuffle.h"
|
||||
#include "deal.h"
|
||||
|
||||
holdemaction_t actionRound();
|
||||
|
||||
void actionRoundInit(int32_t index, void *data);
|
||||
void actionRoundUpdate(int32_t index, void *data);
|
||||
void actionRoundDispose(int32_t index, void *data);
|
||||
|
||||
void actionRoundAfterShuffle();
|
30
src/card/poker/action/shuffle.c
Normal file
30
src/card/poker/action/shuffle.c
Normal file
@ -0,0 +1,30 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "shuffle.h"
|
||||
|
||||
holdemaction_t actionShuffle() {
|
||||
return (holdemaction_t){
|
||||
.init = &actionShuffleInit,
|
||||
.update = &actionShuffleUpdate,
|
||||
.dispose = &actionShuffleDispose
|
||||
};
|
||||
}
|
||||
|
||||
void actionShuffleInit(int32_t index, void *data) {
|
||||
logText("Shuffle Deck");
|
||||
cardShuffle(HOLDEM_GAME_STATE.match.deck, HOLDEM_GAME_STATE.match.deckSize);
|
||||
holdemActionRemove(index);
|
||||
}
|
||||
|
||||
void actionShuffleUpdate(int32_t index, void *data) {
|
||||
|
||||
}
|
||||
|
||||
void actionShuffleDispose(int32_t index, void *data) {
|
||||
if(((shuffledata_t *)data) != NULL) ((shuffledata_t *)data)->done();
|
||||
}
|
23
src/card/poker/action/shuffle.h
Normal file
23
src/card/poker/action/shuffle.h
Normal file
@ -0,0 +1,23 @@
|
||||
/**
|
||||
* 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 "action.h"
|
||||
#include "../../../debug/log.h"
|
||||
|
||||
typedef struct {
|
||||
void (*done)();
|
||||
} shuffledata_t;
|
||||
|
||||
holdemaction_t actionShuffle();
|
||||
|
||||
void actionShuffleInit(int32_t index, void *data);
|
||||
|
||||
void actionShuffleUpdate(int32_t index, void *data);
|
||||
|
||||
void actionShuffleDispose(int32_t index, void *data);
|
@ -18,18 +18,30 @@ holdemaction_t actionStart() {
|
||||
}
|
||||
|
||||
void actionStartInit(int32_t index, void *data) {
|
||||
// holdemactionstart_t *convData = data;
|
||||
uint8_t i;
|
||||
holdemplayer_t *player;
|
||||
holdemmatch_t *match;
|
||||
logText("Holdem Starting");
|
||||
|
||||
// Prepare the match
|
||||
holdemMatchInit(&HOLDEM_GAME_STATE.match);
|
||||
holdemRoundInit(&HOLDEM_GAME_STATE.match);
|
||||
cardShuffle(HOLDEM_GAME_STATE.match.deck, HOLDEM_GAME_STATE.match.deckSize);
|
||||
holdemFlop(&HOLDEM_GAME_STATE.match);
|
||||
match = &HOLDEM_GAME_STATE.match;
|
||||
match->blindBig = 0;
|
||||
match->blindSmall = 0;
|
||||
|
||||
// Reset the players
|
||||
for(i = 0; i < HOLDEM_PLAYER_COUNT; i++) {
|
||||
player = match->players + i;
|
||||
player->state = 0x00;
|
||||
player->chips = 0;
|
||||
}
|
||||
|
||||
holdemActionRemove(index);
|
||||
}
|
||||
|
||||
void actionStartUpdate(int32_t index, void *data) {
|
||||
}
|
||||
|
||||
void actionStartDispose(int32_t index, void *data) {
|
||||
|
||||
// Begin the first round
|
||||
holdemActionAdd(actionRound());
|
||||
}
|
@ -7,6 +7,9 @@
|
||||
|
||||
#pragma once
|
||||
#include <dawn/dawn.h>
|
||||
#include "action.h"
|
||||
#include "round.h"
|
||||
#include "../../../debug/log.h"
|
||||
|
||||
holdemaction_t actionStart();
|
||||
|
||||
|
Reference in New Issue
Block a user