/**
 * Copyright (c) 2021 Dominic Masters
 * 
 * This software is released under the MIT License.
 * https://opensource.org/licenses/MIT
 */

#include "bet.h"

void pokerBetInit(pokerbet_t *bet) {
  bet->blindBig = POKER_BET_BLIND_BIG_DEFAULT;
  bet->blindSmall = POKER_BET_BLIND_SMALL_DEFAULT;
}

void pokerBetReset(pokerbet_t *bet) {
  bet->pot = 0;
  bet->currentBet = 0;
}

void pokerBetPlayer(poker_t *poker, pokerplayer_t *player, int32_t chips) {
  poker->bet.pot += chips;
  player->chips -= chips;
  player->currentBet += chips;
  poker->bet.currentBet = mathMax(poker->bet.currentBet, player->currentBet);
}

void pokerBetResetBetter(poker_t *poker) {
  poker->bet.better = (poker->roundSmallBlind + 1) % POKER_PLAYER_COUNT;
}

void pokerBetTakeBlinds(poker_t *poker) {
  pokerBetPlayer(poker, poker->players + poker->roundSmallBlind,
    poker->bet.blindSmall
  );
  pokerBetPlayer(poker, poker->players + poker->roundBigBlind,
    poker->bet.blindBig
  );
}