Added set dealer method.
This commit is contained in:
@ -17,7 +17,6 @@ void _pokerActionBlindsOnStart(queue_t *queue,queueaction_t *action,uint8_t i) {
|
|||||||
queueNext(queue);
|
queueNext(queue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
queueaction_t * pokerActionBlindsAdd(queue_t *queue, poker_t *poker) {
|
queueaction_t * pokerActionBlindsAdd(queue_t *queue, poker_t *poker) {
|
||||||
queueaction_t *action;
|
queueaction_t *action;
|
||||||
action = queueAdd(queue);
|
action = queueAdd(queue);
|
||||||
|
@ -11,8 +11,6 @@ void _pokerActionFlopDo(queue_t *queue, queueaction_t *action, uint8_t count) {
|
|||||||
poker_t *poker;
|
poker_t *poker;
|
||||||
poker = (poker_t *)action->data;
|
poker = (poker_t *)action->data;
|
||||||
|
|
||||||
// TODO: Fix State
|
|
||||||
// poker->state = POKER_STATE_CARDS_FLOPPING;
|
|
||||||
pokerBurn(poker, POKER_FLOP_BURN_COUNT);
|
pokerBurn(poker, POKER_FLOP_BURN_COUNT);
|
||||||
pokerTurn(poker, count);
|
pokerTurn(poker, count);
|
||||||
|
|
||||||
|
@ -1,33 +0,0 @@
|
|||||||
/**
|
|
||||||
* 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;
|
|
||||||
|
|
||||||
// TODO: Fix state
|
|
||||||
// poker->state = POKER_STATE_STARTING_MATCH;
|
|
||||||
|
|
||||||
// Reset the main game state. This will also init the round.
|
|
||||||
pokerInit(&poker);
|
|
||||||
|
|
||||||
//TODO: Add Players here
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
@ -1,21 +0,0 @@
|
|||||||
// 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 "../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);
|
|
@ -70,17 +70,21 @@ void pokerResetBettingRound(poker_t *poker) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void pokerNewDealer(poker_t *poker) {
|
void pokerNewDealer(poker_t *poker) {
|
||||||
uint8_t i, j, k;
|
pokerSetDealer(poker, poker->playerDealer + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void pokerSetDealer(poker_t *poker, uint8_t dealer) {
|
||||||
|
uint8_t i, k;
|
||||||
pokerplayer_t *player;
|
pokerplayer_t *player;
|
||||||
bool foundDealer;
|
bool foundDealer;
|
||||||
bool foundSmall;
|
bool foundSmall;
|
||||||
|
|
||||||
foundDealer = false;
|
foundDealer = false;
|
||||||
foundSmall = false;
|
foundSmall = false;
|
||||||
|
poker->playerDealer = dealer;
|
||||||
|
|
||||||
j = poker->playerDealer + 1;
|
|
||||||
for(i = 0; i < poker->playerCount; i++) {
|
for(i = 0; i < poker->playerCount; i++) {
|
||||||
k = (j + i) % poker->playerCount;
|
k = (dealer + i) % poker->playerCount;
|
||||||
player = poker->players + k;
|
player = poker->players + k;
|
||||||
if(player->state & POKER_PLAYER_STATE_OUT) continue;
|
if(player->state & POKER_PLAYER_STATE_OUT) continue;
|
||||||
if(!foundDealer) {
|
if(!foundDealer) {
|
||||||
|
@ -217,6 +217,15 @@ void pokerResetBettingRound(poker_t *poker);
|
|||||||
*/
|
*/
|
||||||
void pokerNewDealer(poker_t *poker);
|
void pokerNewDealer(poker_t *poker);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a next dealer. This will also select the new small and big blind players.
|
||||||
|
* This will automatically skip out players if you provide one.
|
||||||
|
*
|
||||||
|
* @param poker Poker game to select a new dealer for.
|
||||||
|
* @param dealer Dealer to become the new dealer.
|
||||||
|
*/
|
||||||
|
void pokerSetDealer(poker_t *poker, uint8_t dealer);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Take the blinds from the blind players.
|
* Take the blinds from the blind players.
|
||||||
*
|
*
|
||||||
|
@ -125,8 +125,48 @@ void test_pokerNewDealer_should_FindANewDealer(void) {
|
|||||||
TEST_ASSERT_EQUAL_UINT8(1, poker.playerBigBlind);
|
TEST_ASSERT_EQUAL_UINT8(1, poker.playerBigBlind);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_pokerNewDealer_should_SkipOutPlayers(void) {
|
void test_pokerSetDealer_should_SetANewSetOfPlayers(void) {
|
||||||
|
poker_t poker;
|
||||||
|
pokerInit(&poker);
|
||||||
|
|
||||||
|
pokerPlayerChipsAdd(poker.players + pokerPlayerAdd(&poker), 1000);
|
||||||
|
pokerPlayerChipsAdd(poker.players + pokerPlayerAdd(&poker), 1000);
|
||||||
|
pokerPlayerChipsAdd(poker.players + pokerPlayerAdd(&poker), 1000);
|
||||||
|
pokerPlayerChipsAdd(poker.players + pokerPlayerAdd(&poker), 1000);
|
||||||
|
pokerPlayerChipsAdd(poker.players + pokerPlayerAdd(&poker), 1000);
|
||||||
|
|
||||||
|
pokerSetDealer(&poker, 0x00);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(0, poker.playerDealer);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(1, poker.playerSmallBlind);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(2, poker.playerBigBlind);
|
||||||
|
|
||||||
|
pokerSetDealer(&poker, 0x01);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(1, poker.playerDealer);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(2, poker.playerSmallBlind);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(3, poker.playerBigBlind);
|
||||||
|
|
||||||
|
pokerSetDealer(&poker, 0x02);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(2, poker.playerDealer);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(3, poker.playerSmallBlind);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(4, poker.playerBigBlind);
|
||||||
|
|
||||||
|
pokerSetDealer(&poker, 0x03);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(3, poker.playerDealer);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(4, poker.playerSmallBlind);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(0, poker.playerBigBlind);
|
||||||
|
|
||||||
|
pokerSetDealer(&poker, 0x04);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(4, poker.playerDealer);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(0, poker.playerSmallBlind);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(1, poker.playerBigBlind);
|
||||||
|
|
||||||
|
pokerSetDealer(&poker, 0x00);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(0, poker.playerDealer);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(1, poker.playerSmallBlind);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(2, poker.playerBigBlind);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_pokerSetDealer_should_SkipOutPlayers(void) {
|
||||||
poker_t poker;
|
poker_t poker;
|
||||||
pokerInit(&poker);
|
pokerInit(&poker);
|
||||||
|
|
||||||
@ -136,17 +176,27 @@ void test_pokerNewDealer_should_SkipOutPlayers(void) {
|
|||||||
pokerPlayerChipsAdd(poker.players + pokerPlayerAdd(&poker), 1000);
|
pokerPlayerChipsAdd(poker.players + pokerPlayerAdd(&poker), 1000);
|
||||||
pokerPlayerAdd(&poker);
|
pokerPlayerAdd(&poker);
|
||||||
|
|
||||||
pokerNewDealer(&poker);
|
pokerSetDealer(&poker, 0x00);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(0, poker.playerDealer);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(1, poker.playerSmallBlind);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(3, poker.playerBigBlind);
|
||||||
|
|
||||||
|
pokerSetDealer(&poker, 0x01);
|
||||||
TEST_ASSERT_EQUAL_UINT8(1, poker.playerDealer);
|
TEST_ASSERT_EQUAL_UINT8(1, poker.playerDealer);
|
||||||
TEST_ASSERT_EQUAL_UINT8(3, poker.playerSmallBlind);
|
TEST_ASSERT_EQUAL_UINT8(3, poker.playerSmallBlind);
|
||||||
TEST_ASSERT_EQUAL_UINT8(0, poker.playerBigBlind);
|
TEST_ASSERT_EQUAL_UINT8(0, poker.playerBigBlind);
|
||||||
|
|
||||||
pokerNewDealer(&poker);
|
pokerSetDealer(&poker, 0x02);
|
||||||
TEST_ASSERT_EQUAL_UINT8(3, poker.playerDealer);
|
TEST_ASSERT_EQUAL_UINT8(3, poker.playerDealer);
|
||||||
TEST_ASSERT_EQUAL_UINT8(0, poker.playerSmallBlind);
|
TEST_ASSERT_EQUAL_UINT8(0, poker.playerSmallBlind);
|
||||||
TEST_ASSERT_EQUAL_UINT8(1, poker.playerBigBlind);
|
TEST_ASSERT_EQUAL_UINT8(1, poker.playerBigBlind);
|
||||||
|
|
||||||
pokerNewDealer(&poker);
|
pokerSetDealer(&poker, 0x03);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(3, poker.playerDealer);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(0, poker.playerSmallBlind);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(1, poker.playerBigBlind);
|
||||||
|
|
||||||
|
pokerSetDealer(&poker, 0x04);
|
||||||
TEST_ASSERT_EQUAL_UINT8(0, poker.playerDealer);
|
TEST_ASSERT_EQUAL_UINT8(0, poker.playerDealer);
|
||||||
TEST_ASSERT_EQUAL_UINT8(1, poker.playerSmallBlind);
|
TEST_ASSERT_EQUAL_UINT8(1, poker.playerSmallBlind);
|
||||||
TEST_ASSERT_EQUAL_UINT8(3, poker.playerBigBlind);
|
TEST_ASSERT_EQUAL_UINT8(3, poker.playerBigBlind);
|
||||||
@ -1544,7 +1594,8 @@ int test_poker() {
|
|||||||
RUN_TEST(test_pokerPotAdd_should_ResetThePot);
|
RUN_TEST(test_pokerPotAdd_should_ResetThePot);
|
||||||
RUN_TEST(test_pokerPotHasPlayer_should_DetermineIfPlayerInThePot);
|
RUN_TEST(test_pokerPotHasPlayer_should_DetermineIfPlayerInThePot);
|
||||||
RUN_TEST(test_pokerNewDealer_should_FindANewDealer);
|
RUN_TEST(test_pokerNewDealer_should_FindANewDealer);
|
||||||
RUN_TEST(test_pokerNewDealer_should_SkipOutPlayers);
|
RUN_TEST(test_pokerSetDealer_should_SetANewSetOfPlayers);
|
||||||
|
RUN_TEST(test_pokerSetDealer_should_SkipOutPlayers);
|
||||||
RUN_TEST(test_pokerTakeBlinds_should_TakeTheBlinds);
|
RUN_TEST(test_pokerTakeBlinds_should_TakeTheBlinds);
|
||||||
RUN_TEST(test_pokerPotAddPlayer_should_AddAPlayer);
|
RUN_TEST(test_pokerPotAddPlayer_should_AddAPlayer);
|
||||||
RUN_TEST(test_pokerPlayerAdd_should_ResetThePlayer);
|
RUN_TEST(test_pokerPlayerAdd_should_ResetThePlayer);
|
||||||
|
Reference in New Issue
Block a user