Added additional tests.

This commit is contained in:
2021-10-05 00:10:09 -07:00
parent a9a7d40df8
commit 189da04c8f
6 changed files with 551 additions and 10 deletions

View File

@ -58,10 +58,9 @@ uint8_t cardCountPairs(card_t *in, uint8_t inCount, uint8_t number,
int32_t out[CARD_SUIT_COUNT]
) {
uint8_t i, count;
int32_t index;
count = 0;
for(i = 0; i <= inCount; i++) {// "For each suit"
for(i = 0; i < inCount; i++) {// "For each suit"
if(cardGetNumber(in[i]) != number) continue;
out[count++] = i;
}
@ -77,4 +76,23 @@ uint8_t cardWriteDeck(card_t *hand) {
uint8_t i;
for(i = 0; i < CARD_DECK_SIZE; i++) hand[i] = i;
return CARD_DECK_SIZE;
}
card_t cardGetHighestCard(card_t *cards, uint8_t cardCount) {
uint8_t i, number, bestNumber;
card_t card, bestCard;
bestNumber = 0xFF;
for(i = 0; i < cardCount; i++) {
card = cards[i];
number = cardGetNumber(card);
if(number == CARD_ACE) return card;
if(bestNumber != 0xFF && number <= bestNumber) continue;
bestCard = card;
bestNumber = number;
}
return bestCard;
}

View File

@ -202,4 +202,13 @@ void cardShuffle(card_t *hand, uint8_t length);
* @param hand Hand to write the deck to.
* @return The count of cards in the deck.
*/
uint8_t cardWriteDeck(card_t *hand);
uint8_t cardWriteDeck(card_t *hand);
/**
* Get the highest card from a hand of cards.
*
* @param cards Array of cards.
* @param cardCount Length of the array.
* @return The highest card in the array.
*/
card_t cardGetHighestCard(card_t *cards, uint8_t cardCount);