Advertisement
Guest User

Untitled

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