#include #include #include #include #include #include #define DECK_NO 1 // Type , Const , Global definition using namespace std; const int _TCARD=DECK_NO*52; typedef struct DECK{ int list[_TCARD]; bool used[_TCARD]; int left[13]; int total; } DECK; typedef struct HAND{ int card[5]; int n; bool bust; // Indicate whether this hand exceeds 21 int mval,no_a; } HAND; int money=100,bet=0, play=1; // Initially, the player play 1 hand. HAND hand[5]; // At most 5 hands per round if the player get 4 equal cards and split them. DECK deck; // deck for this game int known[13],try_card[5]; // Use for AI //functions void initialize(); void init2(); void AI_DRAW_DECK(HAND&); void give_card(HAND&,int n); // give cards to player's i-th hand void call_dealer(); // let the dealer to draw cards void get_amount(int&); void show(HAND&,int); // Display a given hand with a bool representing a player or a computer bool chk_split(HAND& k) {return k.card[0]/4==k.card[1]/4;} string card_name(int i); int value(int i){ int k=(i/4+1); return (k<10)?k:10;} void swap(int& x,int &y) { x^=y; y^=x; x^=y; return ; } bool chk_letter(string k, int n=2){ string LETTER[4]={"Y","y","N","n"}; int i; for (i=0;i<2*n;++i) if (k==LETTER[i]) return true; if (n==0) for (i=2;i<4;++i) if (k==LETTER[i]) return true; return false; } // draw a card from a given DECK d int draw(DECK& d){ int t=d.list[d.total]; d.used[t]=true; --d.left[t/4]; ++d.total; return t; } // main int main(){ string c; int i,j,k; initialize(); do{ // start of do-while , the main loop for each round init2(); i=j=0; cout<<"Player :$"<>c && !chk_letter(c)) cout<<"Re-enter : Split? (Y/N) :"; if(chk_letter(c,1)) { ++play; money-=bet; for(k=0;k<2;++k) {hand[play].card[k]=draw(deck);++hand[play].n;} swap(hand[play].card[0],hand[j].card[1]); cout<0 && hand[i].mval<=11) hand[i].mval+=10; AI_DRAW_DECK(hand[0]); if (hand[0].no_a>0 && hand[0].mval<=11) hand[0].mval+=10; cout << "Final Result :"<>c && !chk_letter(c)) cout<<"Re-enter : Again? (Y/N) :"; } cout<=25) swap(deck.list[j],deck.list[j+1]); /*for (i=0;i<_TCARD;++i) { cout<>bet; cin.get(); if (bet>money || bet<1) { cout<<"Wrong Amount!"<money || bet<1); } void show(HAND& h,int z) { int i,j; i=j=0; if (!z) cout<<"Dealer : * "; else cout<<"Player Hand("<>s;} while (!chk_letter(s)); cout<21) d.bust=true; cout<