This commit is contained in:
2022-11-21 22:04:05 -08:00
parent ad34be05e3
commit c1ac69a146
5 changed files with 259 additions and 128 deletions

View File

@ -5,6 +5,7 @@
#pragma once
#include "dawnlibs.hpp"
#include "assert/assert.hpp"
namespace Dawn {
enum CardSuit {
@ -43,14 +44,56 @@ namespace Dawn {
public:
uint8_t cardValue;
static void fillDeck(std::vector<struct Card> *deck);
/**
* Shuffles a hand / deck
*
* @param deck Array of cards to shuffle.
*/
static void shuffle(std::vector<struct Card> *deck);
static bool_t contains(std::vector<struct Card> *deck, struct Card);
/**
* Fills a vector with all of the cards in a deck, in order.
*
* @param deck Deck to fill.
*/
static void fillDeck(std::vector<struct Card> *deck);
/**
* Check if an array of cards contains a specific card.
*
* @param deck Deck/Hand/Array of cards to check.
* @param card Card to look for
* @returns The index within the array that the card is. -1 if not found.
*/
static int32_t contains(std::vector<struct Card> *deck, struct Card card);
/**
* Check if the array of cards contains a specific number.
*
* @param deck Array of cards to check
* @param number The number to look for.
* @returns The index that the first card is. -1 if not found.
*/
static int32_t containsNumber(
std::vector<struct Card> *deck,
enum CardValue number
);
/**
* Counts the amount of times a card's number appears within the given
* hand.
*
* @param deck The hand to check
* @param val Value of pairs to find.
* @return Card pairs in the deck.
*/
static std::vector<struct Card> countPairs(
std::vector<struct Card> *deck,
enum CardValue value
enum CardValue val
);
static bool_t cardSorter(struct Card left, struct Card right);
/**
* Sort a hand of cards. Cards are ordered in descending weight, aces are
* high. Cards will be grouped by their suits, e.g. CARD_CLUBS_TWO will
@ -71,14 +114,21 @@ namespace Dawn {
assertTrue(cv < CARD_DECK_SIZE);
}
/**
* Returns the number of a given card.
* @returns The card number.
*/
CardValue getValue() {
return (CardValue)(cardValue % CARD_COUNT_PER_SUIT);
}
/**
* Returns the suit of a given card.
* @returns The suit.
*/
CardSuit getSuit() {
return (CardSuit)(cardValue / CARD_COUNT_PER_SUIT);
}
};
bool_t cardSorter(struct Card left, struct Card right);
}