All pastes #518859 Raw Edit

darcy

public text v1 · immutable
#518859 ·published 2007-05-29 13:23 UTC
rendered paste body
//bridge.cpp
#include<iostream>
using namespace std;

const int hand=13;


int main( ) {
    int q; 
    enum suit_t{ SPADES, CLUBS, DIAMONDS, HEARTS, NUM_SUITS };
    enum rank_t { ACE=1, TWO=2, THREE=3, FOUR=4, FIVE=5, SIX=6, SEVEN=7, EIGHT=8, NINE=9, TEN=10, JACK=11, QUEEN=12, KING=13, NUM_RANK=14 };
    typedef struct _card { suit_t suit; rank_t rank; } card;
    card deck[52], hand1[13], hand2[13], hand3[13], hand4[13];
    int d=0;
    for(int i=0; i< NUM_SUITS; i++) {
            for(int j=1; j< NUM_RANK; j++) {
                    deck[d].suit = suit_t(i);
                    deck[d].rank = rank_t(j);
                    d++;
                    }
            }
    srand(time(NULL));
    for(int l=0; l<52; l++) {
            int m= rand() % (52-l);
            card tmp=deck[l];
            deck[l]=deck[l+m];
            deck[l+m]=tmp;
            }
        
    for(int n=0;n<=12;n++){ 
            hand1[n] = deck[n]; 
            }
    q=0;
    for(int n=13;n<=25;n++){ 
            hand2[q] = deck[n];
            q++; 
            }
    q=0; 
    for(int n=26;n<=38;n++){
            hand3[q] = deck[n];
            q++; 
            }
    q=0;
    for(int n=39;n<=51;n++){ 
            hand4[q] = deck[n]; 
            q++;
            } 
            
            
    int hand1total = 0;                    
    cout << "hand 1: " << endl;
    for(int u=0; u<hand; u++) {
        // cout << hand1[u].suit << hand1[u].rank << " ";
        if  (hand1[u].rank == 1) {
            hand1Total = hand1Total + 4;
            cout << hand1[u].suit << hand1[u].rank << " ";
            }
        else if (hand1[u].rank == 11) {
            hand1Total = hand1Total + 1;
            cout << hand1[u].suit << hand1[u].rank << " ";
            }
        else if (hand1[u].rank == 12) {
            hand1Total = hand1Total + 2;
            cout << hand1[u].suit << hand1[u].rank << " ";
            }
        else if (hand1[u].rank == 13) {
            hand1Total = hand1Total + 3;
            cout << hand1[u].suit << hand1[u].rank << " ";
            }
        else {
             cout << hand1[u].suit << hand1[u].rank << " ";
             }
    }
    cout << endl;
    cout << "hand 1 total points: " << hand1Total << endl;
    
    cout << "hand 2: " << endl;
    for(int u=0; u<hand; u++) {
        cout << hand2[u].suit << hand2[u].rank << " "; 
    }
    cout << endl;
    cout << "hand 3: " << endl;
    for(int u=0; u<hand; u++) {
        cout << hand3[u].suit << hand3[u].rank << " ";  
    }
    cout << endl;
    cout << "hand 4: " << endl;
    for(int u=0; u<hand; u++) {
        cout << hand4[u].suit << hand4[u].rank << " ";  
    }
    cout << endl;


    system("pause");                
    return 0;   
}