Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #include <windows.h>
- const char suits[] = { 'c', 'd', 'h', 's' };
- const char rank[] = { '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A' };
- typedef struct
- {
- int value;
- int suit;
- } card;
- void sortowanie_kart(card tab[], int ile_kart)
- {
- int i,j;
- for(i=0;i<ile_kart;i++ ) // srotowanie reki gracza
- {
- for(j=0;j<ile_kart-1;j++ )
- {
- if(tab[j].value> tab[j+1].value)
- {
- int swap1=tab[j].value;
- int swap2=tab[j].suit;
- tab[j].value=tab[j+1].value;
- tab[j].suit=tab[j+1].suit;
- tab[j+1].value=swap1;
- tab[j+1].suit=swap2;
- }
- }
- }
- }
- void game_structure(int stacks, int blinds)
- {
- printf("Welcome to %dNL %d BB deep. Let's play some poker!\n", stacks, blinds);
- Sleep(3000);
- system("cls");
- }
- void straight(card tab[])
- {
- }
- void showdown(card cards[])
- {
- card hand1[7];
- card hand2[7];
- int hand1value=0, hand2value=0, pair=50, twopair=115, trips=171, straight=228, flush=285, boat=335, quads=384, str8flush=444;
- int i, j;
- for(i=0;i<7;i++) // przydzielenie kart do do rak (pierwsze 7 reka nr 1 od 3 do 9 reka nr 2)
- {
- hand1[i].value=cards[i].value;
- hand1[i].suit=cards[i].suit;
- }
- for(i=2;i<9;i++)
- {
- hand2[i-2].value=cards[i].value;
- hand2[i-2].suit=cards[i].suit;
- }
- sortowanie_kart(hand1, 7);
- sortowanie_kart(hand2, 7);
- int strit[3]; // sprawdzanie strita
- strit[0]=0;
- strit[1]=0;
- strit[2]=0;
- for(i=0;i<3;i++)
- {
- for(j=i;j<i+5;i++)
- {
- if(hand1[j].value==hand1[j+1].value) strit[i]++;
- }
- }
- if(strit[2]=4)
- {
- hand1value=straight+5*hand1[2].value+10
- }
- else if(strit[1]=4)
- {
- hand1value=straight+5*hand1[1].value+10
- }
- else if(strit[0]=4)
- {
- hand1value=straight+5*hand1[0].value+10
- }
- for(i=2;i<7;i++) hand1value+=hand1[i].value; // przydzielenie sily rak jezeli reka nie zaweira zadnego ukladu
- for(i=2;i<7;i++) hand2value+=hand2[i].value;
- printf("Your hand value: %d, Your oponent hand value: %d\n", hand1value, hand2value);
- }
- void dealer(card cards[], int ile)
- {
- printf("Dealing cards... \n");
- Sleep(3000);
- int m;
- int i;
- int j;
- for(m=1;m<2;m++) // <------- LOSOWANIE 9 UNIKATOWYCH KART
- {
- for(i=0;i<ile;i++)
- {
- int randomv;
- randomv=rand()%13;
- cards[i].value=randomv;
- }
- for(i=0;i<ile;i++)
- {
- int same_card=0;
- for(j=0;j<ile;j++)
- {
- if(cards[j].value==cards[i].value)
- {
- same_card ++;
- }
- }
- if(same_card>4)
- {
- m--;
- break;
- }
- } // <---------- koniec losowania 9 kart
- }
- for(m=1;m<2;m++) // <----------- przydizelanie suitow do 9 kart
- {
- for(i=0;i<ile;i++)
- {
- int randoms;
- randoms=rand()%4;
- cards[i].suit=randoms;
- }
- for(i=0;i<ile;i++)
- {
- int identical=0;
- for(j=0;j<ile;j++)
- {
- if(cards[j].value==cards[i].value&&cards[j].suit==cards[i].suit)
- {
- identical++;
- }
- }
- if(identical>1)
- {
- m--;
- break;
- }
- }
- }
- }
- int main()
- {
- srand( time( NULL ) );
- int stack1,stack2, SB, BB, ile_BB;
- stack1=stack2;
- BB=stack1/100;
- SB=BB/2;
- printf("Choose amount of money you wanna play for: ");
- scanf("%d", &stack1);
- printf("Choose amount of big blinds you and your opponent will have (min 20 max 200)\n");
- scanf("%d", &ile_BB);
- game_structure(stack1, ile_BB);
- card cards[9];
- dealer(cards, sizeof(cards)/sizeof(cards[0]));
- 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]);
- 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]);
- int i;
- printf("board: ");
- for(i=2;i<7;i++) printf("%c%c ", rank[cards[i].value], suits[cards[i].suit]);
- showdown(cards);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement