Joining the two logics together slowly.
This commit is contained in:
35
src/poker/actions/match.c
Normal file
35
src/poker/actions/match.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 "match.h"
|
||||
|
||||
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;
|
||||
poker->round = POKER_ROUND_MATCH;
|
||||
|
||||
for(x = 0; x < POKER_PLAYER_COUNT; x++) {
|
||||
poker->players[x].state = 0x00;
|
||||
poker->players[x].chips = POKER_BET_PLAYER_CHIPS_DEFAULT;
|
||||
}
|
||||
printf("Match Start\n");
|
||||
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;
|
||||
}
|
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);
|
68
src/poker/actions/round.c
Normal file
68
src/poker/actions/round.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 "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;
|
||||
|
||||
poker->round = POKER_ROUND_START;
|
||||
|
||||
// Prepare the initial game state
|
||||
poker->round = POKER_ROUND_DEAL;
|
||||
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 the players.
|
||||
j = poker->roundDealer;
|
||||
foundDealer = false;
|
||||
foundSmallBlind = false;
|
||||
while(true) {
|
||||
player = poker->players + j;
|
||||
if(!pokerPlayerIsAlive(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;
|
||||
|
||||
printf("Round Start\n");
|
||||
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);
|
Reference in New Issue
Block a user