Hey guys, noob programmer here. Over the last week or so we've been learning about classes and inheritance in my latest progamming class. I've recieved a variation of the ever so popular poker program and am having some problems putting it all together.
I haven't had the opportunity to test the logic because the program obviously isnt in a running state. The parts I KNOW I have a problem with are dealing from the vector, I just dont know the syntax to transfer it to myHand[]. I am also having problems with calling the functions in main another syntax problem for me im affraid.
****on another note im not sure if the clearHand() function has a purpose, I didn't know if it would be necesscary, and if it is, could use some help on that.
Card.h
#pragma once
#include<string>
#include<cstdlib>
using namespace std;
class Card
{
public:
Card();
string getSuit();
char suit[4];
int value[13];
int getRank();
private:
int rank;
Card.cpp
#include "Card.h"
#include <string>
Card::Card()
{
suit[4]=('c', 'h', 'd', 's');
value[13]=('1','2','3','4','5','6','7','8','9','10', '11','12','13');
}
string Card::getSuit()
{
return suit;
}
int Card::getRank()
{
return rank;
}
Hand.h
#pragma once
#include"Deck.h"
#include"Card.h"
#include <vector>
using namespace std;
class Hand
{
public:
vector<Card> myHand[4];
int totalFlush;
void clearHand();
bool checkHand(vector<Card>);
private:
};
Hand.cpp
#include "Hand.h"
#include "Card.h"
void Hand::clearHand()
{
}
bool Hand::checkHand(vector<Card>myHand)
{
// Check for a flush (all the same suit)
if(myHand[0].getSuit() == myHand[1].getSuit() && myHand[1].getSuit()==myHand[2].getSuit() && myHand[2].getSuit()==myHand[3].getSuit() && myHand[3].getSuit()==myHand[4].getSuit())
{
totalFlush++;
}
}
Deck.h
#pragma once
#include <vector>
#include"Card.h"
using namespace std;
class Deck
{
public:
Deck();
void createDeck(vector<Card>myDeck);
void createValue(vector<Card>myDeck);
void createSuit(vector<Card>myDeck);
void shuffleDeck(vector<Card>myDeck);
void dealCards();
vector<Card> myDeck;
private:
};
Deck.cpp
#include "Deck.h"
#include "Card.h"
#include<vector>
#include<algorithm>
Deck::Deck()
{
vector<Card> myDeck(52);
createDeck(myDeck);
}
void Deck::createValue(vector<Card>myDeck)
{
int x=0;
do
{
for(int i=0;i<13;i++)
{
myDeck[i].getRank=i;
}
x++;
}
while(x<3);
}
void Deck::createSuit(vector<Card>myDeck)
{
for(int i = 0; i<52; i++)
if (i<=12)
{
myDeck[i].getSuit='c';
}
else if (i<=25)
{
myDeck[i].getSuit='d';
}
else if (i<=38)
{
myDeck[i].getSuit='h';
}
else if (i<=51)
{
myDeck[i].getSuit='s';
}
}
void Deck::shuffleDeck(vector<Card>myDeck)
{
random_shuffle(myDeck.begin(), myDeck.end());
}
void Deck::dealCards()
{
}
Main.cpp
include <iostream>
#include <stdlib.h>
#include <time.h>
#include "Deck.h"
#include "Card.h"
#include "Hand.h"
using namespace std;
int main()
{
cout<<"Welcome to the Poker Experiment."<<endl;
int totalHands =0;
float flushPercent=0, totalFlush=0;
Card card1;
Deck deck1;
Hand hand1;
do
{
//Create Deck
deck1.createDeck();
//Shuffle Deck
deck1.shuffleDeck();
for(int i = 52; i > 5; i-5)
{
//Deal Hand
deck1.dealCards();
//Check Hand
hand1.checkHand();
totalHands++;
//Clear Hand
hand1.clearHand();
}
}
while(totalHands <16000);
flushPercent=totalFlush/totalHands*100;
cout<<"The probability of you getting a flush over 16000 hands: "<<flushPercent;
return 0;
}