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

void pokerDealerInit(pokerdealer_t *dealer) {
  uint8_t i;

  dealer->graveSize = 0;
  dealer->cardsFacing = 0;
  dealer->deckSize = CARD_DECK_SIZE;
  for(i = 0; i < CARD_DECK_SIZE; i++) dealer->deck[i] = i;
}

void pokerDealerTurn(pokerdealer_t *dealer, uint8_t count) {
  uint8_t i;
  for(i = 0; i < count; i++) {
    cardDeal(
      dealer->deck, &dealer->deckSize,
      dealer->cards, &dealer->cardsFacing
    );
  }
}

void pokerDealerBurn(pokerdealer_t *dealer, uint8_t count) {
  uint8_t i;
  for(i = 0; i < count; i++) {
    cardDeal(
      dealer->deck, &dealer->deckSize,
      dealer->grave, &dealer->graveSize
    );
  }
}

void pokerDealerDeal(pokerdealer_t *dealer, pokerplayer_t *player) {
  cardDeal(dealer->deck, &dealer->deckSize, player->cards, &player->cardCount);
}

void pokerDealerDealAll(poker_t *poker, uint8_t count) {
  uint8_t x, y;
  pokerplayer_t *player;

  for(y = 0; y < count; y++) {
    for(x = 0; x < POKER_PLAYER_COUNT; x++) {
      player = poker->players + x;
      if(!pokerPlayerIsAlive(player)) continue;
      pokerDealerDeal(&poker->dealer, player);
    }
  }
}