first commit
[rofl0r-oopoker.git] / combination.h
blob88eb7894855a880831f52c7e327d304f3178e531
1 /*
2 OOPoker
4 Copyright (c) 2010 Lode Vandevenne
5 All rights reserved.
7 This file is part of OOPoker.
9 OOPoker is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 OOPoker is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with OOPoker. If not, see <http://www.gnu.org/licenses/>.
23 #pragma once
25 #include <vector>
26 #include <string>
27 #include <algorithm>
28 #include <iostream>
30 #include "card.h"
33 Combination:
34 Represents a combination of 5 cards, forming things like a pair, a flush, etc..
35 This file also has functions for checking which combination is formed by 5 or by 7 cards.
37 This contains a naive and slow 7-card hand evaluator, but has the advantage that
38 these functions can be used to check what combination a player has and to convert it to a name,
39 and to check which 5 cards are involved.
41 If you need to evaluate many of hands for combinations for a poker AI, then don't use
42 the functions from this file. Use eval7 from pokermath.h instead: that one can evaluate
43 millions of hands per second.
47 enum ComboType
49 C_HIGH_CARD,
50 C_PAIR,
51 C_TWO_PAIR,
52 C_THREE_OF_A_KIND,
53 C_STRAIGHT,
54 C_FLUSH,
55 C_FULL_HOUSE,
56 C_FOUR_OF_A_KIND,
57 C_STRAIGHT_FLUSH //includes royal flush
60 struct Combination
62 ComboType type;
65 the cards are the 5 cards involved in this combo, and they are sorted in the following order (depending on the type of combo):
66 Straight Flush: highest to lowest (Royal Flush: ace to 10)
67 Four of a kind: first the 4 cards of the same value, then the 5th card (color order unspecified)
68 Full House: first the 3 cards, then the 2 cards (color order unspecified)
69 Flush: highest to lowest
70 Straight: highest to lowest
71 Three of a kind: first the 3, then the highest other cards, then the lowest other card
72 Two Pair: first the 2 of the highest pair, then the two of the lowest pair, then the extra card
73 Pair: first the 2, then the other 3 sorted from highest to lowest
74 High card: highest to lowest
76 Card cards[5];
77 int cards_used; //this is normally 5, unless the combo was made out of less cards (e.g. three of a kind detected given 3 cards)
79 std::string getName() const;
80 std::string getNameWithAllCards() const;
81 std::string getNameWithAllCardsPrintable() const;
84 ////////////////////////////////////////////////////////////////////////////////
86 //only call after having checked all combinations
87 bool checkHighCard(Card result[5], const std::vector<Card>& sorted);
89 //only call after already having checked for better combinations (including two pairs, three of a kind, or other things that already contain a pair in them too)
90 bool checkPair(Card result[5], const std::vector<Card>& sorted);
92 //only call after already having checked for better combinations
93 bool checkTwoPair(Card result[5], const std::vector<Card>& sorted);
95 //only call after already having checked for better combinations (including full house, four of a kind, or other things that already contain a pair in them too)
96 bool checkThreeOfAKind(Card result[5], const std::vector<Card>& sorted);
98 //only call after already having checked for better combinations
99 bool checkStraight(Card result[5], const std::vector<Card>& sorted);
101 //only call after already having checked for better combinations
102 bool checkFlush(Card result[5], const std::vector<Card>& sorted);
104 //only call after already having checked for better combinations
105 bool checkFullHouse(Card result[5], const std::vector<Card>& sorted);
107 //only call after already having checked for better combinations
108 bool checkFourOfAKind(Card result[5], const std::vector<Card>& sorted);
110 //only call after already having checked for better combinations
111 bool checkStraightFlush(Card result[5], const std::vector<Card>& sorted);
113 ////////////////////////////////////////////////////////////////////////////////
115 //only call after already having checked for better combinations (including two pairs, three of a kind, or other things that already contain a pair in them too)
116 bool checkPair(const std::vector<Card>& sorted);
118 //only call after already having checked for better combinations
119 bool checkTwoPair(const std::vector<Card>& sorted);
121 //only call after already having checked for better combinations (including full house, four of a kind, or other things that already contain a pair in them too)
122 bool checkThreeOfAKind(const std::vector<Card>& sorted);
124 //only call after already having checked for better combinations
125 bool checkStraight(const std::vector<Card>& sorted);
127 //only call after already having checked for better combinations
128 bool checkFlush(const std::vector<Card>& sorted);
130 //only call after already having checked for better combinations
131 bool checkFullHouse(const std::vector<Card>& sorted);
133 //only call after already having checked for better combinations
134 bool checkFourOfAKind(const std::vector<Card>& sorted);
136 //only call after already having checked for better combinations
137 bool checkStraightFlush(const std::vector<Card>& sorted);
139 ////////////////////////////////////////////////////////////////////////////////
141 void sortCardsHighToLow(std::vector<Card>& cards);
143 ////////////////////////////////////////////////////////////////////////////////
146 Returns the best combo formed by the given cards. It doesn't matter how many
147 cards are given, but it must be at least 5.
149 void getCombo(Combination& combo, const std::vector<Card>& cards);
150 void getCombo(Combination& combo, const Card& card1, const Card& card2, const Card& card3, const Card& card4, const Card& card5);
152 //2 cards given by short names
153 void getCombo(Combination& combo
154 , const std::string& card1
155 , const std::string& card2);
156 //3 cards given by short names
157 void getCombo(Combination& combo
158 , const std::string& card1
159 , const std::string& card2
160 , const std::string& card3);
161 //4 cards given by short names
162 void getCombo(Combination& combo
163 , const std::string& card1
164 , const std::string& card2
165 , const std::string& card3
166 , const std::string& card4);
167 //5 cards given by short names
168 void getCombo(Combination& combo
169 , const std::string& card1
170 , const std::string& card2
171 , const std::string& card3
172 , const std::string& card4
173 , const std::string& card5);
174 //6 cards given by short names
175 void getCombo(Combination& combo
176 , const std::string& card1
177 , const std::string& card2
178 , const std::string& card3
179 , const std::string& card4
180 , const std::string& card5
181 , const std::string& card6);
182 //7 cards given by short names
183 void getCombo(Combination& combo
184 , const std::string& card1
185 , const std::string& card2
186 , const std::string& card3
187 , const std::string& card4
188 , const std::string& card5
189 , const std::string& card6
190 , const std::string& card7);
191 //string.size() / 2 cards given by short names combined in one string
192 void getCombo(Combination& combo, const std::string& cards);
195 //returns -1 if combo a is worth less than combo b, 0 if worth the same, 1 if combo a is worth more than combo b.
196 int compare(const Combination& a, const Combination& b);
198 bool combinationGreater(const Combination& a, const Combination& b);