/** * 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; poker->pot = 0; poker->graveSize = 0; poker->cardsFacing = 0; poker->deckSize = CARD_DECK_SIZE; for(i = 0; i < CARD_DECK_SIZE; i++) poker->deck[i] = i; // Reset the players for(i = 0; i < POKER_PLAYER_COUNT; i++) { poker->players[i].cardCount = 0; poker->players[i].currentBet = 0; // Invert then bitwise AND to turn off. poker->players[i].state &= ~( POKER_PLAYER_STATE_FOLDED | POKER_PLAYER_STATE_SHOWING ); } // 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); }