Refactoring structs Part 1
This commit is contained in:
80
temp/action/action.c
Normal file
80
temp/action/action.c
Normal file
@ -0,0 +1,80 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "action.h"
|
||||
|
||||
void pokerActionInit() {
|
||||
// Free up all actions
|
||||
memset(GAME_STATE.actionQueue, (int32_t)NULL,
|
||||
sizeof(pokeraction_t) * POKER_ACTION_QUEUE_SIZE
|
||||
);
|
||||
|
||||
// Free up all data
|
||||
memset(GAME_STATE.actionData, (int32_t)NULL, sizeof(void *) *
|
||||
POKER_ACTION_DATA_SIZE * POKER_ACTION_QUEUE_SIZE
|
||||
);
|
||||
}
|
||||
|
||||
int32_t pokerActionAdd(pokeraction_t action) {
|
||||
int32_t i = -1;
|
||||
int32_t j = -1;
|
||||
|
||||
for(i = 0; i < POKER_ACTION_QUEUE_SIZE; i++) {
|
||||
if(GAME_STATE.actionQueue[i].init != NULL) continue;
|
||||
j = i;
|
||||
break;
|
||||
}
|
||||
if(j == -1) return j;
|
||||
|
||||
GAME_STATE.actionQueue[j] = action;
|
||||
GAME_STATE.actionInitState[j] = false;
|
||||
return j;
|
||||
}
|
||||
|
||||
void pokerActionRemove(int32_t index) {
|
||||
if(GAME_STATE.actionQueue[index].dispose != NULL) {
|
||||
GAME_STATE.actionQueue[index].dispose(
|
||||
index, GAME_STATE.actionData + index
|
||||
);
|
||||
}
|
||||
|
||||
memset(GAME_STATE.actionQueue+index, (int32_t)NULL,
|
||||
sizeof(pokeraction_t)
|
||||
);
|
||||
|
||||
memset(GAME_STATE.actionData+index, (int32_t)NULL,
|
||||
sizeof(void *) * POKER_ACTION_DATA_SIZE
|
||||
);
|
||||
}
|
||||
|
||||
void pokerActionUpdate() {
|
||||
int32_t i;
|
||||
void **data;
|
||||
pokeraction_t *action;
|
||||
|
||||
for(i = 0; i < POKER_ACTION_QUEUE_SIZE; i++) {
|
||||
action = GAME_STATE.actionQueue + i;
|
||||
data = GAME_STATE.actionData + i;
|
||||
|
||||
if(action->init != NULL && !GAME_STATE.actionInitState[i]) {
|
||||
GAME_STATE.actionInitState[i] = true;
|
||||
action->init(i, data);
|
||||
}
|
||||
|
||||
if(action->update != NULL) {
|
||||
action->update(i, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void pokerActionDispose() {
|
||||
int32_t i;
|
||||
for(i = 0; i < POKER_ACTION_QUEUE_SIZE; i++) {
|
||||
if(GAME_STATE.actionQueue[i].dispose == NULL) continue;
|
||||
GAME_STATE.actionQueue[i].dispose(i, GAME_STATE.actionData+i);
|
||||
}
|
||||
}
|
40
temp/action/action.h
Normal file
40
temp/action/action.h
Normal file
@ -0,0 +1,40 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <dawn/dawn.h>
|
||||
|
||||
/**
|
||||
* Initializes the action manager.
|
||||
*/
|
||||
void pokerActionInit();
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
int32_t pokerActionAdd(pokeraction_t action);
|
||||
|
||||
/**
|
||||
* Removes an action from the action queue.
|
||||
*
|
||||
* @param index Action to remove (by index in the queue).
|
||||
*/
|
||||
void pokerActionRemove(int32_t index);
|
||||
|
||||
/**
|
||||
* Updates the action manager, which (in turn) updates all actions that are
|
||||
* currently running.
|
||||
*/
|
||||
void pokerActionUpdate();
|
||||
|
||||
/**
|
||||
* Cleans up the action manager and all actions.
|
||||
*/
|
||||
void pokerActionDispose();
|
39
temp/action/ai.c
Normal file
39
temp/action/ai.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 "ai.h"
|
||||
|
||||
pokeraction_t actionAi() {
|
||||
return (pokeraction_t){
|
||||
.init = &actionAiInit,
|
||||
.update = &actionAiUpdate,
|
||||
.dispose = &actionAiDispose
|
||||
};
|
||||
}
|
||||
|
||||
void actionAiInit(int32_t index, void *data) {
|
||||
logText("AI Round start");
|
||||
|
||||
/*
|
||||
Current theory for the AI code will be;
|
||||
1 - Determine weight of my cards+flop as %
|
||||
2 - Determine current bet, compare against [something] and then determine if
|
||||
worth the risk. I may need history of the game to make informed decision
|
||||
*/
|
||||
|
||||
pokerActionRemove(index);
|
||||
}
|
||||
|
||||
void actionAiUpdate(int32_t index, void *data) {
|
||||
}
|
||||
|
||||
void actionAiDispose(int32_t index, void *data) {
|
||||
// Do we need to do a flop?
|
||||
if(GAME_STATE.cardsFacing < POKER_DEALER_HAND) {
|
||||
pokerActionAdd(actionFlop());
|
||||
}
|
||||
}
|
22
temp/action/ai.h
Normal file
22
temp/action/ai.h
Normal 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 <dawn/dawn.h>
|
||||
#include "action.h"
|
||||
#include "flop.h"
|
||||
#include "../../debug/log.h"
|
||||
|
||||
typdef struct {
|
||||
uint8_t player;
|
||||
} actionaidata_t;
|
||||
|
||||
pokeraction_t actionAi();
|
||||
|
||||
void actionAiInit(int32_t index, void *data);
|
||||
void actionAiUpdate(int32_t index, void *data);
|
||||
void actionAiDispose(int32_t index, void *data);
|
45
temp/action/deal.c
Normal file
45
temp/action/deal.c
Normal file
@ -0,0 +1,45 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "deal.h"
|
||||
|
||||
pokeraction_t actionDeal() {
|
||||
return (pokeraction_t){
|
||||
.init = &actionDealInit,
|
||||
.update = &actionDealUpdate,
|
||||
.dispose = &actionDealDispose
|
||||
};
|
||||
}
|
||||
|
||||
void actionDealInit(int32_t index, void *data) {
|
||||
uint8_t i, j;
|
||||
pokerplayer_t *player;
|
||||
logText("Dealing Cards");
|
||||
|
||||
for(i = 0; i < 2; i++) {
|
||||
for(j = 0; j < POKER_PLAYER_COUNT; j++) {
|
||||
player = GAME_STATE.players + j;
|
||||
cardDeal(GAME_STATE.deck,
|
||||
player->cards,
|
||||
GAME_STATE.deckSize,
|
||||
player->cardCount
|
||||
);
|
||||
GAME_STATE.deckSize--;
|
||||
player->cardCount++;
|
||||
}
|
||||
}
|
||||
|
||||
pokerActionRemove(index);
|
||||
}
|
||||
|
||||
void actionDealUpdate(int32_t i, void *data) {
|
||||
|
||||
}
|
||||
|
||||
void actionDealDispose(int32_t i, void *data) {
|
||||
int32_t newI = pokerActionAdd(actionAi());
|
||||
}
|
18
temp/action/deal.h
Normal file
18
temp/action/deal.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 "../../debug/log.h"
|
||||
#include "action.h"
|
||||
#include "ai.h"
|
||||
|
||||
pokeraction_t actionDeal();
|
||||
|
||||
void actionDealInit(int32_t i, void *data);
|
||||
void actionDealUpdate(int32_t i, void *data);
|
||||
void actionDealDispose(int32_t i, void *data);
|
50
temp/action/flop.c
Normal file
50
temp/action/flop.c
Normal file
@ -0,0 +1,50 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "flop.h"
|
||||
|
||||
pokeraction_t actionFlop() {
|
||||
return (pokeraction_t){
|
||||
.init = &actionFlopInit,
|
||||
.update = &actionFlopUpdate,
|
||||
.dispose = &actionFlopDispose
|
||||
};
|
||||
}
|
||||
|
||||
void actionFlopInit(int32_t index, void *data) {
|
||||
uint8_t i, count;
|
||||
logText("Flop");
|
||||
|
||||
// Look at the dealer
|
||||
|
||||
// Do the flop
|
||||
// if(match->cardsFacing >= HOLDEM_DEALER_HAND) return;
|
||||
|
||||
// Burn the card off the top
|
||||
GAME_STATE.deckSize -= 1;
|
||||
|
||||
// Change count depending on facing
|
||||
count = GAME_STATE.cardsFacing == 0 ? 0x03 : 0x01;
|
||||
|
||||
// Deal
|
||||
for(i = 0; i < count; i++) {
|
||||
cardDeal(GAME_STATE.deck, GAME_STATE.cards, GAME_STATE.deckSize, GAME_STATE.cardsFacing);
|
||||
GAME_STATE.deckSize -= 1;
|
||||
GAME_STATE.cardsFacing += 1;
|
||||
}
|
||||
|
||||
// Next action
|
||||
pokerActionRemove(index);
|
||||
}
|
||||
|
||||
void actionFlopUpdate(int32_t index, void *data) {
|
||||
|
||||
}
|
||||
|
||||
void actionFlopDispose(int32_t index, void *data) {
|
||||
pokerActionAdd(actionAi());
|
||||
}
|
19
temp/action/flop.h
Normal file
19
temp/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 "../../debug/log.h"
|
||||
#include "../render/look.h"
|
||||
#include "action.h"
|
||||
#include "ai.h"
|
||||
|
||||
pokeraction_t actionFlop();
|
||||
|
||||
void actionFlopInit(int32_t index, void *data);
|
||||
void actionFlopUpdate(int32_t index, void *data);
|
||||
void actionFlopDispose(int32_t index, void *data);
|
66
temp/action/round.c
Normal file
66
temp/action/round.c
Normal file
@ -0,0 +1,66 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "round.h"
|
||||
|
||||
pokeraction_t actionRound() {
|
||||
return (pokeraction_t){
|
||||
.init = &actionRoundInit,
|
||||
.update = &actionRoundUpdate,
|
||||
.dispose = &actionRoundDispose
|
||||
};
|
||||
}
|
||||
|
||||
void actionRoundInit(int32_t index, void *data) {
|
||||
uint8_t i;
|
||||
pokerplayer_t *player;
|
||||
|
||||
logText("Round Start");
|
||||
|
||||
// Look at the dealer.
|
||||
holdemRenderLookHand(&GAME_STATE.cameraLeft, HOLDEM_GAME_SEAT_PLAYER0);
|
||||
|
||||
// Init the round and shuffle the deck
|
||||
cardDeckFill(GAME_STATE.deck);
|
||||
GAME_STATE.deckSize = CARD_DECK_SIZE;
|
||||
GAME_STATE.pot = 0;
|
||||
GAME_STATE.cardsFacing = 0;
|
||||
|
||||
// Reset the players
|
||||
for(i = 0; i < POKER_PLAYER_COUNT; i++) {
|
||||
player = GAME_STATE.players + i;
|
||||
|
||||
// Clear Round State(s)
|
||||
player->state &= ~(
|
||||
POKER_PLAYER_STATE_FOLDED |
|
||||
POKER_PLAYER_STATE_SHOWING
|
||||
);
|
||||
|
||||
player->cardCount = 0;
|
||||
player->currentBet = 0;
|
||||
|
||||
player->chips = 1000;
|
||||
player->currentBet = 1000;
|
||||
}
|
||||
|
||||
// Next action
|
||||
pokerActionRemove(index);
|
||||
}
|
||||
|
||||
void actionRoundUpdate(int32_t index, void *data) {
|
||||
}
|
||||
|
||||
void actionRoundAfterShuffle() {
|
||||
logText("Shuffle Done");
|
||||
int32_t i = pokerActionAdd(actionDeal());
|
||||
}
|
||||
|
||||
void actionRoundDispose(int32_t index, void *data) {
|
||||
int32_t newI = pokerActionAdd(actionShuffle());
|
||||
shuffledata_t *newData=(shuffledata_t *)(GAME_STATE.actionData + newI);
|
||||
newData->done = &actionRoundAfterShuffle;
|
||||
}
|
23
temp/action/round.h
Normal file
23
temp/action/round.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 "../render/look.h"
|
||||
#include "../../debug/log.h"
|
||||
#include "action.h"
|
||||
#include "ai.h"
|
||||
#include "shuffle.h"
|
||||
#include "deal.h"
|
||||
|
||||
pokeraction_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
temp/action/shuffle.c
Normal file
30
temp/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"
|
||||
|
||||
pokeraction_t actionShuffle() {
|
||||
return (pokeraction_t){
|
||||
.init = &actionShuffleInit,
|
||||
.update = &actionShuffleUpdate,
|
||||
.dispose = &actionShuffleDispose
|
||||
};
|
||||
}
|
||||
|
||||
void actionShuffleInit(int32_t index, void *data) {
|
||||
logText("Shuffle Deck");
|
||||
cardShuffle(GAME_STATE.deck, GAME_STATE.deckSize);
|
||||
pokerActionRemove(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
temp/action/shuffle.h
Normal file
23
temp/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;
|
||||
|
||||
pokeraction_t actionShuffle();
|
||||
|
||||
void actionShuffleInit(int32_t index, void *data);
|
||||
|
||||
void actionShuffleUpdate(int32_t index, void *data);
|
||||
|
||||
void actionShuffleDispose(int32_t index, void *data);
|
46
temp/action/start.c
Normal file
46
temp/action/start.c
Normal file
@ -0,0 +1,46 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "start.h"
|
||||
|
||||
pokeraction_t actionStart() {
|
||||
pokeraction_t action = {
|
||||
.init = &actionStartInit,
|
||||
.update = &actionStartUpdate,
|
||||
.dispose = &actionStartDispose
|
||||
};
|
||||
|
||||
return action;
|
||||
}
|
||||
|
||||
void actionStartInit(int32_t index, void *data) {
|
||||
uint8_t i;
|
||||
pokerplayer_t *player;
|
||||
logText("Holdem Starting");
|
||||
|
||||
// Prepare the match
|
||||
GAME_STATE.blindBig = 0;
|
||||
GAME_STATE.blindSmall = 0;
|
||||
GAME_STATE.pot = 0;
|
||||
|
||||
// Reset the players
|
||||
for(i = 0; i < POKER_PLAYER_COUNT; i++) {
|
||||
player = GAME_STATE.players + i;
|
||||
player->state = 0x00;
|
||||
player->chips = 0;
|
||||
}
|
||||
|
||||
pokerActionRemove(index);
|
||||
}
|
||||
|
||||
void actionStartUpdate(int32_t index, void *data) {
|
||||
}
|
||||
|
||||
void actionStartDispose(int32_t index, void *data) {
|
||||
// Begin the first round
|
||||
pokerActionAdd(actionRound());
|
||||
}
|
18
temp/action/start.h
Normal file
18
temp/action/start.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 "action.h"
|
||||
#include "round.h"
|
||||
#include "../../debug/log.h"
|
||||
|
||||
pokeraction_t actionStart();
|
||||
|
||||
void actionStartInit(int32_t index, void *data);
|
||||
void actionStartUpdate(int32_t index, void *data);
|
||||
void actionStartDispose(int32_t index, void *data);
|
Reference in New Issue
Block a user