Joining the two logics together slowly.
This commit is contained in:
75
temp/round/bet.c
Normal file
75
temp/round/bet.c
Normal file
@ -0,0 +1,75 @@
|
||||
/**
|
||||
* 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);
|
||||
}
|
19
temp/round/bet.h
Normal file
19
temp/round/bet.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 "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);
|
19
temp/round/blinds.c
Normal file
19
temp/round/blinds.c
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 "blinds.h"
|
||||
|
||||
void pokerBlindsInit(poker_t *poker) {
|
||||
poker->round = POKER_ROUND_BLINDS;
|
||||
|
||||
// Now take blinds
|
||||
pokerBetTakeBlinds(poker);
|
||||
|
||||
printf("Blinds Taken\n");
|
||||
pokerDealInit(poker);
|
||||
}
|
16
temp/round/blinds.h
Normal file
16
temp/round/blinds.h
Normal file
@ -0,0 +1,16 @@
|
||||
/**
|
||||
* 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);
|
23
temp/round/deal.c
Normal file
23
temp/round/deal.c
Normal file
@ -0,0 +1,23 @@
|
||||
/**
|
||||
* 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);
|
||||
}
|
19
temp/round/deal.h
Normal file
19
temp/round/deal.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 "../../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);
|
32
temp/round/flop.c
Normal file
32
temp/round/flop.c
Normal file
@ -0,0 +1,32 @@
|
||||
/**
|
||||
* 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);
|
||||
}
|
14
temp/round/flop.h
Normal file
14
temp/round/flop.h
Normal file
@ -0,0 +1,14 @@
|
||||
/**
|
||||
* 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);
|
26
temp/round/match.c
Normal file
26
temp/round/match.c
Normal file
@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
#include "match.h"
|
||||
|
||||
void pokerMatchInit(poker_t *poker, engine_t *engine) {
|
||||
uint8_t x;
|
||||
|
||||
// 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");
|
||||
pokerStartInit(poker);
|
||||
}
|
||||
|
||||
void pokerMatchUpdate(poker_t *poker, engine_t *engine) {
|
||||
}
|
23
temp/round/match.h
Normal file
23
temp/round/match.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 "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);
|
57
temp/round/start.c
Normal file
57
temp/round/start.c
Normal file
@ -0,0 +1,57 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "start.h"
|
||||
|
||||
void pokerStartInit(poker_t *poker) {
|
||||
uint8_t i, indexDealer, indexSmallBlind, indexBigBlind;
|
||||
bool foundDealer, foundSmallBlind;
|
||||
pokerplayer_t *player;
|
||||
|
||||
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.
|
||||
i = poker->roundDealer;
|
||||
foundDealer = false;
|
||||
foundSmallBlind = false;
|
||||
while(true) {
|
||||
player = poker->players + i;
|
||||
if(!pokerPlayerIsAlive(player)) continue;
|
||||
if(!foundDealer) {
|
||||
indexDealer = i;
|
||||
foundDealer = true;
|
||||
} else if(!foundSmallBlind) {
|
||||
indexSmallBlind = i;
|
||||
foundSmallBlind = true;
|
||||
} else {
|
||||
indexBigBlind = i;
|
||||
break;
|
||||
}
|
||||
i = (i + 1) % POKER_PLAYER_COUNT;
|
||||
}
|
||||
|
||||
// Update players for the round.
|
||||
poker->roundDealer = indexDealer;
|
||||
poker->roundBigBlind = indexBigBlind;
|
||||
poker->roundSmallBlind = indexSmallBlind;
|
||||
|
||||
printf("Round Start\n");
|
||||
pokerBlindsInit(poker);
|
||||
}
|
14
temp/round/start.h
Normal file
14
temp/round/start.h
Normal file
@ -0,0 +1,14 @@
|
||||
/**
|
||||
* 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);
|
12
temp/round/winner.c
Normal file
12
temp/round/winner.c
Normal file
@ -0,0 +1,12 @@
|
||||
/**
|
||||
* 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);
|
||||
}
|
13
temp/round/winner.h
Normal file
13
temp/round/winner.h
Normal file
@ -0,0 +1,13 @@
|
||||
/**
|
||||
* 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