├── src ├── Card.cpp ├── Hand.cpp ├── Poker.cpp ├── HandRanker.cpp ├── HandGenerator.cpp ├── stdafx.cpp ├── targetver.h ├── stdafx.h ├── Poker.h ├── Card.h ├── HandGenerator.h ├── HandRanker.h └── Hand.h ├── res ├── poker.png └── pokerhands.png ├── win32 └── poker.exe ├── LICENSE └── README.md /src/Card.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/donnemartin/poker/HEAD/src/Card.cpp -------------------------------------------------------------------------------- /src/Hand.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/donnemartin/poker/HEAD/src/Hand.cpp -------------------------------------------------------------------------------- /res/poker.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/donnemartin/poker/HEAD/res/poker.png -------------------------------------------------------------------------------- /src/Poker.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/donnemartin/poker/HEAD/src/Poker.cpp -------------------------------------------------------------------------------- /win32/poker.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/donnemartin/poker/HEAD/win32/poker.exe -------------------------------------------------------------------------------- /res/pokerhands.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/donnemartin/poker/HEAD/res/pokerhands.png -------------------------------------------------------------------------------- /src/HandRanker.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/donnemartin/poker/HEAD/src/HandRanker.cpp -------------------------------------------------------------------------------- /src/HandGenerator.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/donnemartin/poker/HEAD/src/HandGenerator.cpp -------------------------------------------------------------------------------- /src/stdafx.cpp: -------------------------------------------------------------------------------- 1 | // stdafx.cpp : source file that includes just the standard includes 2 | // dmartinHW2.pch will be the pre-compiled header 3 | // stdafx.obj will contain the pre-compiled type information 4 | 5 | #include "stdafx.h" 6 | 7 | // TODO: reference any additional headers you need in STDAFX.H 8 | // and not in this file 9 | -------------------------------------------------------------------------------- /src/targetver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Including SDKDDKVer.h defines the highest available Windows platform. 4 | 5 | // If you wish to build your application for a previous Windows platform, include WinSDKVer.h and 6 | // set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. 7 | 8 | #include 9 | -------------------------------------------------------------------------------- /src/stdafx.h: -------------------------------------------------------------------------------- 1 | // stdafx.h : include file for standard system include files, 2 | // or project specific include files that are used frequently, but 3 | // are changed infrequently 4 | // 5 | 6 | #pragma once 7 | 8 | #include "targetver.h" 9 | 10 | #include 11 | #include 12 | 13 | 14 | 15 | // TODO: reference additional headers your program requires here 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2014 Donne Martin 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![alt text](http://donnemartin.com/wp-content/uploads/2014/10/poker_cover.jpg) 2 | 3 | poker 4 | ============ 5 | 6 | Poker hand ranker written in C++. 7 | 8 | ##License 9 | 10 | Copyright 2014 Donne Martin 11 | 12 | Licensed under the Apache License, Version 2.0 (the "License"); 13 | you may not use this file except in compliance with the License. 14 | You may obtain a copy of the License at 15 | 16 | http://www.apache.org/licenses/LICENSE-2.0 17 | 18 | Unless required by applicable law or agreed to in writing, software 19 | distributed under the License is distributed on an "AS IS" BASIS, 20 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | See the License for the specific language governing permissions and 22 | limitations under the License. 23 | 24 | ##Ranked Hands 25 | 26 | Uses the set of hands from http://en.wikipedia.org/wiki/Hand_rankings to demonstrate its functionality: 27 | 28 | ![alt tag](https://raw.githubusercontent.com/donnemartin/poker/master/res/pokerhands.png) -------------------------------------------------------------------------------- /src/Poker.h: -------------------------------------------------------------------------------- 1 | //****************************************************************************** 2 | // 3 | // File Name: Poker.h 4 | // 5 | // File Overview: Represents Poker that generates and ranks hands 6 | // 7 | //****************************************************************************** 8 | // 9 | // Revision History: 10 | // 11 | // Date Author Description 12 | // 6.12.11 Donne Martin Added class 13 | //****************************************************************************** 14 | 15 | #ifndef Poker_h 16 | #define Poker_h 17 | 18 | #include "HandGenerator.h" 19 | #include "HandRanker.h" 20 | 21 | //****************************************************************************** 22 | // 23 | // Class: Poker 24 | // 25 | // Revision History: 26 | // 27 | // Date Author Description 28 | // 6.12.11 Donne Martin Added class 29 | // 30 | // Notes : None 31 | // 32 | //****************************************************************************** 33 | class Poker 34 | { 35 | public: 36 | 37 | //*************************************************************************** 38 | // Function : constructor 39 | // Description : Initializes data members to invalid values 40 | // Constraints : None 41 | //*************************************************************************** 42 | Poker(); 43 | 44 | //*************************************************************************** 45 | // Function : destructor 46 | // Description : Performs cleanup tasks 47 | // Constraints : None 48 | //*************************************************************************** 49 | virtual ~Poker(); 50 | 51 | //*************************************************************************** 52 | // Function : runPoker 53 | // Description : Executes the poker program 54 | // Constraints : None 55 | //*************************************************************************** 56 | void runPoker() const; 57 | 58 | private: 59 | //*************************************************************************** 60 | // Function : outputCardNumbers 61 | // Description : Called by runPoker. Internal use only. 62 | // Constraints : None 63 | //*************************************************************************** 64 | void outputCardNumbers() const; 65 | 66 | // No data members 67 | 68 | }; // end class Poker 69 | 70 | #endif // Poker_h -------------------------------------------------------------------------------- /src/Card.h: -------------------------------------------------------------------------------- 1 | //****************************************************************************** 2 | // 3 | // File Name: Card.h 4 | // 5 | // File Overview: Represents a Card containing a number and a suit 6 | // 7 | //****************************************************************************** 8 | // 9 | // Revision History: 10 | // 11 | // Date Author Description 12 | // 6.12.11 Donne Martin Added class 13 | //****************************************************************************** 14 | 15 | #ifndef Card_h 16 | #define Card_h 17 | 18 | using namespace std; 19 | 20 | //****************************************************************************** 21 | // 22 | // Class: Card 23 | // 24 | // Revision History: 25 | // 26 | // Date Author Description 27 | // 6.12.11 Donne Martin Added class 28 | // 29 | // Notes : None 30 | // 31 | //****************************************************************************** 32 | class Card 33 | { 34 | public: 35 | 36 | // Forward declarations for Card enums used in member function params 37 | enum CardSuit; 38 | enum CardNumber; 39 | 40 | //*************************************************************************** 41 | // Function : constructor 42 | // Description : Initializes data members to invalid values 43 | // Not the recommended constructor 44 | // Constraints : Need to set the number and suit afterwards 45 | //*************************************************************************** 46 | Card(); 47 | 48 | //*************************************************************************** 49 | // Function : constructor 50 | // Description : Initializes data members to input suit and number 51 | // Recommended constructor 52 | // Constraints : None 53 | //*************************************************************************** 54 | Card(Card::CardNumber number, Card::CardSuit suit); 55 | 56 | //*************************************************************************** 57 | // Function : destructor 58 | // Description : Performs cleanup tasks 59 | // Constraints : None 60 | //*************************************************************************** 61 | virtual ~Card(); 62 | 63 | // Member functions in alphabetical order 64 | 65 | //*************************************************************************** 66 | // Function : getNumber 67 | // Description : Accessor for number 68 | // Constraints : None 69 | //*************************************************************************** 70 | inline Card::CardNumber getNumber() const; 71 | 72 | //*************************************************************************** 73 | // Function : getSuit 74 | // Description : Accessor for suit 75 | // Constraints : None 76 | //*************************************************************************** 77 | inline Card::CardSuit getSuit() const; 78 | 79 | //*************************************************************************** 80 | // Function : printCard 81 | // Description : prints the card number and suit 82 | // Constraints : None 83 | //*************************************************************************** 84 | void printCard(); 85 | 86 | //*************************************************************************** 87 | // Function : printNumber 88 | // Description : Prints the card number 89 | // Constraints : None 90 | //*************************************************************************** 91 | void printNumber(); 92 | 93 | //*************************************************************************** 94 | // Function : printSuit 95 | // Description : Prints the suit 96 | // Constraints : None 97 | //*************************************************************************** 98 | void printSuit(); 99 | 100 | //*************************************************************************** 101 | // Function : setNumber 102 | // Description : Mutator for number 103 | // Constraints : None 104 | //*************************************************************************** 105 | inline void setNumber(Card::CardNumber number); 106 | 107 | //*************************************************************************** 108 | // Function : setSuit 109 | // Description : Mutator for suit 110 | // Constraints : None 111 | //*************************************************************************** 112 | inline void setSuit(Card::CardSuit suit); 113 | 114 | //*************************************************************************** 115 | // Function : operator< 116 | // Description : Overloads the < operator 117 | // Constraints : None 118 | //*************************************************************************** 119 | inline bool operator<(const Card& a); 120 | 121 | //*************************************************************************** 122 | // public Class Attributes. 123 | //*************************************************************************** 124 | 125 | // Represents a card's suit 126 | enum CardSuit 127 | { 128 | INVALIDSUIT, 129 | CLUB, 130 | SPADE, 131 | HEART, 132 | DIAMOND 133 | }; 134 | 135 | // Represents a card's number 136 | enum CardNumber 137 | { 138 | INVALIDNUMBER, 139 | TWO = 2, 140 | THREE, 141 | FOUR, 142 | FIVE, 143 | SIX, 144 | SEVEN, 145 | EIGHT, 146 | NINE, 147 | TEN, 148 | JACK, 149 | QUEEN, 150 | KING, 151 | ACE 152 | }; 153 | 154 | private: 155 | Card::CardNumber number; // Card's number 156 | Card::CardSuit suit; // Card's suit 157 | 158 | }; // end class Card 159 | 160 | //*************************************************************************** 161 | // Function : getNumber 162 | // Process : Accessor for number 163 | // Notes : None 164 | // 165 | // Revision History: 166 | // 167 | // Date Author Description 168 | // 6.12.11 Donne Martin Added function 169 | //*************************************************************************** 170 | inline Card::CardNumber Card::getNumber() const 171 | { 172 | return this->number; 173 | } // end Card::getNumber 174 | 175 | //*************************************************************************** 176 | // Function : getSuit 177 | // Process : Accessor for suit 178 | // Notes : None 179 | // 180 | // Revision History: 181 | // 182 | // Date Author Description 183 | // 6.12.11 Donne Martin Added function 184 | //*************************************************************************** 185 | inline Card::CardSuit Card::getSuit() const 186 | { 187 | return this->suit; 188 | } // end Card::getSuit 189 | 190 | //*************************************************************************** 191 | // Function : setNumber 192 | // Process : Mutator for number 193 | // Notes : None 194 | // 195 | // Revision History: 196 | // 197 | // Date Author Description 198 | // 6.12.11 Donne Martin Added function 199 | //*************************************************************************** 200 | inline void Card::setNumber(Card::CardNumber number) 201 | { 202 | this->number = number; 203 | } // end Card::setNumber 204 | 205 | //*************************************************************************** 206 | // Function : setSuit 207 | // Process : Mutator for suit 208 | // Notes : None 209 | // 210 | // Revision History: 211 | // 212 | // Date Author Description 213 | // 6.12.11 Donne Martin Added function 214 | //*************************************************************************** 215 | inline void Card::setSuit(Card::CardSuit suit) 216 | { 217 | this->suit = suit; 218 | } // end Card::setSuit 219 | 220 | //*************************************************************************** 221 | // Function : operator< 222 | // Process : Overload the < operator to work with the Card class 223 | // Notes : None 224 | // 225 | // Revision History: 226 | // 227 | // Date Author Description 228 | // 6.12.11 Donne Martin Added function 229 | //*************************************************************************** 230 | inline bool Card::operator<(const Card& a) 231 | { 232 | return a.getNumber() < this->getNumber(); 233 | } // end Card::operator< 234 | 235 | #endif // Card_h -------------------------------------------------------------------------------- /src/HandGenerator.h: -------------------------------------------------------------------------------- 1 | //****************************************************************************** 2 | // 3 | // File Name: HandGenerator.h 4 | // 5 | // File Overview: Represents a Hand Generator to generate hands of cards 6 | // Test harness to evaluate the ranking behavior 7 | // 8 | //****************************************************************************** 9 | // 10 | // Revision History: 11 | // 12 | // Date Author Description 13 | // 6.12.11 Donne Martin Added class 14 | //****************************************************************************** 15 | 16 | #ifndef HandGenerator_h 17 | #define HandGenerator_h 18 | 19 | #include "Hand.h" 20 | 21 | //****************************************************************************** 22 | // 23 | // Class: HandGenerator 24 | // 25 | // Revision History: 26 | // 27 | // Date Author Description 28 | // 6.12.11 Donne Martin Added class 29 | // 30 | // Notes : None 31 | // 32 | //****************************************************************************** 33 | class HandGenerator 34 | { 35 | public: 36 | 37 | //*************************************************************************** 38 | // Function : constructor 39 | // Description : None 40 | // Constraints : None 41 | //*************************************************************************** 42 | HandGenerator(); 43 | 44 | //*************************************************************************** 45 | // Function : destructor 46 | // Description : Performs cleanup tasks 47 | // Constraints : None 48 | //*************************************************************************** 49 | virtual ~HandGenerator(); 50 | 51 | // Member functions in alphabetical order 52 | 53 | //*************************************************************************** 54 | // Function : addHand 55 | // Description : Adds the specified hand 56 | // Optionally prints the cards in the hand (default true) 57 | // Constraints : None 58 | //*************************************************************************** 59 | void addHand(const Hand& hand, const bool printCards = true); 60 | 61 | //*************************************************************************** 62 | // Function : generateFlush 63 | // Description : Generates the flush hands listed in wikipedia 64 | // Constraints : None 65 | //*************************************************************************** 66 | void generateFlush(); 67 | 68 | //*************************************************************************** 69 | // Function : generateFourOfAKind 70 | // Description : Generates the four of a kind hands listed in wikipedia 71 | // Constraints : None 72 | //*************************************************************************** 73 | void generateFourOfAKind(); 74 | 75 | //*************************************************************************** 76 | // Function : generateFullHouse 77 | // Description : Generates the full house hands listed in wikipedia 78 | // Constraints : None 79 | //*************************************************************************** 80 | void generateFullHouse(); 81 | 82 | //*************************************************************************** 83 | // Function : generateHands 84 | // Description : Generates the hands by calling other generate- functions 85 | // Constraints : None 86 | //*************************************************************************** 87 | void generateHands(); 88 | 89 | //*************************************************************************** 90 | // Function : generateHighCard 91 | // Description : Generates the high card hands lissted in wikipedia 92 | // Constraints : None 93 | //*************************************************************************** 94 | void generateHighCard(); 95 | 96 | //*************************************************************************** 97 | // Function : generateOnePair 98 | // Description : Generates the pair hands listed in wikipedia 99 | // Constraints : None 100 | //*************************************************************************** 101 | void generateOnePair(); 102 | 103 | //*************************************************************************** 104 | // Function : generateStraight 105 | // Description : Generates the straight hands listed in wikipedia 106 | // Constraints : None 107 | //*************************************************************************** 108 | void generateStraight(); 109 | 110 | //*************************************************************************** 111 | // Function : generateStraightFlush 112 | // Description : Generates the straight flush hands listed in wikipedia 113 | // Constraints : None 114 | //*************************************************************************** 115 | void generateStraightFlush(); 116 | 117 | //*************************************************************************** 118 | // Function : generateStraightFlushAndFourOfAKind 119 | // Description : Generates straight flush vs four of a kind hands 120 | // Constraints : None 121 | //*************************************************************************** 122 | void generateStraightFlushAndFourOfAKind(); 123 | 124 | //*************************************************************************** 125 | // Function : generateThreeOfAKind 126 | // Description : Generates the three of a kind hands listed in wikipedia 127 | // Constraints : None 128 | //*************************************************************************** 129 | void generateThreeOfAKind(); 130 | 131 | //*************************************************************************** 132 | // Function : generateTwoPair 133 | // Description : Generates the two pair hands listed in wikipedia 134 | // Constraints : None 135 | //*************************************************************************** 136 | void generateTwoPair(); 137 | 138 | //*************************************************************************** 139 | // Function : getHand 140 | // Description : Retrieves the specified hand given the index 141 | // Constraints : Throws an exception if the index is invalid 142 | //*************************************************************************** 143 | inline void getHand(int index, Hand& hand) const; 144 | 145 | //*************************************************************************** 146 | // Function : getHands 147 | // Description : Retrieves all hands 148 | // Constraints : None 149 | //*************************************************************************** 150 | inline void getHands(vector& hands) const; 151 | 152 | //*************************************************************************** 153 | // Function : setHands 154 | // Description : Sets the hands 155 | // Constraints : None 156 | //*************************************************************************** 157 | inline void setHands(const vector& hands); 158 | 159 | private: 160 | vector hands; 161 | }; // end class HandGenerator 162 | 163 | //*************************************************************************** 164 | // Function : getHand 165 | // Process : Retrieve the specified hand given the index 166 | // Notes : Throw an exception if the index is invalid 167 | // 168 | // Revision History: 169 | // 170 | // Date Author Description 171 | // 6.12.11 Donne Martin Added function 172 | //*************************************************************************** 173 | inline void HandGenerator::getHand(int index, Hand& hand) const 174 | { 175 | hand = this->hands.at(index); 176 | } // end HandGenerator::getHand 177 | 178 | //*************************************************************************** 179 | // Function : getHands 180 | // Process : Retrieve all hands 181 | // Notes : None 182 | // 183 | // Revision History: 184 | // 185 | // Date Author Description 186 | // 6.12.11 Donne Martin Added function 187 | //*************************************************************************** 188 | inline void HandGenerator::getHands(vector& hands) const 189 | { 190 | hands = this->hands; 191 | } // end HandGenerator::getHands 192 | 193 | //*************************************************************************** 194 | // Function : setHands 195 | // Process : Set the hands 196 | // Notes : None 197 | // 198 | // Revision History: 199 | // 200 | // Date Author Description 201 | // 6.12.11 Donne Martin Added function 202 | //*************************************************************************** 203 | inline void HandGenerator::setHands(const vector& hands) 204 | { 205 | this->hands = hands; 206 | } // end HandGenerator::setHands 207 | 208 | #endif // HandGenerator_h -------------------------------------------------------------------------------- /src/HandRanker.h: -------------------------------------------------------------------------------- 1 | //****************************************************************************** 2 | // 3 | // File Name: HandRanker.h 4 | // 5 | // File Overview: Represents a Hand Ranker to rank a hand of cards 6 | // 7 | //****************************************************************************** 8 | // 9 | // Revision History: 10 | // 11 | // Date Author Description 12 | // 6.12.11 Donne Martin Added class 13 | //****************************************************************************** 14 | 15 | #ifndef HandRanker_h 16 | #define HandRanker_h 17 | 18 | #include "Hand.h" 19 | 20 | //****************************************************************************** 21 | // 22 | // Class: HandRanker 23 | // 24 | // Revision History: 25 | // 26 | // Date Author Description 27 | // 6.12.11 Donne Martin Added class 28 | // 29 | // Notes : Relies on the hands to be sorted from highest to lowest 30 | // 31 | //****************************************************************************** 32 | class HandRanker 33 | { 34 | public: 35 | 36 | // Forward declaration for Hand enum used in member function params 37 | enum CompareResult; 38 | 39 | //*************************************************************************** 40 | // Function : constructor 41 | // Description : None 42 | // Not the recommended constructor 43 | // Constraints : Need to set hands afterwards 44 | //*************************************************************************** 45 | HandRanker(); 46 | 47 | //*************************************************************************** 48 | // Function : constructor 49 | // Description : Initializes hands to input value 50 | // Recommended constructor 51 | // Constraints : None 52 | //*************************************************************************** 53 | HandRanker(const vector& hands); 54 | 55 | //*************************************************************************** 56 | // Function : destructor 57 | // Description : Performs cleanup tasks 58 | // Constraints : None 59 | //*************************************************************************** 60 | virtual ~HandRanker(); 61 | 62 | // Member functions in alphabetical order 63 | 64 | //*************************************************************************** 65 | // Function : addHand 66 | // Description : Adds the specified hand to list of hands to be ranked 67 | // Constraints : None 68 | //*************************************************************************** 69 | inline void addHand(const Hand& hand); 70 | 71 | //*************************************************************************** 72 | // Function : compareAllHands 73 | // Description : Compares hands, [i vs i + 1], [i + 2 vs i + 3], etc 74 | // Consider changing this algorithm to make it cleaner 75 | // Constraints : None 76 | //*************************************************************************** 77 | void compareAllHands() const; 78 | 79 | //*************************************************************************** 80 | // Function : compareCardHandNumbers 81 | // Description : Compares the input card hand's numbers 82 | // Determines which is larger 83 | // Constraints : None 84 | //*************************************************************************** 85 | HandRanker::CompareResult compareCardHandNumbers( 86 | const Hand& firstHand, 87 | const Hand& secondHand, 88 | const int cardIndex) const; 89 | 90 | //*************************************************************************** 91 | // Function : compareCardNumbers 92 | // Description : Compares the input card numbers 93 | // Determines which is larger 94 | // Constraints : None 95 | //*************************************************************************** 96 | HandRanker::CompareResult HandRanker::compareCardNumbers( 97 | const Card::CardNumber firstCardNumber, 98 | const Card::CardNumber secondCardNumber) const; 99 | 100 | //*************************************************************************** 101 | // Function : compareFourOfAKind 102 | // Description : Compares the two four of a kind hands 103 | // Constraints : The input hands must be four of a kind hands 104 | //*************************************************************************** 105 | HandRanker::CompareResult compareFourOfAKind( 106 | const Hand& firstHand, 107 | const Hand& secondHand) const; 108 | 109 | //*************************************************************************** 110 | // Function : compareFullHouse 111 | // Description : Compares the two full house hands 112 | // Constraints : The input hands must be full house hands 113 | //*************************************************************************** 114 | HandRanker::CompareResult compareFullHouse( 115 | const Hand& firstHand, 116 | const Hand& secondHand) const; 117 | 118 | //*************************************************************************** 119 | // Function : compareHands 120 | // Description : Compares the hands 121 | // Constraints : None 122 | //*************************************************************************** 123 | void compareHands( 124 | const Hand& firstHand, 125 | const Hand& secondHand) const; 126 | 127 | //*************************************************************************** 128 | // Function : compareHandsOfSameType 129 | // Description : Compares hands of same type (ie straight vs straight) 130 | // Constraints : The input hands must be of the same type 131 | //*************************************************************************** 132 | HandRanker::CompareResult compareHandsOfSameType( 133 | const Hand& firstHand, 134 | const Hand& secondHand) const; 135 | 136 | //*************************************************************************** 137 | // Function : compareHighCards 138 | // Description : Compares the hands by determining the high cards 139 | // Called when comparing straight flush, straight, 140 | // flush, and high card types 141 | // Constraints : None 142 | //*************************************************************************** 143 | HandRanker::CompareResult compareHighCards( 144 | const Hand& firstHand, 145 | const Hand& secondHand) const; 146 | 147 | //*************************************************************************** 148 | // Function : compareOneOrTwoPair 149 | // Description : Compares the hands by determining the pairs then high cards 150 | // Called when comparing pair or two pair types 151 | // Constraints : The input hands must be pair or two pair hands 152 | //*************************************************************************** 153 | HandRanker::CompareResult compareOneOrTwoPair( 154 | const Hand& firstHand, 155 | const Hand& secondHand) const; 156 | 157 | //*************************************************************************** 158 | // Function : compareThreeOfAKind 159 | // Description : Compares the two three of a kind hands 160 | // Constraints : The input hands must be three of a kind hands 161 | //*************************************************************************** 162 | HandRanker::CompareResult compareThreeOfAKind( 163 | const Hand& firstHand, 164 | const Hand& secondHand) const; 165 | 166 | //*************************************************************************** 167 | // Function : fixSortOrderIfLowAce 168 | // Description : Calls isLowAceStraight 169 | // Calls fixLowAceStraightSort if needed 170 | // Constraints : Consider making private 171 | //*************************************************************************** 172 | void fixSortOrderIfLowAce(Hand& hand) const; 173 | 174 | //*************************************************************************** 175 | // Function : getHand 176 | // Description : Accessor for hand 177 | // Constraints : None 178 | //*************************************************************************** 179 | inline void getHand(const int index, Hand& hand) const; 180 | 181 | //*************************************************************************** 182 | // Function : getHands 183 | // Description : Accessor for hands 184 | // Constraints : None 185 | //*************************************************************************** 186 | inline void getHands(vector& hands) const; 187 | 188 | //*************************************************************************** 189 | // Function : getHandsSize 190 | // Description : Retrieves the size of Hands 191 | // Constraints : None 192 | //*************************************************************************** 193 | inline int getHandsSize() const; 194 | 195 | //*************************************************************************** 196 | // Function : isFlush 197 | // Description : Determines if the input hand is a flush 198 | // Constraints : None 199 | //*************************************************************************** 200 | bool isFlush(const Hand& hand) const; 201 | 202 | //*************************************************************************** 203 | // Function : isLowAceStraight 204 | // Description : Determines if the input hand is a low ace straight (5 to A) 205 | // Constraints : None 206 | //*************************************************************************** 207 | bool isLowAceStraight(const Hand& hand) const; 208 | 209 | //*************************************************************************** 210 | // Function : isStraight 211 | // Description : Determines if the input hand is a straight 212 | // Constraints : None 213 | //*************************************************************************** 214 | bool isStraight(const Hand& hand) const; 215 | 216 | //*************************************************************************** 217 | // Function : isStraightFlush 218 | // Description : Determines if the input hand is a straight flush 219 | // Constraints : None 220 | //*************************************************************************** 221 | bool isStraightFlush(const Hand& hand) const; 222 | 223 | //*************************************************************************** 224 | // Function : printHandComparisonHeader 225 | // Description : Prints the header showing hand vs hand 226 | // Constraints : None 227 | //*************************************************************************** 228 | void printHandComparisonHeader( 229 | const Hand& firstHand, 230 | const Hand& secondHand) const; 231 | 232 | //*************************************************************************** 233 | // Function : printWinningHand 234 | // Description : Prints the winning hand based on the result parameter 235 | // Constraints : None 236 | //*************************************************************************** 237 | void printWinningHand( 238 | const Hand& firstHand, 239 | const Hand& secondHand, 240 | const HandRanker::CompareResult result) const; 241 | 242 | //*************************************************************************** 243 | // Function : rankHand 244 | // Description : Ranks the hand to determine its type (ie Straight) 245 | // Constraints : None 246 | //*************************************************************************** 247 | void rankHand(Hand& hand) const; 248 | 249 | //*************************************************************************** 250 | // Function : rankHands 251 | // Description : Ranks all hands in the data member hands 252 | // Constraints : None 253 | //*************************************************************************** 254 | void rankHands(); 255 | 256 | //*************************************************************************** 257 | // Function : setHands 258 | // Description : Mutator for hands 259 | // Constraints : None 260 | //*************************************************************************** 261 | inline void setHands(const vector& hands); 262 | 263 | //*************************************************************************** 264 | // public Class Attributes. 265 | //*************************************************************************** 266 | 267 | // Represents the result of hand comparison 268 | enum CompareResult 269 | { 270 | TIE, 271 | FIRSTWINNER, 272 | SECONDWINNER, 273 | INVALIDRESULT 274 | }; 275 | 276 | private: 277 | //*************************************************************************** 278 | // Function : buildHandRepetitionLists 279 | // Description : Builds the hand's repetition lists which include 280 | // singles, pairs, trips, and quads 281 | // Returns the number of unique card numbers in the hand 282 | // Constraints : Private, called by rankHand 283 | //*************************************************************************** 284 | int HandRanker::buildHandRepetitionLists(Hand& hand) const; 285 | 286 | //*************************************************************************** 287 | // Function : fixLowAceStraightSort 288 | // Description : Puts the Ace at low end if we have a low straight 289 | // For example: 5, 4, 3, 2, 1 since the Ace = 14 290 | // Constraints : Does not determine if the input hand is a low straight 291 | // Private, call fixSortOrderIfLowAce instead 292 | //*************************************************************************** 293 | void fixLowAceStraightSort(Hand& hand) const; 294 | 295 | //*************************************************************************** 296 | // Function : rankHandRepetitions 297 | // Description : Ranks the input hands based on the input card repetitions 298 | // Calls rankHandRepetitions 299 | // Used for optimized hand ranking 300 | // Constraints : Private 301 | // Call the appropriate comparison function instead 302 | // based on your hand and your needs, for example: 303 | // -compareHands 304 | // -compareHandsOfSameType 305 | // -compareFourOfAKind 306 | //*************************************************************************** 307 | HandRanker::CompareResult HandRanker::rankHandRepetitions( 308 | const Hand& firstHand, 309 | const Hand& secondHand, 310 | const Hand::CardRepetition repetition) const; 311 | 312 | //*************************************************************************** 313 | // Function : rankHandRepetitionVectors 314 | // Description : Ranks the input hands based on the input card repetitions 315 | // Called by rankHandRepetitions 316 | // Used for optimized hand ranking 317 | // Constraints : Private 318 | // Call the appropriate comparison function instead 319 | // based on your hand and your needs, for example: 320 | // -compareHands 321 | // -compareHandsOfSameType 322 | // -compareFourOfAKind 323 | //*************************************************************************** 324 | HandRanker::CompareResult HandRanker::rankHandRepetitionVectors( 325 | const vector& firstVector, 326 | const vector& secondVector) const; 327 | 328 | vector hands; // List of hands to be ranked 329 | }; // end class HandRanker 330 | 331 | //*************************************************************************** 332 | // Function : addHand 333 | // Process : Adds the specified hand to list of hands to be ranked 334 | // Notes : None 335 | // 336 | // Revision History: 337 | // 338 | // Date Author Description 339 | // 6.12.11 Donne Martin Added function 340 | //*************************************************************************** 341 | inline void HandRanker::addHand(const Hand& hand) 342 | { 343 | this->hands.push_back(hand); 344 | } // end HandRanker::addHand 345 | 346 | //*************************************************************************** 347 | // Function : getHand 348 | // Process : Accessor for hand 349 | // Notes : None 350 | // 351 | // Revision History: 352 | // 353 | // Date Author Description 354 | // 6.12.11 Donne Martin Added function 355 | //*************************************************************************** 356 | inline void HandRanker::getHand(const int index, Hand& hand) const 357 | { 358 | hand = this->hands.at(index); 359 | } // end HandRanker::getHand 360 | 361 | //*************************************************************************** 362 | // Function : getHands 363 | // Process : Accessor for hands 364 | // Notes : None 365 | // 366 | // Revision History: 367 | // 368 | // Date Author Description 369 | // 6.12.11 Donne Martin Added function 370 | //*************************************************************************** 371 | inline void HandRanker::getHands(vector& hands) const 372 | { 373 | hands = this->hands; 374 | } // end HandRanker::getHands 375 | 376 | //*************************************************************************** 377 | // Function : getHandsSize 378 | // Process : Retrieves the size of hands 379 | // Notes : None 380 | // 381 | // Revision History: 382 | // 383 | // Date Author Description 384 | // 6.12.11 Donne Martin Added function 385 | //*************************************************************************** 386 | inline int HandRanker::getHandsSize() const 387 | { 388 | return this->hands.size(); 389 | } // end HandRanker::getHandsSize 390 | 391 | //*************************************************************************** 392 | // Function : setHands 393 | // Process : Mutator for hands 394 | // Notes : None 395 | // 396 | // Revision History: 397 | // 398 | // Date Author Description 399 | // 6.12.11 Donne Martin Added function 400 | //*************************************************************************** 401 | inline void HandRanker::setHands(const vector& hands) 402 | { 403 | this->hands = hands; 404 | } // end HandRanker::setHands 405 | 406 | #endif // HandRanker_h -------------------------------------------------------------------------------- /src/Hand.h: -------------------------------------------------------------------------------- 1 | //****************************************************************************** 2 | // 3 | // File Name: Hand.h 4 | // 5 | // File Overview: Represents a Hand containing five cards 6 | // 7 | //****************************************************************************** 8 | // 9 | // Revision History: 10 | // 11 | // Date Author Description 12 | // 6.12.11 Donne Martin Added class 13 | //****************************************************************************** 14 | 15 | #ifndef Hand_h 16 | #define Hand_h 17 | 18 | #include 19 | #include 20 | #include 21 | #include "Card.h" 22 | 23 | //****************************************************************************** 24 | // 25 | // Class: Hand 26 | // 27 | // Revision History: 28 | // 29 | // Date Author Description 30 | // 6.12.11 Donne Martin Added class 31 | // 32 | // Notes : None 33 | // 34 | //****************************************************************************** 35 | class Hand 36 | { 37 | public: 38 | 39 | // Forward declaration for Hand enum used in member function params 40 | enum HandType; 41 | 42 | //*************************************************************************** 43 | // Function : constructor 44 | // Description : None 45 | // Not the recommended constructor 46 | // Constraints : Need to set cards afterwards 47 | //*************************************************************************** 48 | Hand(); 49 | 50 | //*************************************************************************** 51 | // Function : constructor 52 | // Description : Initializes data members to input cards 53 | // Recommended constructor 54 | // Constraints : None 55 | //*************************************************************************** 56 | Hand( 57 | Card card0, 58 | Card card1, 59 | Card card2, 60 | Card card3, 61 | Card card4); 62 | 63 | //*************************************************************************** 64 | // Function : destructor 65 | // Description : Performs cleanup tasks 66 | // Constraints : None 67 | //*************************************************************************** 68 | virtual ~Hand(); 69 | 70 | // Member functions in alphabetical order 71 | 72 | //*************************************************************************** 73 | // Function : addToPairs 74 | // Description : Adds the number to the list of pairs 75 | // Used for optimized hand ranking 76 | // Constraints : None 77 | //*************************************************************************** 78 | inline void addToPairs(const Card::CardNumber cardNumber); 79 | 80 | //*************************************************************************** 81 | // Function : addToQuads 82 | // Description : Adds the number to the list of quads 83 | // Used for optimized hand ranking 84 | // Constraints : None 85 | //*************************************************************************** 86 | inline void addToQuads(const Card::CardNumber cardNumber); 87 | 88 | //*************************************************************************** 89 | // Function : addToSingles 90 | // Description : Adds the number to the list of singles 91 | // Used for optimized hand ranking 92 | // Constraints : None 93 | //*************************************************************************** 94 | inline void addToSingles(const Card::CardNumber cardNumber); 95 | 96 | //*************************************************************************** 97 | // Function : addToTrips 98 | // Description : Adds the number to the list of trips 99 | // Used for optimized hand ranking 100 | // Constraints : None 101 | //*************************************************************************** 102 | inline void addToTrips(const Card::CardNumber cardNumber); 103 | 104 | //*************************************************************************** 105 | // Function : getCard 106 | // Description : Accessor for cards 107 | // Does not check if index is valid 108 | // Constraints : index must be valid 109 | //*************************************************************************** 110 | inline void getCard( 111 | const int index, 112 | Card& card) const; 113 | 114 | //*************************************************************************** 115 | // Function : getCardNumber 116 | // Description : Accessor for card number 117 | // Checks index for validity 118 | // Constraints : None 119 | //*************************************************************************** 120 | inline Card::CardNumber getCardNumber(const int index) const; 121 | 122 | //*************************************************************************** 123 | // Function : getCards 124 | // Description : Accessor for cards 125 | // Constraints : None 126 | //*************************************************************************** 127 | inline void getCards(vector& cards) const; 128 | 129 | //*************************************************************************** 130 | // Function : getCardSafe 131 | // Description : Accessor for cards, verifies index is valid 132 | // Checks if index is valid, return success, update card param 133 | // Constraints : None 134 | //*************************************************************************** 135 | bool Hand::getCardSafe( 136 | const int index, 137 | Card& card) const; 138 | 139 | //*************************************************************************** 140 | // Function : getCardSuit 141 | // Description : Get the card suit associated with the card 142 | // Checks index for validity 143 | // Constraints : None 144 | //*************************************************************************** 145 | inline Card::CardSuit getCardSuit(const int index) const; 146 | 147 | //*************************************************************************** 148 | // Function : getPairs 149 | // Description : Accessor for the list of pairs 150 | // Used for optimized hand ranking 151 | // Constraints : None 152 | //*************************************************************************** 153 | inline void getPairs(vector& pairs) const; 154 | 155 | //*************************************************************************** 156 | // Function : getQuads 157 | // Description : Accessor for the list of quads 158 | // Used for optimized hand ranking 159 | // Constraints : None 160 | //*************************************************************************** 161 | inline void getQuads(vector& quads) const; 162 | 163 | //*************************************************************************** 164 | // Function : getSingles 165 | // Description : Accessor for the list of singles 166 | // Used for optimized hand ranking 167 | // Constraints : None 168 | //*************************************************************************** 169 | inline void getSingles(vector& singles) const; 170 | 171 | //*************************************************************************** 172 | // Function : getTrips 173 | // Description : Accessor for the list of trips 174 | // Used for optimized hand ranking 175 | // Constraints : None 176 | //*************************************************************************** 177 | inline void getTrips(vector& trips) const; 178 | 179 | //*************************************************************************** 180 | // Function : getType 181 | // Description : Accessor for type 182 | // Constraints : None 183 | //*************************************************************************** 184 | inline Hand::HandType getType() const; 185 | 186 | //*************************************************************************** 187 | // Function : hasPairs 188 | // Description : Determines if the hand has pairs 189 | // Used for optimized hand ranking 190 | // Constraints : None 191 | //*************************************************************************** 192 | inline bool hasPairs() const; 193 | 194 | //*************************************************************************** 195 | // Function : hasQuads 196 | // Description : Determines if the hand has quads 197 | // Used for optimized hand ranking 198 | // Constraints : None 199 | //*************************************************************************** 200 | inline bool hasQuads() const; 201 | 202 | //*************************************************************************** 203 | // Function : hasTrips 204 | // Description : Determines if the hand has trips 205 | // Used for optimized hand ranking 206 | // Constraints : None 207 | //*************************************************************************** 208 | inline bool hasTrips() const; 209 | 210 | //*************************************************************************** 211 | // Function : hasSingles 212 | // Description : Determines if the hand has singles 213 | // Used for optimized hand ranking 214 | // Constraints : None 215 | //*************************************************************************** 216 | inline bool hasSingles() const; 217 | 218 | //*************************************************************************** 219 | // Function : isValidCardIndex 220 | // Description : Determines if the card index is valid (within range) 221 | // Constraints : None 222 | //*************************************************************************** 223 | inline bool isValidCardIndex(const int index) const; 224 | 225 | //*************************************************************************** 226 | // Function : printHand 227 | // Description : Prints each card in the hand 228 | // Prints the hand type 229 | // Constraints : None 230 | //*************************************************************************** 231 | void printHand() const; 232 | 233 | //*************************************************************************** 234 | // Function : printType 235 | // Description : Prints the hand type (straight flush, full house, etc) 236 | // Constraints : None 237 | //*************************************************************************** 238 | void Hand::printType() const; 239 | 240 | //*************************************************************************** 241 | // Function : setCards 242 | // Description : Mutator for cards 243 | // Optionally sorts cards 244 | // Constraints : None 245 | //*************************************************************************** 246 | inline void setCards(const vector& cards, bool sort = true); 247 | 248 | //*************************************************************************** 249 | // Function : setType 250 | // Description : Mutator for type 251 | // Constraints : None 252 | //*************************************************************************** 253 | inline void setType(Hand::HandType type); 254 | 255 | //*************************************************************************** 256 | // Function : sortCards 257 | // Description : Cards utility function 258 | // Sorts the cards based on their CardNumber (low to high) 259 | // Constraints : None 260 | //*************************************************************************** 261 | inline void sortCards(); 262 | 263 | //*************************************************************************** 264 | // Function : sortPairs 265 | // Description : Sorts the list of pairs 266 | // Used for optimized hand ranking 267 | // Constraints : None 268 | //*************************************************************************** 269 | inline void sortPairs(); 270 | 271 | //*************************************************************************** 272 | // Function : sortQuads 273 | // Description : Sorts the list of pairs 274 | // Used for optimized hand ranking 275 | // Constraints : None 276 | //*************************************************************************** 277 | inline void sortQuads(); 278 | 279 | //*************************************************************************** 280 | // Function : sortSingles 281 | // Description : Sorts the list of pairs 282 | // Used for optimized hand ranking 283 | // Constraints : None 284 | //*************************************************************************** 285 | inline void sortSingles(); 286 | 287 | //*************************************************************************** 288 | // Function : sortTrips 289 | // Description : Sorts the list of pairs 290 | // Used for optimized hand ranking 291 | // Constraints : None 292 | //*************************************************************************** 293 | inline void sortTrips(); 294 | 295 | //*************************************************************************** 296 | // public Class Attributes. 297 | //*************************************************************************** 298 | 299 | // Represents the card's hand index from 0 to 4, max 5 cards 300 | enum CardIndex 301 | { 302 | FIRSTCARDINDEX, 303 | SECONDCARDINDEX, 304 | THIRDCARDINDEX, 305 | FOURTHCARDINDEX, 306 | FIFTHCARDINDEX, 307 | MAXCARDS 308 | }; 309 | 310 | // Represents the number of times a card appears in the hand 311 | enum CardRepetition 312 | { 313 | SINGLES = 1, 314 | PAIRS, 315 | TRIPS, 316 | QUADS 317 | }; 318 | 319 | // Represents the hand type (poker hands) 320 | enum HandType 321 | { 322 | INVALIDHAND, 323 | HIGHCARD, 324 | ONEPAIR, 325 | TWOPAIR, 326 | THREEOFAKIND, 327 | STRAIGHT, 328 | FLUSH, 329 | FULLHOUSE, 330 | FOUROFAKIND, 331 | STRAIGHTFLUSH 332 | }; 333 | 334 | private: 335 | vector cards; // List of cards 336 | HandType type; // Hand type (poker hands) 337 | 338 | // The following data members are used for optimized hand ranking 339 | vector pairs; // List of pairs 340 | vector quads; // List of quads 341 | vector singles; // List of singles 342 | vector trips; // List of trips 343 | }; // end class Hand 344 | 345 | //*************************************************************************** 346 | // Function : addToPairs 347 | // Process : Add the number to the list of pairs 348 | // Used for optimized hand ranking 349 | // Notes : None 350 | // 351 | // Revision History: 352 | // 353 | // Date Author Description 354 | // 6.12.11 Donne Martin Added function 355 | //*************************************************************************** 356 | inline void Hand::addToPairs(const Card::CardNumber cardNumber) 357 | { 358 | this->pairs.push_back(cardNumber); 359 | } // end Card::addToPairs 360 | 361 | //*************************************************************************** 362 | // Function : addToQuads 363 | // Process : Add the number to the list of quads 364 | // Used for optimized hand ranking 365 | // Notes : None 366 | // 367 | // Revision History: 368 | // 369 | // Date Author Description 370 | // 6.12.11 Donne Martin Added function 371 | //*************************************************************************** 372 | inline void Hand::addToQuads(const Card::CardNumber cardNumber) 373 | { 374 | this->quads.push_back(cardNumber); 375 | } // end Card::addToQuads 376 | 377 | //*************************************************************************** 378 | // Function : addToSingles 379 | // Process : Add the number to the list of singles 380 | // Used for optimized hand ranking 381 | // Notes : None 382 | // 383 | // Revision History: 384 | // 385 | // Date Author Description 386 | // 6.12.11 Donne Martin Added function 387 | //*************************************************************************** 388 | inline void Hand::addToSingles(const Card::CardNumber cardNumber) 389 | { 390 | this->singles.push_back(cardNumber); 391 | } // end Card::addToSingles 392 | 393 | //*************************************************************************** 394 | // Function : addToTrips 395 | // Process : Add the number to the list of trips 396 | // Used for optimized hand ranking 397 | // Notes : None 398 | // 399 | // Revision History: 400 | // 401 | // Date Author Description 402 | // 6.12.11 Donne Martin Added function 403 | //*************************************************************************** 404 | inline void Hand::addToTrips(const Card::CardNumber cardNumber) 405 | { 406 | this->trips.push_back(cardNumber); 407 | } // end Card::addToTrips 408 | 409 | //*************************************************************************** 410 | // Function : getCard 411 | // Process : Accessor for cards 412 | // Does not check if index 413 | // Notes : index must be valid 414 | // 415 | // Revision History: 416 | // 417 | // Date Author Description 418 | // 6.12.11 Donne Martin Added function 419 | //*************************************************************************** 420 | inline void Hand::getCard( 421 | const int index, 422 | Card& card) const 423 | { 424 | card = this->cards[index]; 425 | } // end Card::getCard 426 | 427 | //*************************************************************************** 428 | // Function : getCardNumber 429 | // Process : Get the card number associated with the card 430 | // Checks index for validity 431 | // Notes : None 432 | // 433 | // Revision History: 434 | // 435 | // Date Author Description 436 | // 6.12.11 Donne Martin Added function 437 | //*************************************************************************** 438 | inline Card::CardNumber Hand::getCardNumber(const int index) const 439 | { 440 | Card card; 441 | this->getCardSafe(index, card); 442 | 443 | return card.getNumber(); 444 | } // end Card::getCardNumber 445 | 446 | //*************************************************************************** 447 | // Function : getCards 448 | // Process : Accessor for cards 449 | // Notes : None 450 | // 451 | // Revision History: 452 | // 453 | // Date Author Description 454 | // 6.12.11 Donne Martin Added function 455 | //*************************************************************************** 456 | inline void Hand::getCards(vector& card) const 457 | { 458 | card = this->cards; 459 | } // end Card::getCards 460 | 461 | //*************************************************************************** 462 | // Function : getCardSuit 463 | // Process : Get the card suit associated with the card 464 | // Checks index for validity 465 | // Notes : None 466 | // 467 | // Revision History: 468 | // 469 | // Date Author Description 470 | // 6.12.11 Donne Martin Added function 471 | //*************************************************************************** 472 | inline Card::CardSuit Hand::getCardSuit(const int index) const 473 | { 474 | Card card; 475 | this->getCardSafe(index, card); 476 | 477 | return card.getSuit(); 478 | } // end Card::getCardSuit 479 | 480 | //*************************************************************************** 481 | // Function : getPairs 482 | // Process : Accessor for the list of pairs 483 | // Used for optimized hand ranking 484 | // Notes : None 485 | // 486 | // Revision History: 487 | // 488 | // Date Author Description 489 | // 6.12.11 Donne Martin Added function 490 | //*************************************************************************** 491 | inline void Hand::getPairs(vector& pairs) const 492 | { 493 | pairs = this->pairs; 494 | } // end Card::getPairs 495 | 496 | //*************************************************************************** 497 | // Function : getQuads 498 | // Process : Accessor for the list of quads 499 | // Used for optimized hand ranking 500 | // Notes : None 501 | // 502 | // Revision History: 503 | // 504 | // Date Author Description 505 | // 6.12.11 Donne Martin Added function 506 | //*************************************************************************** 507 | inline void Hand::getQuads(vector& quads) const 508 | { 509 | quads = this->quads; 510 | } // end Card::getQuads 511 | 512 | //*************************************************************************** 513 | // Function : getSingles 514 | // Process : Accessor for the list of singles 515 | // Used for optimized hand ranking 516 | // Notes : None 517 | // 518 | // Revision History: 519 | // 520 | // Date Author Description 521 | // 6.12.11 Donne Martin Added function 522 | //*************************************************************************** 523 | inline void Hand::getSingles(vector& singles) const 524 | { 525 | singles = this->singles; 526 | } // end Card::getSingles 527 | 528 | //*************************************************************************** 529 | // Function : getTrips 530 | // Process : Accessor for the list of trips 531 | // Used for optimized hand ranking 532 | // Notes : None 533 | // 534 | // Revision History: 535 | // 536 | // Date Author Description 537 | // 6.12.11 Donne Martin Added function 538 | //*************************************************************************** 539 | inline void Hand::getTrips(vector& trips) const 540 | { 541 | trips = this->trips; 542 | } // end Card::getTrips 543 | 544 | //*************************************************************************** 545 | // Function : getType 546 | // Process : Accessor for type 547 | // Notes : None 548 | // 549 | // Revision History: 550 | // 551 | // Date Author Description 552 | // 6.12.11 Donne Martin Added function 553 | //*************************************************************************** 554 | inline Hand::HandType Hand::getType() const 555 | { 556 | return this->type; 557 | } // end Card::getType 558 | 559 | //*************************************************************************** 560 | // Function : hasPairs 561 | // Process : Determines if the hand has pairs 562 | // Used for optimized hand ranking 563 | // Notes : None 564 | // 565 | // Revision History: 566 | // 567 | // Date Author Description 568 | // 6.12.11 Donne Martin Added function 569 | //*************************************************************************** 570 | inline bool Hand::hasPairs() const 571 | { 572 | bool hasPairs = false; 573 | 574 | if (this->pairs.size() > 0) 575 | { 576 | hasPairs = true; 577 | } 578 | 579 | return hasPairs; 580 | } // end Card::hasPairs 581 | 582 | //*************************************************************************** 583 | // Function : hasQuads 584 | // Process : Determines if the hand has quads 585 | // Used for optimized hand ranking 586 | // Notes : None 587 | // 588 | // Revision History: 589 | // 590 | // Date Author Description 591 | // 6.12.11 Donne Martin Added function 592 | //*************************************************************************** 593 | inline bool Hand::hasQuads() const 594 | { 595 | bool hasQuads = false; 596 | 597 | if (this->quads.size() > 0) 598 | { 599 | hasQuads = true; 600 | } 601 | 602 | return hasQuads; 603 | } // end Card::hasQuads 604 | 605 | //*************************************************************************** 606 | // Function : hasTrips 607 | // Process : Determines if the hand has trips 608 | // Used for optimized hand ranking 609 | // Notes : None 610 | // 611 | // Revision History: 612 | // 613 | // Date Author Description 614 | // 6.12.11 Donne Martin Added function 615 | //*************************************************************************** 616 | inline bool Hand::hasTrips() const 617 | { 618 | bool hasTrips = false; 619 | 620 | if (this->trips.size() > 0) 621 | { 622 | hasTrips = true; 623 | } 624 | 625 | return hasTrips; 626 | } // end Card::hasTrips 627 | 628 | //*************************************************************************** 629 | // Function : hasSingles 630 | // Process : Determines if the hand has singles 631 | // Used for optimized hand ranking 632 | // Notes : None 633 | // 634 | // Revision History: 635 | // 636 | // Date Author Description 637 | // 6.12.11 Donne Martin Added function 638 | //*************************************************************************** 639 | inline bool Hand::hasSingles() const 640 | { 641 | bool hasSingles = false; 642 | 643 | if (this->singles.size() > 0) 644 | { 645 | hasSingles = true; 646 | } 647 | 648 | return hasSingles; 649 | } // end Card::hasSingles 650 | 651 | //*************************************************************************** 652 | // Function : isValidCardIndex 653 | // Process : Determine if the card index is valid (within range) 654 | // Notes : None 655 | // 656 | // Revision History: 657 | // 658 | // Date Author Description 659 | // 6.12.11 Donne Martin Added function 660 | //*************************************************************************** 661 | inline bool Hand::isValidCardIndex(const int index) const 662 | { 663 | bool isValid = false; // determines if the card is valid 664 | 665 | if (index < Hand::MAXCARDS) 666 | { 667 | isValid = true; 668 | } 669 | 670 | return isValid; 671 | } // end Card::isValidCardIndex 672 | 673 | //*************************************************************************** 674 | // Function : setCards 675 | // Process : Mutator for cards 676 | // Optionally sorts the cards (default to true) 677 | // Notes : None 678 | // 679 | // Revision History: 680 | // 681 | // Date Author Description 682 | // 6.12.11 Donne Martin Added function 683 | //*************************************************************************** 684 | inline void Hand::setCards(const vector& cards, bool sort) 685 | { 686 | this->cards = cards; 687 | 688 | if (sort) 689 | { 690 | this->sortCards(); 691 | } 692 | } // end Card::setCards 693 | 694 | //*************************************************************************** 695 | // Function : setType 696 | // Process : Mutator for type 697 | // Notes : None 698 | // 699 | // Revision History: 700 | // 701 | // Date Author Description 702 | // 6.12.11 Donne Martin Added function 703 | //*************************************************************************** 704 | inline void Hand::setType(Hand::HandType type) 705 | { 706 | this->type = type; 707 | } // end Card::setType 708 | 709 | //*************************************************************************** 710 | // Function : sortCards 711 | // Process : Cards utility function 712 | // Sort the cards based on their CardNumber (low to high) 713 | // Notes : None 714 | // 715 | // Revision History: 716 | // 717 | // Date Author Description 718 | // 6.12.11 Donne Martin Added function 719 | //*************************************************************************** 720 | inline void Hand::sortCards() 721 | { 722 | sort(this->cards.begin(), this->cards.end()); 723 | } // end Card::sortCards 724 | 725 | //*************************************************************************** 726 | // Function : sortPairs 727 | // Process : Sort the list of pairs 728 | // Used for optimized hand ranking 729 | // Notes : None 730 | // 731 | // Revision History: 732 | // 733 | // Date Author Description 734 | // 6.12.11 Donne Martin Added function 735 | //*************************************************************************** 736 | inline void Hand::sortPairs() 737 | { 738 | sort(this->pairs.begin(), this->pairs.end()); 739 | } // end Card::sortPairs 740 | 741 | //*************************************************************************** 742 | // Function : sortQuads 743 | // Process : Sort the list of pairs 744 | // Used for optimized hand ranking 745 | // Notes : None 746 | // 747 | // Revision History: 748 | // 749 | // Date Author Description 750 | // 6.12.11 Donne Martin Added function 751 | //*************************************************************************** 752 | inline void Hand::sortQuads() 753 | { 754 | sort(this->quads.begin(), this->quads.end()); 755 | } // end Card::sortQuads 756 | 757 | //*************************************************************************** 758 | // Function : sortSingles 759 | // Process : Sort the list of pairs 760 | // Used for optimized hand ranking 761 | // Notes : None 762 | // 763 | // Revision History: 764 | // 765 | // Date Author Description 766 | // 6.12.11 Donne Martin Added function 767 | //*************************************************************************** 768 | inline void Hand::sortSingles() 769 | { 770 | sort(this->singles.begin(), this->singles.end()); 771 | } // end Card::sortSingles 772 | 773 | //*************************************************************************** 774 | // Function : sortTrips 775 | // Process : Sort the list of pairs 776 | // Used for optimized hand ranking 777 | // Notes : None 778 | // 779 | // Revision History: 780 | // 781 | // Date Author Description 782 | // 6.12.11 Donne Martin Added function 783 | //*************************************************************************** 784 | inline void Hand::sortTrips() 785 | { 786 | sort(this->trips.begin(), this->trips.end()); 787 | } // end Card::sortTrips 788 | 789 | #endif // Hand_h --------------------------------------------------------------------------------