#pragma once #include #include #include #include template std::string EnumToString(T value, const std::vector & names) { return names[static_cast(value)]; } template T RandomEnum(const int max) { return static_cast (rand() % max); } template T StringToEnum(std::string name, const std::vector & names) { size_t i; std::string newName; std::vector:: const_iterator pos; // lower it for (i = 0; i < name.size(); ++i) { newName += static_cast(tolower(name[i])); } // uppercase first letter if (newName.size() > 0) { newName[0] = static_cast (toupper(newName[0])); } // find it. pos = std::find(cbegin(names), cend(names), newName); // return it if (pos == cend(names)) { return static_cast(names.size()); } else { return static_cast(pos-cbegin(names)); } } enum class SuiteT {HEART, SPADE, DIAMOND, CLUB, NONE}; const std::vector SUITE_NAMES{"Heart","Spade", "Diamond","Club","None"}; const int SUITE_COUNT{static_cast(SuiteT::NONE)}; SuiteT StringToSuiteT(std::string name); enum class ValueT {ACE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN, JACK, QUEEN, KING, NONE}; const std::vector VALUE_NAMES {"Ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King", "None"}; const int VALUE_COUNT{static_cast(ValueT::NONE)}; ValueT StringToValueT(std::string name); class CardT { public: CardT(SuiteT s = SuiteT::NONE, ValueT v=ValueT::NONE): suite(s), value(v) {}; void Randomize(); virtual bool operator ==(const CardT & other) const; virtual bool operator <(const CardT & other) const; virtual std::string Name() { return "CardT"; } ValueT Value() const; SuiteT Suite() const; std::string ToString() const; private: SuiteT suite{SuiteT::NONE}; ValueT value{ValueT::NONE}; }; std::ostream & operator << (std::ostream & s, const CardT & c);