This assignment is due at midnight. i have been working on it for the better part of a week and I still can't figure out how to analyze poker hands for what kind of hand they are. I have looked around the internet for ideas to no avail. I am supposed to do this without sorting because we don't know how to do that yet. My code only reveals that I have NO idea what I'm doing. Most of it (besides what's in the functions) is what my teacher gave me to start off with. Please help. Here's my code:
#include <iostream>
#include <cstdlib>
#include <time.h>
#include <vector>
using namespace std;
string suits[] = {"Hearts", "Spades", "Diamonds", "Clubs"};
string values[] = {"2","3","4","5","6","7","8","9","10","Jack","Queen","King","Ace"};
//function for each type of hand Flushes, straights, etc.
vector<int> highs;
int getSuit(int card){
return card / 13;
}
int getValue(int card){
return card % 13;
}
void print(int d[], int length){
for(int i = 0; i < length; i++){
cout << values[ getValue(d[i]) ]<< " of " << suits[ getSuit(d[i]) ]<< endl;
}
}
void shuffle(int d[], int length){
for(int i = 0; i < length; i++){
int other = rand() % length;
int temp = d[i];
d[i] = d[other];
d[other] = temp;
}
}
//example function given by teacher (not needed for assignment)
/*bool royalty(int h[], int length){
int num_kings = 0;
int num_queens = 0;
for(int i = 0; i < length; i++){
if(getValue(h[i]) == 11){ //king
num_kings++;
}
if(getValue(h[i]) == 10){ //queen
num_queens++;
}
}
return num_kings > 0 && num_queens > 0;
}*/
int averageHigh(vector<int> array){
int sum = 0;
for(int i = 0; i < array.size(); i++){
sum += array[i];
}
return sum/array.size();
}
int highCard(int h[], int length){
//stuff
int tempHigh = getValue(h[0]);
for(int i = 0; i < length; i++){
if(getValue(h[i]) > tempHigh){
tempHigh = getValue(h[i]);
}
}
highs.push_back(tempHigh);
return tempHigh;
}
bool straight(int h[], int length){
//scan till you find next highest etc then return false
//for(int i = 0; i < length; i++){
//if(/*confusion*/){
/*more confusion*/
//}else{
// return false; //??
//}
}
bool flush(int h[], int length){
//stuff
if(getSuit(h[0]) == getSuit(h[1]) && getSuit(h[1]) == getSuit(h[2]) && getSuit(h[2]) == getSuit(h[3]) && getSuit(h[3]) == getSuit(h[4])){
return true;
}else{
return false;
}
/*for(int i = 0; i < length; i++){
if(getSuit(h[i]) == getSuit(h[i + 1])){
flush++;
}else{
return 0;
}
}*/
}
bool straightFlush(int h[], int length){
//stuff
}
bool royalFlush(int h[], int length){
//stuff
}
/*int strength(int h[], int length){
//stuff
if(royalFlush(h[], length)){
return 9;
}else if(straightFlush(int h[], length)){
return 8;
}else if(flush(int h[], length)){
return 7;
}else if(straight(int h[], length)){
return 6,
}else{
return 5;
}
}*/
int main(){
srand(time(0));
int deck[52]; // contains garbage numbers.
float times = 0;
cout << "How many games do you want to simulate?" << endl;
cin >> times;
for(int i = 0; i < 52; i++){
deck[i] = i;
}
int straight_count = 0;
int flush_count = 0;
int straightFlush_count = 0;
int royalFlush_count = 0;
for(int i = 0; i < times; i++){
shuffle(deck,52);
int hand1[5];
int hand2[5];
//print(deck, 52);
for(int i = 0; i < 5; i++){
hand1[i] = deck[i];
hand2[i] = deck[i + 5];
}
/*cout << "Hand 1:" << endl;
print(hand1, 5);
cout << endl;
cout << "Hand 2:" << endl;
print(hand2, 5);
cout << endl;
//cout << royalty(hand1, 5) << endl;
//cout << royalty(hand2, 5) << endl; */
if(straight(hand1, 5)){
straight_count++;
}
if(straight(hand2, 5)){
straight_count++;
}
if(flush(hand1, 5)){
flush_count++;
}
if(flush(hand2, 5)){
flush_count++;
}
if(straightFlush(hand1, 5)){
straightFlush_count++;
}
if(straightFlush(hand2, 5)){
straightFlush_count++;
}
if(royalFlush(hand1, 5)){
royalFlush_count++;
}
if(royalFlush(hand2, 5)){
royalFlush_count++;
}
highCard(hand1, 5);
highCard(hand2, 5);
straight(hand1, 5);
straight(hand2, 5);
flush(hand1, 5);
flush(hand2, 5);
}
cout << "Average High Card Value: " << averageHigh(highs) << endl;
cout << "Percent of Straight Hands: " << straight_count/times * 100 << "%" << endl;
cout << "Percent of Flush Hands: " << flush_count/times * 100 << "%" << endl;
cout << "Percent of Straight Flush Hands: " << straightFlush_count/times * 100 << "%" << endl;
cout << "Percent of Royal Flush Hands: " << royalFlush_count/times * 100 << "%" << endl;
Here's the teacher's specific instructions on how it's graded:
10% - Programs follows style guidelines and has header information.
10% - Filename is pokerHands.cpp.
10% - Produces random decks of cards.
10% - Is able to detect a Royal Flush and correct percentage.
10% - Is able to detect a Straight Flush and correct percentage.
10% - Is able to detect a Flush and correct percentage.
10% - Is able to detect a Straight and correct percentage.
10% - Correctly reports the high card (value) and correct percentage.
10% - Overall correct structure of program; accepts # rounds, etc.
10% - Correct reported percentages of tie.