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 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
|
#include "stdafx.h"
#include <iostream>
#include <ctime>
#include <string>
#include <cmath>
#include <cstdlib>
#include <fstream>
#include <cctype>
using namespace std;
short convert_value(string value); //converts card face to a value, 2=2, jack=11, king=13 etc.
bool straight(short value[]); //checks if cards make a straight
bool same_suit(string suit[]);//checks if cards make a flush
void check(bool& four, bool& three, bool& pair, bool& two_pair, short combos[], short& size); //checks if cards make 3 of a kind, pairs, etc.
void xx(short value[], short num_of_combos[], short& size);//checks for multiple occurences or something, dont really know, given to me by partner
int _tmain(int argc, _TCHAR* argv[])
{
srand(time(NULL));
string cardval[13];
cardval[0]="A";
cardval[1]="2";
cardval[2]="3";
cardval[3]="4";
cardval[4]="5";
cardval[5]="6";
cardval[6]="7";
cardval[7]="8";
cardval[8]="9";
cardval[9]="10";
cardval[10]="J";
cardval[11]="Q";
cardval[12]="K";
string suit[4];
suit[0]="H";
suit[1]="D";
suit[2]="C";
suit[3]="S";
string card1val=cardval[rand()%13];
string card1suit=suit[rand()%4];
string card2val=cardval[rand()%13];
string card2suit=suit[rand()%4];
string card3val=cardval[rand()%13];
string card3suit=suit[rand()%4];
string card4val=cardval[rand()%13];
string card4suit=suit[rand()%4];
string card5val=cardval[rand()%13];
string card5suit=suit[rand()%4];
cout<<card1val<<" "<<card1suit<<endl;
cout<<card2val<<" "<<card2suit<<endl;
cout<<card3val<<" "<<card3suit<<endl;
cout<<card4val<<" "<<card4suit<<endl;
cout<<card5val<<" "<<card5suit<<endl;
int x1=convert_value(card1val);
int x2=convert_value(card2val);
int x3=convert_value(card3val);
int x4=convert_value(card4val);
int x5=convert_value(card5val);
short value[]={x2,x2,x3,x4,x5};
cout<<value[2]<<endl;
short combos[5], size(0);
xx(value, combos, size);
bool pair(false), two_pair(false), three(false), four(false);
check(four, three, pair, two_pair, combos, size);
bool is_straight=straight(value);
bool is_same=same_suit(suit);
if(is_same && is_straight)
{
cout << "Straight Flush\n\n";
}
else if(is_straight)
{
cout << "Straight\n\n";
}
else if(four)
{
cout << "Four of a kind\n\n";
}
else if(three)
{
cout<<"Three of a kind\n\n";
}
else if(three && pair)
{
cout << "Full House\n\n";
}
else if(is_same)
{
cout << "Flush\n\n";
}
else if(two_pair)
{
cout << "Two pair\n\n";
}
else if(pair)
{
cout << "Pair\n\n";
}
else
{
cout << "No Winning Hand\n\n";
}
return 0;
}
short convert_value(string value)
{
if(value == "2")
{
return 2;
}
else if(value == "3")
{
return 3;
}
else if(value == "4")
{
return 4;
}
else if(value == "5")
{
return 5;
}
else if(value == "6")
{
return 6;
}
else if(value == "7")
{
return 7;
}
else if(value == "8")
{
return 8;
}
else if(value == "9")
{
return 9;
}
else if(value == "10")
{
return 10;
}
else if(value == "Q")
{
return 11;
}
else if(value == "J")
{
return 12;
}
else if(value == "K")
{
return 13;
}
else//(value == "A")
{
return 14;
}
}
bool straight(short value[])
{
short min = value[0];
for(short i = 1; i < 5; i++)
{
if(value[i] < min)
{
min = value[i];
}
}
short next = min + 1;
short i = 0;
while(i < 5)
{
if(value[i] == next)
{
next++;
i=0;
}
else
{
i++;
}
}
if(next == (min+5))
{
return true;
}
else
{
return false;
}
}
bool same_suit(string suit[])
{
string test=suit[0];
for(short i=1; i<5; i++)
{
if(test!=suit[i])
{
return false;
}
}
return true;
}
void check(bool& four, bool& three, bool& pair, bool& two_pair, short combos[], short& size)
{
short pairs(0), threes(0), fours(0);
for(short i = 0; i < size; i++)
{
if(combos[i] == 2)
{
pairs++;
}
if(combos[i] == 3)
{
three = true;
}
if(combos[i] == 4)
{
four = true;
}
}
if(pairs == 2)
{
two_pair = true;
}
else if(pairs == 1)
{
pair = true;
}
return;
}
void xx(short value[], short combos[], short& size)
{
short k = 0;
short count;
bool encountered[] = {false, false, false, false, false};
for(short i = 0; i < 5; i++)
{
if(!encountered[i])
{
size++;
encountered[i] = true;
count = 1;
for(short j = 1; j < 5; j++)
{
if((!encountered[j]) && (value[i] == value[j]))
{
encountered[j] = true;
count++;
}
}
combos[k] = count;
k++;
}
}
return;
}
|