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

#include "turn.h"

pokerturn_t pokerTurnGet(poker_t *poker, uint8_t playerIndex) {
  pokerturn_t turn;
  pokerplayer_t *player;
  bool canCheck;

  player = poker->players + playerIndex;

  // Can the player do anything?
  turn.type = POKER_TURN_TYPE_OUT;
  if(player->state & POKER_PLAYER_STATE_FOLDED) return turn;
  if(player->state & POKER_PLAYER_STATE_OUT) return turn;

  canCheck = player->currentBet >= poker->bet.currentBet;

  if(canCheck) {
    turn.type = POKER_TURN_TYPE_CHECK;
    return turn;
  }

  // I have nfi
  turn.type = POKER_TURN_TYPE_BET;
  turn.chips = poker->bet.currentBet - player->currentBet;
  turn.confidence = 1;

  return turn;
}