Started merging new poker code in.
This commit is contained in:
39
backup/poker/poker.c
Normal file
39
backup/poker/poker.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 "poker.h"
|
||||
|
||||
void pokerGameWin(poker_t *poker) {
|
||||
uint8_t i;
|
||||
pokerplayerwinning_t *winning;
|
||||
pokerplayer_t *player;
|
||||
int32_t chipsRounded, chipsDifferent;
|
||||
float chipsEach;
|
||||
|
||||
poker->state = POKER_STATE_DECIDING_WINNER;
|
||||
|
||||
// Get the chips each.
|
||||
chipsEach = poker->bet.pot / ((float)poker->winner.winnerCount);
|
||||
|
||||
// Now work out the rounded offset chips.
|
||||
chipsRounded = (int32_t)mathFloor(chipsEach);
|
||||
chipsDifferent = poker->bet.pot - chipsRounded;
|
||||
|
||||
// Let's start by rewarding the winnings to the players.
|
||||
for(i = 0; i < poker->winner.winnerCount; i++) {
|
||||
player = poker->players + poker->winner.winners[i];
|
||||
winning = poker->winner.winnings + i;
|
||||
player->chips += chipsRounded;
|
||||
if(i == 0) player->chips += chipsDifferent;
|
||||
}
|
||||
|
||||
// Now kill the players who are terrible low life gamblers.
|
||||
for(i = 0; i < POKER_PLAYER_COUNT; i++) {
|
||||
player = poker->players + i;
|
||||
if(player->chips <= 0) player->state &= POKER_PLAYER_STATE_OUT;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user