Guest User

Untitled

a guest
Dec 30th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.43 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #include <windows.h>
  5.  
  6. const char suits[] = { 'c', 'd', 'h', 's' };
  7. const char rank[] = { '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A' };
  8. const int  pair=50, twopair=115, trips=171, straight=228, flush=285, boat=335, quads=384, str8flush=444;
  9.  
  10. typedef struct
  11. {
  12.     int value;
  13.     int suit;
  14. } card;
  15.  
  16. void sortowanie(int tab[], int ile_elementow)
  17. {
  18.     int i, j;
  19.     for(i=0;i<ile_elementow;i++)
  20.     {
  21.         for(j=0;j<ile_elementow-1;j++)
  22.         {
  23.             if(tab[j]>tab[j+1])
  24.             {
  25.                 int swap = tab[j];
  26.                 tab[j] = tab[j+1];
  27.                 tab[j+1] = swap;
  28.  
  29.             }
  30.         }
  31.     }
  32. }
  33.  
  34. void sortowanie_kart(card tab[], int ile_kart)
  35. {
  36.     int i,j;
  37.     for(i=0;i<ile_kart;i++ ) // srotowanie reki gracza
  38.      {
  39.         for(j=0;j<ile_kart-1;j++ )
  40.         {
  41.             if(tab[j].value>tab[j+1].value)
  42.             {
  43.                 int swap1=tab[j].value;
  44.                 int swap2=tab[j].suit;
  45.                 tab[j].value=tab[j+1].value;
  46.                 tab[j].suit=tab[j+1].suit;
  47.                 tab[j+1].value=swap1;
  48.                 tab[j+1].suit=swap2;
  49.             }
  50.         }
  51.     }
  52. }
  53.  
  54. void game_structure(int stacks, int blinds)
  55. {
  56.     printf("Welcome to %dNL %d BB deep. Let's play some poker!\n", stacks, blinds);
  57.     Sleep(3000);
  58.     system("cls");
  59. }
  60. }
  61.  
  62. void showdown(card cards[])
  63. {
  64.     card hand1[7];
  65.     card hand2[7];
  66.     int hand1value=0, hand2value=0;
  67.     int i, j;
  68.     for(i=0;i<7;i++)                        // przydzielenie kart do do rak (pierwsze 7 reka nr 1 od 3 do 9 reka nr 2)
  69.     {
  70.         hand1[i].value=cards[i].value;
  71.         hand1[i].suit=cards[i].suit;
  72.     }
  73.     for(i=2;i<9;i++)
  74.     {
  75.         hand2[i-2].value=cards[i].value;
  76.         hand2[i-2].suit=cards[i].suit;
  77.     }
  78.     sortowanie_kart(hand1, 7);
  79.     sortowanie_kart(hand2, 7);
  80.     int clubs=0, diamonds=0, hearts=0, spades=0;
  81.     for(i=0;i<7;i++)
  82.     {
  83.         if(hand1[i].suit==0) clubs++;
  84.         else if(hand1[i].suit==1) diamonds++;
  85.         else if(hand1[i].suit==2) hearts++;
  86.         else if(hand1[i].suit==3) spades++;
  87.     }
  88.     if(clubs>=5)
  89.     {
  90.         int kolor[7]={0};
  91.         hand1value=flush;
  92.         for(i=0;i<7;i++)
  93.         {
  94.             if(hand1[i].suit==0) kolor[i]=hand1[i].value;
  95.         }
  96.         sortowanie(kolor, 7);
  97.         for(i=2;i<7;i++)  hand1value+=kolor[i];
  98.     }
  99.     if(hand1value==0)
  100.     {
  101.        for(i=2;i<7;i++) hand1value+=hand1[i].value;  // przydzielenie sily rak jezeli reka nie zaweira zadnego ukladu
  102.     }
  103.     if(hand2value==0)
  104.     {
  105.        for(i=2;i<7;i++) hand2value+=hand2[i].value;
  106.     }
  107.     printf("Your hand value: %d, Your oponent hand value: %d\n", hand1value, hand2value);
  108.  
  109. }
  110.  
  111.  
  112. void dealer(card cards[], int ile)
  113. {
  114.     printf("Dealing cards... \n");
  115.     int n;
  116.     int m;
  117.     int i;
  118.     int j;
  119.     int identical;
  120.     for(m=1;m<2;m++) // <------- LOSOWANIE 9 UNIKATOWYCH KART
  121.     {
  122.         for(i=0;i<ile;i++)
  123.         {
  124.             int randomv;
  125.             randomv=rand()%13;
  126.             cards[i].value=randomv;
  127.         }
  128.         for(i=0;i<ile;i++)
  129.         {
  130.             int randoms;
  131.             randoms=rand()%4;
  132.             cards[i].suit=randoms;
  133.         }
  134.         for(i=0;i<ile;i++)
  135.         {
  136.             identical=0;
  137.             for(j=0;j<ile;j++)
  138.             {
  139.                 if(cards[j].value==cards[i].value&&cards[j].suit==cards[i].suit)
  140.                 {
  141.                 identical++;
  142.                 }
  143.             }
  144.             if(identical>1) m--; break;
  145.         }
  146.     }
  147. }
  148.  
  149. int main()
  150. {
  151.     srand( time( NULL ) );
  152.     int stack1,stack2, SB, BB, ile_BB;
  153.     stack1=stack2;
  154.     BB=stack1/100;
  155.     SB=BB/2;
  156.     printf("Choose amount of money you wanna play for: ");
  157.     scanf("%d", &stack1);
  158.     printf("Choose amount of big blinds you and your opponent will have (min 20 max 200)\n");
  159.     scanf("%d", &ile_BB);
  160.     game_structure(stack1, ile_BB);
  161.     card cards[9];
  162.     dealer(cards, 9);
  163.     printf("Your hand is: %c%c %c%c \n", rank[cards[0].value], suits[cards[0].suit], rank[cards[1].value], suits[cards[1].suit]);
  164.     printf("Your opponent hand is: %c%c %c%c\n", rank[cards[7].value], suits[cards[7].suit], rank[cards[8].value], suits[cards[8].suit]);
  165.     int i;
  166.     printf("board: ");
  167.     for(i=2;i<7;i++) printf("%c%c ", rank[cards[i].value], suits[cards[i].suit]);
  168.     showdown(cards);
  169.     return 0;
  170. }
Add Comment
Please, Sign In to add comment