#include %26lt;iostream%26gt;//input/output
#include %26lt;fstream%26gt;//file input/output
#include %26lt;string%26gt;//allows use of string variables
#include %26lt;time.h%26gt;//critical in generating random number
using namespace std;
void Load();
void clear();
void Bet();
bool Valid(int, int, int); //Generic int validity tester
void Generate(int); //Generates values of the cards dealt
void Hand(int); //Determines what hand the players have
void WhichCards(int, int, int, int, int, int, int%26amp;, int%26amp;); //After the hand is determined, this func tells the user what cards are winners
void AI(); //Gives the CPU a cardplaying brain
void SglGen(int, int); //Generates single card out of hand
void CardBuilder(int); //Prints out hand of card
void Advice(); //Gives advice basically using the AI engine
void Replace(); //Determines if user wishes to trade in a card and if so executes
void Sort(int); //Puts card values in order
void Decision(); //Decides who wins
void Shuffle(); //Resets values of Cards array
void Save();
char ValChars[15] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'X', 'J', 'Q', 'K', 'A'}; //This array stores the visual value of each card value for when it's printed out in CardBuilder and Hand
char Cards[15][4];//This array keeps track if a card has been taken from the deck or not
string Anything; //My dummy variable that I use to pause the program
string SuitS[4] = {"Hearts", "Diamonds", "Spades", "Clubs"}; // This array stores the suits names to be able to match and print them later in CardBuilder
int PCs[2][5][2]; //First dim is PLAYER/CPU, second dim is which card, third dim is Value/Suit
int Hnd[2] = {NULL, NULL}; //Keeps track of what hand each player has
int HndVal[2] = {NULL, NULL}; //Keeps value of specific hands (ie. "a pair of what?")
bool AIDone = false;//Makes sure that each players hand won't be exposed before AI is done
bool AdviceOn = false;//Determines whether or not Advice should be called
bool AdvDone = true;//Makes sure that each players hand won't be exposed before Advice is done
bool BettingOn = false;
int Wins = 0;
int Losses = 0;
int Chips = 5000;
int Wager = 0;
int main()
{
//----------------------------------
bool Done = true;
char Reply = NULL;// play again? reply
char AdRep = NULL;// advice reply
char LRep = NULL;// load reply
char SRep = NULL;// save reply
char BRep = NULL;// betting reply
cout %26lt;%26lt; "WELCOME TO THE NEW AND GREATLY IMPROVED" %26lt;%26lt; endl %26lt;%26lt; " FIVE CARD DRAW POKER!" %26lt;%26lt; endl;
cout %26lt;%26lt; endl %26lt;%26lt; " NEW FEATURES: AI, Record Keeping, Advice, and Betting " %26lt;%26lt; endl %26lt;%26lt; endl;
cout %26lt;%26lt; "Poker 3.3 is a one player game." %26lt;%26lt; endl;
cout %26lt;%26lt; endl %26lt;%26lt; " ** NOTE: X represents 10 ** " %26lt;%26lt; endl %26lt;%26lt; endl;
cout %26lt;%26lt; "Do you wish to enable betting? (Y or N)" %26lt;%26lt; endl;
cin %26gt;%26gt; BRep;
if(toupper(BRep) == 'Y')
BettingOn = true;
cout %26lt;%26lt; "Do you wish to load W/L record? (Y or N)" %26lt;%26lt; endl;
cin %26gt;%26gt; LRep;
if(toupper(LRep) == 'Y')
{
Load();
cout %26lt;%26lt; endl %26lt;%26lt; " Your current record is " %26lt;%26lt; Wins %26lt;%26lt; " / " %26lt;%26lt; Losses %26lt;%26lt; endl;
}
cout %26lt;%26lt; endl %26lt;%26lt; "Do you wish to play with advice turned on?(Y or N)" %26lt;%26lt; endl;
cin %26gt;%26gt; AdRep;
if(toupper(AdRep) == 'Y')
AdviceOn = true;
do
{
SRep = NULL;
Reply = NULL;
AIDone = false;
AdvDone = false;
cout %26lt;%26lt; "Press return to continue.";
getline(cin, Anything);
if(BettingOn)
Bet();
clear();
Generate(1); //CPU is given it's cards
cout %26lt;%26lt; endl %26lt;%26lt; " Your current record is " %26lt;%26lt; Wins %26lt;%26lt; " / " %26lt;%26lt; Losses %26lt;%26lt; endl;
cout %26lt;%26lt; "PLAYER's cards" %26lt;%26lt; endl;
Generate(0); //Player is given their cards
Hand(1); //CPU's hand is judged
AI(); //Based on that judgement, CPU swaps out cards
Hand(0); //Player's hand is judged
cout %26lt;%26lt; " Card# Card# Card# Card# Card#" %26lt;%26lt; endl;
cout %26lt;%26lt; " 1. 2. 3. 4. 5." %26lt;%26lt; endl;
CardBuilder(0);//Player's cards are printed
if(AdviceOn)
Advice();//Gives player advice if they asked for it
AdvDone = true;
Replace();//Asks player if they want to replace any of their cards and does so
Hand(0);//Player's hand is judged again
cout %26lt;%26lt; "CPU's cards" %26lt;%26lt; endl;
Sort(1);//CPU cards are put in order by value (ex. 4,6,8,K,A)
CardBuilder(1); //CPU's cards are printed
Hand(1);//CPU's hand is judged again
Decision();//Winner is declared
Shuffle();//Cards array is cleared
cout %26lt;%26lt; "Press return to shuffle and continue.";
getline(cin, Anything);
clear();
cout %26lt;%26lt; "Do you wish to play again?(Y or N)" %26lt;%26lt; endl;
cin %26gt;%26gt; Reply;
if(toupper(Reply) == 'Y')
Done = false;
else if(toupper(Reply) == 'N')
{
Done = true;
if(BettingOn)
cout %26lt;%26lt; "Do you wish to save W/L record and chips?" %26lt;%26lt; endl;
else
cout %26lt;%26lt; "Do you wish to save W/L record?" %26lt;%26lt; endl;
cin %26gt;%26gt; SRep;
if(toupper(SRep) == 'Y')
Save();
cout %26lt;%26lt; "Thanks for playing!!" %26lt;%26lt; endl;
}
else
cout %26lt;%26lt; "Since you cannot enter a correct response, please close the program" %26lt;%26lt; endl;
}while(!Done);
//----------------------------------
return 0;
}
void Load()
{
ifstream InFile;
if(BettingOn)
{
InFile.open("Poker.dat");
InFile %26gt;%26gt; Wins %26gt;%26gt; Losses %26gt;%26gt; Chips;
InFile.close();
if(Chips == 0)
Chips = 5000;
}
else
{
InFile.open("Poker.dat");
InFile %26gt;%26gt; Wins %26gt;%26gt; Losses;
InFile.close();
}
}
void clear()
{
cout %26lt;%26lt; endl %26lt;%26lt; endl %26lt;%26lt; endl %26lt;%26lt; endl %26lt;%26lt; endl %26lt;%26lt; endl %26lt;%26lt; endl %26lt;%26lt; endl %26lt;%26lt; endl %26lt;%26lt; endl
%26lt;%26lt; endl %26lt;%26lt; endl %26lt;%26lt; endl %26lt;%26lt; endl %26lt;%26lt; endl %26lt;%26lt; endl %26lt;%26lt; endl %26lt;%26lt; endl %26lt;%26lt; endl %26lt;%26lt; endl
%26lt;%26lt; endl %26lt;%26lt; endl %26lt;%26lt; endl %26lt;%26lt; endl %26lt;%26lt; endl %26lt;%26lt; endl %26lt;%26lt; endl %26lt;%26lt; endl %26lt;%26lt; endl %26lt;%26lt; endl;
}
void Bet()
{
clear();
if(Chips %26lt;= 0)
{
cout %26lt;%26lt; "You are BANKRUPT!!!" %26lt;%26lt; endl
%26lt;%26lt; "Do not despair though... you can continue" %26lt;%26lt; endl
%26lt;%26lt; "playing with betting turned off." %26lt;%26lt; endl
%26lt;%26lt; "PRESS RETURN TO CONTINUE" %26lt;%26lt; endl;
getline(cin, Anything);
BettingOn = false;
}
else
{
do
{
cout %26lt;%26lt; "You currently have $" %26lt;%26lt; Chips %26lt;%26lt; endl
%26lt;%26lt; "Please place your wager" %26lt;%26lt; endl;
cin %26gt;%26gt; Wager;
}while(!Valid(Wager, Chips, 0));
}
}
bool Valid(int tester, int High, int Low)
{
if(Low %26lt;= tester %26amp;%26amp; tester %26lt;= High)
return true;
cout %26lt;%26lt; endl %26lt;%26lt; " ***Please enter a valid response***" %26lt;%26lt; endl %26lt;%26lt; endl;
return false;
}
void Generate(int Player)
{
bool CardTaken;
int C;
int CurVal;
int CurSuit;
srand(time(NULL));
CardTaken = true;
for(C = 0; C %26lt; 5; C++)
{
do
{
PCs[Player][C][0] = (rand() % 13) + 2;
PCs[Player][C][1] = (rand() % 4);
CurVal = PCs[Player][C][0];
CurSuit = PCs[Player][C][1];
if(Cards[CurVal][CurSuit] == 'X')
CardTaken = true;
else
CardTaken = false;
}
while(CardTaken || PCs[Player][C][0] %26gt; 14);
Cards[CurVal][CurSuit] = 'X';
}
}
void Hand(int Player)
{
bool Group1 = false, Group2 = false;
Sort(Player); //Prevents me from having to write out every possibility later. Finds high card.
int CV1 = PCs[Player][0][0];
int CV2 = PCs[Player][1][0];
int CV3 = PCs[Player][2][0];
int CV4 = PCs[Player][3][0];
int CV5 = PCs[Player][4][0];
int SV1 = PCs[Player][0][1];
int SV2 = PCs[Player][1][1];
int SV3 = PCs[Player][2][1];
int SV4 = PCs[Player][3][1];
int SV5 = PCs[Player][4][1];
int WC1 = NULL;
int WC2 = NULL;
Hnd[Player] = 0;
if(CV1 == CV2 || CV2 == CV3 || CV3 == CV4 || CV4 == CV5)
{//One pair
Group1 = true;
Hnd[Player] = 1;
if(CV1 == CV2 %26amp;%26amp; CV3 == CV4 || CV1 == CV2 %26amp;%26amp; CV4 == CV5 || CV2 == CV3 %26amp;%26amp; CV4 == CV5)//Two pair
Hnd[Player] = 2;
if(CV1 == CV2 %26amp;%26amp; CV1 == CV3 || CV2 == CV3 %26amp;%26amp; CV2 == CV4 || CV3 == CV4 %26amp;%26amp; CV3 == CV5)//Three of a kind
Hnd[Player] = 3;
if(CV1 == CV2 %26amp;%26amp; CV3 == CV4 %26amp;%26amp; CV3 == CV5 || CV1 == CV2 %26amp;%26amp; CV1 == CV3 %26amp;%26amp; CV4 == CV5)//Full House
Hnd[Player] = 6;
if(CV1 == CV2 %26amp;%26amp; CV1 == CV3 %26amp;%26amp; CV1 == CV4 || CV2 == CV3 %26amp;%26amp; CV2 == CV4 %26amp;%26amp; CV2 == CV5)//Four of a kind
Hnd[Player] = 7;
}
if(!Group1)
{
Group2 = true;
if(CV1 == CV2 - 1 %26amp;%26amp; CV2 == CV3 - 1 %26amp;%26amp; CV3 == CV4 - 1 %26amp;%26amp; CV4 == CV5 - 1)
{//Straight
Hnd[Player] = 4;
if(SV1 == SV2 %26amp;%26amp; SV1 == SV3 %26amp;%26amp; SV1 == SV4 %26amp;%26amp; SV1 == SV5)
{//Straight Flush
Hnd[Player] = 8;
if(CV5 == 14)//Royal Flush
Hnd[Player] = 9;
}
}
else if(SV1 == SV2 %26amp;%26amp; SV1 == SV3 %26amp;%26amp; SV1 == SV4 %26amp;%26amp; SV1 == SV5)//Flush
Hnd[Player] = 5;
}
if(!Group1 %26amp;%26amp; !Group2)//High Card
Hnd[Player] = 0;
WhichCards(Player, CV1, CV2, CV3, CV4, CV5, WC1, WC2);
if(AIDone %26amp;%26amp; AdvDone)
{
switch(Player)
{
case 0:cout %26lt;%26lt; "PLAYER has ";
break;
case 1: cout %26lt;%26lt; "CPU has ";
break;
}
switch(Hnd[Player])
{
case 0: cout %26lt;%26lt; "A HIGH CARD OF " %26lt;%26lt; ValChars[HndVal[Player]] %26lt;%26lt; endl;
break;
case 1: cout %26lt;%26lt; "A PAIR OF " %26lt;%26lt; ValChars[HndVal[Player]] %26lt;%26lt; "'s" %26lt;%26lt; endl;
break;
case 2: cout %26lt;%26lt; "TWO PAIR " %26lt;%26lt; ValChars[WC1] %26lt;%26lt; "'s and " %26lt;%26lt; ValChars[WC2] %26lt;%26lt; "'s" %26lt;%26lt; endl;
break;
case 3: cout %26lt;%26lt; "THREE OF A KIND " %26lt;%26lt; ValChars[HndVal[Player]] %26lt;%26lt; "'s" %26lt;%26lt; endl;
break;
case 4: cout %26lt;%26lt; "A STRAIGHT " %26lt;%26lt; ValChars[CV1] %26lt;%26lt; " thru " %26lt;%26lt; ValChars[CV5] %26lt;%26lt; endl;
break;
case 5: cout %26lt;%26lt; "A FLUSH " %26lt;%26lt; SuitS[SV1] %26lt;%26lt; endl;
break;
case 6: cout %26lt;%26lt; "A FULL HOUSE " %26lt;%26lt; ValChars[WC1] %26lt;%26lt; "'s and " %26lt;%26lt; ValChars[WC2] %26lt;%26lt; "'s" %26lt;%26lt; endl;
break;
case 7: cout %26lt;%26lt; "FOUR OF A KIND " %26lt;%26lt; ValChars[HndVal[Player]] %26lt;%26lt; "'s" %26lt;%26lt; endl;
break;
case 8: cout %26lt;%26lt; "STRAIGHT FLUSH " %26lt;%26lt; ValChars[CV1] %26lt;%26lt; " thru " %26lt;%26lt; ValChars[CV5] %26lt;%26lt; " of " %26lt;%26lt; SuitS[SV1] %26lt;%26lt; endl;
break;
case 9: cout %26lt;%26lt; "ROYAL FLUSH " %26lt;%26lt; ValChars[CV1] %26lt;%26lt; " thru " %26lt;%26lt; ValChars[CV5] %26lt;%26lt; " of " %26lt;%26lt; SuitS[SV1] %26lt;%26lt; endl;
break;
}
cout %26lt;%26lt; endl;
}
}
void WhichCards(int Player, int Card1, int Card2, int Card3, int Card4, int Card5, int%26amp; WinC1, int%26amp; WinC2)
{
if(Hnd[Player] == 0)//High Card
HndVal[Player] = Card5;
if(Hnd[Player] == 1)// Pair
{
if(Card1 == Card2)
HndVal[Player] = Card1;
if(Card2 == Card3)
HndVal[Player] = Card2;
if(Card3 == Card4)
HndVal[Player] = Card3;
if(Card4 == Card5)
HndVal[Player] = Card4;
}
if(Hnd[Player] == 2)// Two Pair
{
if(Card1 == Card2 %26amp;%26amp; Card3 == Card4)
{
HndVal[Player] = Card1 + Card3;
WinC1 = Card1;
WinC2 = Card3;
}
if(Card1 == Card2 %26amp;%26amp; Card4 == Card5)
{
HndVal[Player] = Card1 + Card4;
WinC1 = Card1;
WinC2 = Card4;
}
if(Card2 == Card3 %26amp;%26amp; Card4 == Card5)
{
HndVal[Player] = Card2 + Card4;
WinC1 = Card2;
WinC2 = Card4;
}
}
if(Hnd[Player] == 3)// Three of a Kind
{
if(Card1 == Card2 %26amp;%26amp; Card1 == Card3)
HndVal[Player] = Card1;
if(Card2 == Card3 %26amp;%26amp; Card2 == Card4)
HndVal[Player] = Card2;
if(Card3 == Card4 %26amp;%26amp; Card3 == Card5)
HndVal[Player] = Card3;
}
if(Hnd[Player] == 4)// Straight
HndVal[Player] = Card5;
//One for flush not needed
if(Hnd[Player] == 6)//Full House
{
WinC1 = Card1;
WinC2 = Card5;
HndVal[Player] = Card1 + Card5;
}
if(Hnd[Player] == 7)//Four of a Kind
{
if(Card1 == Card2 %26amp;%26amp; Card1 == Card3 %26amp;%26amp; Card1 == Card4)
HndVal[Player] = Card1;
if(Card2 == Card3 %26amp;%26amp; Card2 == Card4 %26amp;%26amp; Card2 == Card5)
HndVal[Player] = Card2;
}//Straight flush unnecessary
//Royal Flush unnecessary
}
void AI()
{
int CV1 = PCs[1][0][0];
int SV1 = PCs[1][0][1];
int CV2 = PCs[1][1][0];
int SV2 = PCs[1][1][1]; //Sets the values and suit of each card for easier readability in later code
int CV3 = PCs[1][2][0];
int SV3 = PCs[1][2][1];
int CV4 = PCs[1][3][0];
int SV4 = PCs[1][3][1];
int CV5 = PCs[1][4][0];
int SV5 = PCs[1][4][1];
AIDone = true;
Sort(1);
if(Hnd[1] == 0)
{
if(Hnd[1] == 0 %26amp;%26amp; SV1 == SV2 %26amp;%26amp; SV1 == SV3 %26amp;%26amp; SV1 == SV4)// Go for flush
SglGen(1, 4);
else if(Hnd[1] == 0 %26amp;%26amp; SV1 == SV2 %26amp;%26amp; SV1 == SV3 %26amp;%26amp; SV1 == SV5)// Go for flush
SglGen(1, 3);
else if(Hnd[1] == 0 %26amp;%26amp; SV1 == SV2 %26amp;%26amp; SV1 == SV4 %26amp;%26amp; SV1 == SV5)// Go for flush
SglGen(1, 2);
else if(Hnd[1] == 0 %26amp;%26amp; SV1 == SV3 %26amp;%26amp; SV1 == SV4 %26amp;%26amp; SV1 == SV5)// Go for flush
SglGen(1, 1);
else if(Hnd[1] == 0 %26amp;%26amp; SV2 == SV3 %26amp;%26amp; SV2 == SV4 %26amp;%26amp; SV2 == SV5)// Go for flush
SglGen(1, 0);
else if(Hnd[1] == 0 %26amp;%26amp; CV5 == CV4 + 1 %26amp;%26amp; CV4 == CV3 + 1 %26amp;%26amp; CV3 == CV2 + 1) // Go for straight
SglGen(1, 0);
else if(Hnd[1] == 0 %26amp;%26amp; CV4 == CV3 + 1 %26amp;%26amp; CV3 == CV2 + 1 %26amp;%26amp; CV2 == CV1 + 1) // Go for straight
SglGen(1, 4);
else if(Hnd[1] == 0 %26amp;%26amp; HndVal[1] %26gt;= 10) // Keeps top card
{
SglGen(1, 3);
SglGen(1, 2);
SglGen(1, 1);
SglGen(1, 0);
}
else if(Hnd[1] == 0)
Generate(1);
}
if(Hnd[1] == 1)//Replaces cards other than the pair
{
if(CV1 == CV2)
{
SglGen(1, 2);
SglGen(1, 3);
}
if(CV2 == CV3)
{
SglGen(1, 0);
SglGen(1, 3);
}
if(CV3 == CV4)
{
SglGen(1, 0);
SglGen(1, 1);
}
if(CV4 == CV5)
{
SglGen(1, 0);
SglGen(1, 1);
SglGen(1, 2);
}
}
if(Hnd[1] == 2)
{
if(CV1 == CV2 %26amp;%26amp; CV3 == CV4)
{
SglGen(1, 4);
}
if(CV2 == CV3 %26amp;%26amp; CV4 == CV5)
{
SglGen(1, 0);
}
}
if(Hnd[1] == 3)
{
if(CV1 == CV2 %26amp;%26amp; CV1 == CV3)
{
SglGen(1, 3);
SglGen(1, 4);
}
if(CV2 == CV3 %26amp;%26amp; CV2 == CV4)
{
SglGen(1, 0);
SglGen(1, 4);
}
if(CV3 == CV4 %26amp;%26amp; CV3 == CV5)
{
SglGen(1, 0);
SglGen(1, 1);
}
}
}
void SglGen(int Player, int CNum)
{
//When player or AI wants to swap out a card this function generates
// a card for them and makes sure that is not already taken from the "deck"
bool CardTaken;
int CurVal;
int CurSuit;
srand(time(NULL));
do
{
CardTaken = true;
PCs[Player][CNum][0] = (rand() % 13) + 2;
PCs[Player][CNum][1] = (rand() % 4);
CurVal = PCs[Player][CNum][0];
CurSuit = PCs[Player][CNum][1];
if(Cards[CurVal][CurSuit] == 'X')
CardTaken = true;
else
CardTaken = false;
}
while(CardTaken || PCs[Player][CNum][0] %26gt; 14);
Cards[CurVal][CurSuit] = 'X';
}
void CardBuilder(int Player)
{
int CV1 = PCs[Player][0][0];
int SV1 = PCs[Player][0][1];
int CV2 = PCs[Player][1][0];
int SV2 = PCs[Player][1][1]; //Sets the values and suit of each card for easier readability in later code
int CV3 = PCs[Player][2][0];
int SV3 = PCs[Player][2][1];
int CV4 = PCs[Player][3][0];
int SV4 = PCs[Player][3][1];
int CV5 = PCs[Player][4][0];
int SV5 = PCs[Player][4][1];
cout %26lt;%26lt; " --------- --------- --------- --------- --------- " %26lt;%26lt; endl;
cout %26lt;%26lt; "| | | | | | | | | |" %26lt;%26lt; endl;
cout %26lt;%26lt; "| | | | | | | | | |" %26lt;%26lt; endl;
cout %26lt;%26lt; "| " %26lt;%26lt; ValChars[CV1] %26lt;%26lt; " | | " %26lt;%26lt; ValChars[CV2] %26lt;%26lt; " | | " %26lt;%26lt; ValChars[CV3] %26lt;%26lt; " | | " %26lt;%26lt; ValChars[CV4] %26lt;%26lt; " | | " %26lt;%26lt; ValChars[CV5] %26lt;%26lt; " |" %26lt;%26lt; endl;
cout %26lt;%26lt; "| | | | | | | | | |" %26lt;%26lt; endl;
cout %26lt;%26lt; " " %26lt;%26lt; SuitS[SV1] %26lt;%26lt; " " %26lt;%26lt; SuitS[SV2] %26lt;%26lt; " " %26lt;%26lt; SuitS[SV3] %26lt;%26lt; " " %26lt;%26lt; SuitS[SV4] %26lt;%26lt; " " %26lt;%26lt; SuitS[SV5] %26lt;%26lt; endl;
cout %26lt;%26lt; " --------- --------- --------- --------- --------- " %26lt;%26lt; endl;
}
void Advice()
{
Sort(0);
int CV1 = PCs[0][0][0];
int SV1 = PCs[0][0][1];
int CV2 = PCs[0][1][0];
int SV2 = PCs[0][1][1]; //Sets the values and suit of each card for easier readability in later code
int CV3 = PCs[0][2][0];
int SV3 = PCs[0][2][1];
int CV4 = PCs[0][3][0];
int SV4 = PCs[0][3][1];
int CV5 = PCs[0][4][0];
int SV5 = PCs[0][4][1];
cout %26lt;%26lt; endl;
if(Hnd[0] == 0)
{
if(Hnd[0] == 0 %26amp;%26amp; SV1 == SV2 %26amp;%26amp; SV1 == SV3 %26amp;%26amp; SV1 == SV4)// Go for flush
cout %26lt;%26lt; "Go for the flush and swap the " %26lt;%26lt; ValChars[CV5] %26lt;%26lt; endl;
else if(Hnd[0] == 0 %26amp;%26amp; SV1 == SV2 %26amp;%26amp; SV1 == SV3 %26amp;%26amp; SV1 == SV5)// Go for flush
cout %26lt;%26lt; "Go for the flush and swap the " %26lt;%26lt; ValChars[CV4] %26lt;%26lt; endl;
else if(Hnd[0] == 0 %26amp;%26amp; SV1 == SV2 %26amp;%26amp; SV1 == SV4 %26amp;%26amp; SV1 == SV5)// Go for flush
cout %26lt;%26lt; "Go for the flush and swap the " %26lt;%26lt; ValChars[CV3] %26lt;%26lt; endl;
else if(Hnd[0] == 0 %26amp;%26amp; SV1 == SV3 %26amp;%26amp; SV1 == SV4 %26amp;%26amp; SV1 == SV5)// Go for flush
cout %26lt;%26lt; "Go for the flush and swap the " %26lt;%26lt; ValChars[CV2] %26lt;%26lt; endl;
else if(Hnd[0] == 0 %26amp;%26amp; SV2 == SV3 %26amp;%26amp; SV2 == SV4 %26amp;%26amp; SV2 == SV5)// Go for flush
cout %26lt;%26lt; "Go for the flush and swap the " %26lt;%26lt; ValChars[CV1] %26lt;%26lt; endl;
else if(Hnd[0] == 0 %26amp;%26amp; CV5 == CV4 + 1 %26amp;%26amp; CV4 == CV3 + 1 %26amp;%26amp; CV3 == CV2 + 1) // Go for straight
cout %26lt;%26lt; "Go for the straight and swap the " %26lt;%26lt; ValChars[CV1] %26lt;%26lt; endl;
else if(Hnd[0] == 0 %26amp;%26amp; CV4 == CV3 + 1 %26amp;%26amp; CV3 == CV2 + 1 %26amp;%26amp; CV2 == CV1 + 1) // Go for straight
cout %26lt;%26lt; "Go for the straight and swap the " %26lt;%26lt; ValChars[CV5] %26lt;%26lt; endl;
else if(Hnd[0] == 0 %26amp;%26amp; HndVal[0] %26gt;= 10) // Keep top card
cout %26lt;%26lt; "Swap out everything but the " %26lt;%26lt; ValChars[CV5] %26lt;%26lt; endl;
else if(Hnd[0] == 0)
cout %26lt;%26lt; "Just swap em all out" %26lt;%26lt; endl;
}
if(Hnd[0] == 1)//Replace cards other than the pair
{
if(CV1 == CV2)
cout %26lt;%26lt; "You should probably drop the " %26lt;%26lt; ValChars[CV3] %26lt;%26lt; " and the " %26lt;%26lt; ValChars[CV4] %26lt;%26lt; endl;
if(CV2 == CV3)
cout %26lt;%26lt; "You should probably drop the " %26lt;%26lt; ValChars[CV1] %26lt;%26lt; " and the " %26lt;%26lt; ValChars[CV4] %26lt;%26lt; endl;
if(CV3 == CV4)
cout %26lt;%26lt; "You should probably drop the " %26lt;%26lt; ValChars[CV1] %26lt;%26lt; " and the " %26lt;%26lt; ValChars[CV2] %26lt;%26lt; endl;
if(CV4 == CV5)
cout %26lt;%26lt; "You should probably drop the " %26lt;%26lt; ValChars[CV1] %26lt;%26lt; ", the " %26lt;%26lt; ValChars[CV2] %26lt;%26lt; " and the " %26lt;%26lt; ValChars[CV3] %26lt;%26lt; endl;
}
if(Hnd[0] == 2)// Two Pair
{
if(CV1 == CV2 %26amp;%26amp; CV3 == CV4)
cout %26lt;%26lt; "Drop the " %26lt;%26lt; ValChars[CV5] %26lt;%26lt; endl;
if(CV2 == CV3 %26amp;%26amp; CV4 == CV5)
cout %26lt;%26lt; "Drop the " %26lt;%26lt; ValChars[CV1] %26lt;%26lt; endl;
}
if(Hnd[0] == 3)//Three of a kind
{
if(CV1 == CV2 %26amp;%26amp; CV1 == CV3)
cout %26lt;%26lt; "Drop the " %26lt;%26lt; ValChars[CV4] %26lt;%26lt; " and the " %26lt;%26lt; ValChars[CV5] %26lt;%26lt; endl;
if(CV2 == CV3 %26amp;%26amp; CV2 == CV4)
cout %26lt;%26lt; "Drop the " %26lt;%26lt; ValChars[CV1] %26lt;%26lt; " and the " %26lt;%26lt; ValChars[CV5] %26lt;%26lt; endl;
if(CV3 == CV4 %26amp;%26amp; CV3 == CV5)
cout %26lt;%26lt; "Drop the " %26lt;%26lt; ValChars[CV1] %26lt;%26lt; " and the " %26lt;%26lt; ValChars[CV2] %26lt;%26lt; endl;
}
if(Hnd[0] %26gt;= 4)
cout %26lt;%26lt; "You want to keep this hand" %26lt;%26lt; endl;
cout %26lt;%26lt; endl;
}
void Replace()
{
char Reply = NULL;
bool RValid;
int Num, C, CardNum;
bool Swapped[6] = {true, false, false, false, false, false};//Used to make sure people don't try to swap the same card twice
RValid = false;
while(!RValid)
{
cout %26lt;%26lt; "Do you wish to replace any of your cards?" %26lt;%26lt; endl %26lt;%26lt; "Y(y) or N(n)" %26lt;%26lt; endl;
cin %26gt;%26gt; Reply;
cin.ignore(1, '/n');
if(toupper(Reply) == 'Y')
{
cout %26lt;%26lt; "How many cards do you wish to replace?" %26lt;%26lt; endl;
cin %26gt;%26gt; Num;
if(Num == 5)
Generate(0);
else
{
do{
cout %26lt;%26lt; "Which card(s) do you wish to replace? (Give the card #)" %26lt;%26lt; endl;
cin %26gt;%26gt; CardNum;
cin.ignore(1, '/n');
}while(!Valid(CardNum, 5, 1) %26amp;%26amp; Swapped[CardNum] == false);
Swapped[CardNum] = true;
SglGen(0, CardNum - 1);
for(C = 1; C %26lt; Num; C++)
{
do{
cout %26lt;%26lt; "and?" %26lt;%26lt; endl;
cin %26gt;%26gt; CardNum;
}while(!Valid(CardNum, 5, 1) %26amp;%26amp; Swapped[CardNum] == false);
Swapped[CardNum] = true;
SglGen(0, CardNum - 1);
}
}
RValid = true;
}
else if(toupper(Reply) == 'N')
RValid = true;
else
{
cout %26lt;%26lt; "Illegal reply. Try again." %26lt;%26lt; endl;
RValid = false;
}
}
Sort(0);
cout %26lt;%26lt; "Press return to continue.";
getline(cin, Anything);
clear();
cout %26lt;%26lt; "PLAYER's cards" %26lt;%26lt; endl;
CardBuilder(0);
}
void Sort(int Player)
{
int NTemp, STemp;
int C;
int CV1 = PCs[Player][0][0];
int CV2 = PCs[Player][1][0];
int CV3 = PCs[Player][2][0];//NEW overhaul of Sort
int CV4 = PCs[Player][3][0];//Before this version, the Sort was done using passed variables, but the
int CV5 = PCs[Player][4][0];//PCs array itself was never touched. Doing it this way there is ALOT less passing
int SV1 = PCs[Player][0][1];//the five cards' values, and so it's more efficent and neat than previously.
int SV2 = PCs[Player][1][1];
int SV3 = PCs[Player][2][1];
int SV4 = PCs[Player][3][1];
int SV5 = PCs[Player][4][1];
for(C = 0;C %26lt; 4; C++)
{
if(CV1 %26gt; CV2)
{
NTemp = CV1;
CV1 = CV2;
CV2 = NTemp;
STemp = SV1;
SV1 = SV2;
SV2 = STemp;
}
if(CV2 %26gt; CV3)
{
NTemp = CV2;
CV2 = CV3;
CV3 = NTemp;
STemp = SV2;
SV2 = SV3;
SV3 = STemp;
}
if(CV3 %26gt; CV4)
{
NTemp = CV3;
CV3 = CV4;
CV4 = NTemp;
STemp = SV3;
SV3 = SV4;
SV4 = STemp;
}
if(CV4 %26gt; CV5)
{
NTemp = CV4;
CV4 = CV5;
CV5 = NTemp;
STemp = SV4;
SV4 = SV5;
SV5 = STemp;
}
}
PCs[Player][0][0] = CV1;
PCs[Player][1][0] = CV2;
PCs[Player][2][0] = CV3;
PCs[Player][3][0] = CV4;
PCs[Player][4][0] = CV5;
PCs[Player][0][1] = SV1;
PCs[Player][1][1] = SV2;
PCs[Player][2][1] = SV3;
PCs[Player][3][1] = SV4;
PCs[Player][4][1] = SV5;
}
void Decision()
{
if(Hnd[0] %26gt; Hnd[1])
{
cout %26lt;%26lt; "PLAYER wins!!!!!" %26lt;%26lt; endl;
Wins++;
if(BettingOn)
{
cout %26lt;%26lt; "PLAYER wins $" %26lt;%26lt; Wager %26lt;%26lt; endl;
Chips = Chips + Wager;
}
}
else if(Hnd[0] %26lt; Hnd[1])
{
cout %26lt;%26lt; "CPU wins!!!!!" %26lt;%26lt; endl;
Losses++;
if(BettingOn)
{
cout %26lt;%26lt; "PLAYER loses $" %26lt;%26lt; Wager %26lt;%26lt; endl;
Chips = Chips - Wager;
}
}
else if(Hnd[0] == Hnd[1])
{
if(HndVal[0] %26gt; HndVal[1])
{
cout %26lt;%26lt; "PLAYER wins!!!!!" %26lt;%26lt; endl;
Wins++;
if(BettingOn)
{
cout %26lt;%26lt; "PLAYER wins $" %26lt;%26lt; Wager %26lt;%26lt; endl;
Chips = Chips + Wager;
}
}
else if(HndVal[0] %26lt; HndVal[1])
{
cout %26lt;%26lt; "CPU wins!!!!!" %26lt;%26lt; endl;
Losses++;
if(BettingOn)
{
cout %26lt;%26lt; "PLAYER loses $" %26lt;%26lt; Wager %26lt;%26lt; endl;
Chips = Chips - Wager;
}
}
else
cout %26lt;%26lt; "DRAW!!!!" %26lt;%26lt; endl;
}
}
void Shuffle()
{
int OC, IC;
for(OC = 0; OC %26lt; 15; OC++)
{
for(IC = 0; IC %26lt; 4; IC++)
Cards[OC][IC] = NULL;
}
}
void Save()
{
ofstream OutFile;
if(BettingOn)
{
OutFile.open("Poker.dat");
OutFile %26lt;%26lt; Wins %26lt;%26lt; " " %26lt;%26lt; Losses %26lt;%26lt; " " %26lt;%26lt; Chips;
OutFile.close();
}
else
{
OutFile.open("Poker.dat");
OutFile %26lt;%26lt; Wins %26lt;%26lt; " " %26lt;%26lt; Losses;
OutFile.close();
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment