// Copyright (c) 2022 Dominic Masters // // This software is released under the MIT License. // https://opensource.org/licenses/MIT #include "Card.hpp" using namespace Dawn; void Card::fillDeck(std::vector *deck) { assertNotNull(deck); for(uint8_t i = 0; i < CARD_DECK_SIZE; i++) { deck->push_back(Card(i)); } } int32_t Card::contains(std::vector *deck, struct Card c) { assertNotNull(deck); auto it = deck->begin(); while(it != deck->end()) { if(it->cardValue == c.cardValue) return (int32_t)(it - deck->begin()); ++it; } return -1; } int32_t Card::containsNumber( std::vector *deck, enum CardValue number ) { assertNotNull(deck); assertTrue(number < CARD_COUNT_PER_SUIT); auto it = deck->begin(); while(it != deck->end()) { if(it->getValue() == number) return (int32_t)(it - deck->begin()); ++it; } return -1; } std::vector Card::countPairs( std::vector *deck, enum CardValue val ) { std::vector pairs; assertNotNull(deck); assertTrue(deck->size() > 0); auto it = deck->begin(); while(it != deck->end()) { if(it->getValue() == val) pairs.push_back(*it); ++it; } return pairs; } bool_t Card::cardSorter(struct Card left, struct Card right) { return left.cardValue < right.cardValue; } void Card::sort(std::vector *deck) { assertNotNull(deck); assertTrue(deck->size() > 1); std::sort(deck->begin(), deck->end(), &Card::cardSorter); }