-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathclassify.cpp
219 lines (201 loc) · 5.78 KB
/
classify.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
//Author: PlanckBit
//MIT License
//Copyright (c) 2019 PlanckBit
#include <iostream>
#include "cards.h"
#include "classify.h"
classify::classify(){
for(int i=hand; i<hand; i++) {
store_suit[i]=0;
store_rank[i]=0;
}
}
int classify::straight_flush() const {
int test=1; //test while loop condition
int k=0; //variable use for scanning elements of arrays
while(test!=0) {
if(k<hand-1 && store_rank[k]==((store_rank[k+1])-1)) {
if(store_suit[k]==store_suit[k+1]) {
++k;
}
else {
return 0; //no straight flush
}
}
else if(k==hand-1) {
return 1; //straight flush found
}
else {
test=0; //terminate the loop, no straight flush found
}
}
return 0; //no straight flush found by termination of loop
}
int classify::flush() const {
int test=1;
int k=0;
while(test!=0) {
if(store_suit[k]==store_suit[k+1] && k<hand-1) {
++k; //condition is true so continue loop
}
else if(k==hand-1) {
return 1; //flush found in hand
}
else {
test=0; //terminate the loop
}
}
return 0; //loop terminated on no flush found, so return 0
}
int classify::straight() const {
int test=1;
int k=0;
while(test!=0) {
if(k < hand-1 && store_rank[k]==((store_rank[k+1])-1)) {
++k; //continue loop
}
else if(k==hand-1) {
return 1; //a straight hand was found, return true
}
else {
test=0; //end loop, no straight hand found
}
}
return 0; //no straight hand found on termination of loop
}
int classify::four_kind() const {
int k=0;
if(store_rank[k]==store_rank[k+3] || store_rank[k+1]==store_rank[k+4]) {
return 1; //four of a kind was found in the hand
}
else {
return 0; //four of a kind was not found
}
}
int classify::full_house() const {
int k=0;
if((store_rank[k]==store_rank[k+1] && store_rank[k+2]==store_rank[k+4]) ||
(store_rank[k]==store_rank[k+2] && store_rank[k+3]==store_rank[k+4])) {
return 1; //full house found in hand
}
else {
return 0; //full house was not found
}
}
int classify::three_kind() const {
int k=0;
if(store_rank[k]==store_rank[k+2] || store_rank[k+1]==store_rank[k+3]) {
return 1; //three of a kind was found
}
else if(store_rank[k+2]==store_rank[k+4]) {
return 1; //three of a kind was found
}
else {
return 0; //three of a kind was not found
}
}
int classify::two_pair() const {
int k=0;
if(store_rank[k]==store_rank[k+1] && store_rank[k+2]==store_rank[k+3]) {
return 1; //two pair found
}
else if(store_rank[k]==store_rank[k+1] && store_rank[k+3]==store_rank[k+4]) {
return 1; //two pair found
}
else {
return 0;
}
}
int classify::one_pair() const {
int k=0;
if(store_rank[k]==store_rank[k+1] || store_rank[k+1]==store_rank[k+2]) {
return 1; //one pair found
}
else if(store_rank[k+2]==store_rank[k+3] || store_rank[k+3]==store_rank[k+4]) {
return 1; //one pair found
}
else {
return 0;
}
}
int classify::plain() const {
for(int k=0; k<hand-1; k++) {
if(store_rank[k]==store_rank[k+1] || flush()==1) {
return 0; //no plain found
}
}
return 1; //a plain hand was found
}
//Will print a hand in sorted order by rank
// the hand will never exceed 5 cards
void classify::print() const {
for(int j=0; j<hand; j++) {
int rank_card=store_rank[j];
int suit_card=store_suit[j];
switch(rank_card) {
case 0:
std::cout << "2"; break;
case 1:
std::cout << "3"; break;
case 2:
std::cout << "4"; break;
case 3:
std::cout << "5"; break;
case 4:
std::cout << "6"; break;
case 5:
std::cout << "7"; break;
case 6:
std::cout << "8"; break;
case 7:
std::cout << "9"; break;
case 8:
std::cout << "T"; break;
case 9:
std::cout << "J"; break;
case 10:
std::cout << "Q"; break;
case 11:
std::cout << "K"; break;
case 12:
std::cout << "A"; break;
}
switch(suit_card) {
case 0:
std::cout << "C" <<" "; break;
case 1:
std::cout << "D" <<" "; break;
case 2:
std::cout << "H" <<" "; break;
case 3:
std::cout << "S" <<" "; break;
}
}
}
//Will insert one card at a time, one for rank, one for suit
void classify::insert_card(cardRank r, cardSuit s, int i) {
//The card being stored must not exceed the hand which is 5 cards per hand
if (i<hand) {
store_rank[i]=r;
store_suit[i]=s;
}
}
//Will sort out the hand, by rank, the suit will also be sorted
// so that the elements correspond to each other.
void classify::sort_hand() {
//This will only sort a five card hand
for(int scan=1; scan<hand; scan++) {
for(int i=0; i< hand-scan; i++) {
if(store_rank[i] > store_rank[i+1]) {
//sorting the rank
int hold_rank=store_rank[i];
store_rank[i]=store_rank[i+1];
store_rank[i+1]=hold_rank;
//sorting the suit
int hold_suit=store_suit[i];
store_suit[i]=store_suit[i+1];
store_suit[i+1]=hold_suit;
}
}
}
}