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
|
#include <iostream>
#include<cstdlib>
#include <string>
#include <ctime>
#define PLAYERS 9
using namespace std;
//create information class which stores player's chip count, hole cards, position etc
class information{
public:
string hole_cards[4];
};
information player[PLAYERS]; //set number of players
int RNG(int n); //random number generator
string suits[4] = {"s", "c", "d", "h"}; //use to give a card suit
string ranks[13] = {"A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"}; //use to give a card rank
bool card_drawn[52];
int cards_remaining = 52;
int select_available_card(int card);
void deal_hole_cards(void);
int main(){
srand(time(NULL)); //set seed for randomizing
deal_hole_cards();
for(int j = 1; j <= PLAYERS; j++){
cout << player[j].hole_cards[0] << player[j].hole_cards[1] << " ";
}
system("PAUSE");
return 0;
}
int RNG(int n) {
return rand() % n;
}
void deal_hole_cards(void){
int card, r, s, k;
int i = 0;
k = i + 1;
for(int j = 1; j <= PLAYERS; j++){
card = select_available_card(RNG(cards_remaining--)); //get a random card, based on cards left
r = card % 13;
s = card / 13;
player[j].hole_cards[i] = ranks[r]; //set players hole_cards using the information class
player[j].hole_cards[k] = suits[s];
}
}
int select_available_card(int card){
int i = -1;
card++;
while(card-->0){
i++; //go to next card as we have counted one card off
while(card_drawn[i]){
i++; //if current card has already been drawn skip to next card
}
}
card_drawn[i] = true; //set card selected to be shown as drawn
return i;
}
|