Files
Dawn/src/poker/pot.c

44 lines
987 B
C

/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "pot.h"
uint8_t pokerPotAdd(poker_t *poker) {
pokerpot_t *pot;
uint8_t i = poker->potCount++;
pot = poker->pots + i;
pot->chips = 0;
pot->playerCount = 0;
pot->call = 0;
return i;
}
bool pokerPotHasPlayer(pokerpot_t *pot, uint8_t playerIndex) {
return arrayContains(
sizeof(uint8_t), pot->players, pot->playerCount, &playerIndex
);
}
void pokerPotAddPlayer(pokerpot_t *pot, uint8_t playerIndex) {
if(pokerPotHasPlayer(pot, playerIndex)) return;
pot->players[pot->playerCount++] = playerIndex;
}
int32_t pokerPotGetSumOfChipsForPlayer(poker_t *poker, uint8_t playerIndex) {
int32_t count;
uint8_t i;
pokerpot_t *pot;
count = 0;
for(i = 0; i < poker->potCount; i++) {
pot = poker->pots + i;
if(!pokerPotHasPlayer(pot, playerIndex)) continue;
count += pot->chips;
}
return count;
}