34 lines
809 B
C
34 lines
809 B
C
/**
|
|
* Copyright (c) 2021 Dominic Masters
|
|
*
|
|
* This software is released under the MIT License.
|
|
* https://opensource.org/licenses/MIT
|
|
*/
|
|
|
|
#include "card.h"
|
|
|
|
void cardDeckFill(card_t *deck) {
|
|
uint8_t i;
|
|
for(i = 0; i < CARD_DECK_SIZE; i++) {
|
|
deck[i] = i;
|
|
}
|
|
}
|
|
|
|
void cardShuffle(card_t *hand, uint8_t cardCount) {
|
|
uint8_t i, j;
|
|
card_t temporary;
|
|
for(i = 0; i < cardCount - 1; i++) {
|
|
// Select random element from remaining elements.
|
|
j = u8randRange(i, cardCount);
|
|
temporary = hand[j];// Take out other card
|
|
hand[j] = hand[i];// Move my card there
|
|
hand[i] = temporary;// Put other card here.
|
|
}
|
|
}
|
|
|
|
void cardDeal(card_t *deck, card_t *hand, uint8_t deckSize, uint8_t handSize) {
|
|
card_t card;
|
|
card = deck[deckSize-1];
|
|
deck[deckSize-1] = 0x00;
|
|
hand[handSize] = card;
|
|
} |