Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // No Limit Hold'em alpha version
- #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' };
- const int pair=32, twopairs=303, threeOfaKind=430, straight=668, flush=719 , boat=937, quads=996, str8flush=1248;
- typedef struct
- {
- int value;
- int suit;
- } card;
- typedef struct
- {
- int stack1;
- int stack2;
- int pot;
- int decisionOn;
- int bet;
- } game;
- typedef struct
- {
- int hand1;
- int hand2;
- } handStrength;
- int random(int zakres1, int zakres2)
- {
- int value;
- value = rand()%(zakres2-zakres1+1) + zakres1;
- return value;
- }
- void sortowanie(int tab[], int ile_elementow)
- {
- int i, j;
- for(i=0;i<ile_elementow;i++)
- {
- for(j=0;j<ile_elementow-1;j++)
- {
- if(tab[j]>tab[j+1])
- {
- int swap = tab[j];
- tab[j] = tab[j+1];
- tab[j+1] = swap;
- }
- }
- }
- }
- 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)
- {
- card swap = tab[j];
- tab[j] = tab [j+1];
- tab[j+1] = swap;
- }
- }
- }
- }
- int checkStr8Flush(card cards[])
- {
- int clubs = 0;
- int diamonds = 0;
- int hearts = 0;
- int spades = 0;
- int i, j;
- int value = 0;
- int str8 = 0;
- for(i=0;i<7;i++)
- {
- if(cards[i].suit==0) clubs++;
- else if(cards[i].suit==1) diamonds++;
- else if(cards[i].suit==2) hearts++;
- else if(cards[i].suit==3) spades++;
- }
- int kolor[7]={-1, -1, -1, -1 ,-1 -1, -1};
- if(clubs>=5)
- {
- for(i=0;i<7;i++)
- {
- if(cards[i].suit==0) kolor[i]=cards[i].value;
- }
- sortowanie(kolor, 7);
- for(i=3; i>0; i--)
- {
- str8=0;
- for(j=i+3;j>i-1;j--)
- {
- if(kolor[j]-1 == kolor[j-1]) str8 ++;
- }
- if(str8 == 4)
- {
- value = str8flush + (kolor[j+4]*5-10);
- break;
- }
- }
- if (value == 0) // przypadek Ah2h3h4h5h
- {
- str8 = 0;
- for(i=0;i<7;i++)
- {
- if(kolor[i] == 0 || kolor[i] == 1 || kolor[i] == 2 || kolor[i] == 3 || kolor[i] == 12)
- str8 ++;
- }
- if(str8 == 5) value = str8flush + 6;
- }
- }
- else if(diamonds>=5)
- {
- for(i=0;i<7;i++)
- {
- if(cards[i].suit==0) kolor[i]=cards[i].value;
- }
- sortowanie(kolor, 7);
- for(i=3; i>0; i--)
- {
- str8=0;
- for(j=i+3;j>i-1;j--)
- {
- if(kolor[j]-1 == kolor[j-1]) str8 ++;
- }
- if(str8 == 4)
- {
- value = str8flush + (kolor[j+4]*5-10);
- break;
- }
- }
- if (value == 0) // przypadek Ah2h3h4h5h
- {
- str8 = 0;
- for(i=0;i<7;i++)
- {
- if(kolor[i] == 0 || kolor[i] == 1 || kolor[i] == 2 || kolor[i] == 3 || kolor[i] == 12)
- str8 ++;
- }
- if(str8 == 5) value = str8flush + 6;
- }
- }
- else if(hearts>=5)
- {
- for(i=0;i<7;i++)
- {
- if(cards[i].suit==0) kolor[i]=cards[i].value;
- }
- sortowanie(kolor, 7);
- for(i=3; i>0; i--)
- {
- str8=0;
- for(j=i+3;j>i-1;j--)
- {
- if(kolor[j]-1 == kolor[j-1]) str8 ++;
- }
- if(str8 == 4)
- {
- value = str8flush + (kolor[j+4]*5-10);
- break;
- }
- }
- if (value == 0) // przypadek Ah2h3h4h5h
- {
- str8 = 0;
- for(i=0;i<7;i++)
- {
- if(kolor[i] == 0 || kolor[i] == 1 || kolor[i] == 2 || kolor[i] == 3 || kolor[i] == 12)
- str8 ++;
- }
- if(str8 == 5) value = str8flush + 6;
- }
- }
- else if(spades>=5)
- {
- for(i=0;i<7;i++)
- {
- if(cards[i].suit==0) kolor[i]=cards[i].value;
- }
- sortowanie(kolor, 7);
- for(i=3; i>0; i--)
- {
- str8=0;
- for(j=i+3;j>i-1;j--)
- {
- if(kolor[j]-1 == kolor[j-1]) str8 ++;
- }
- if(str8 == 4)
- {
- value = str8flush + (kolor[j+4]*5-10);
- break;
- }
- }
- if (value == 0) // przypadek Ah2h3h4h5h
- {
- str8 = 0;
- for(i=0;i<7;i++)
- {
- if(kolor[i] == 0 || kolor[i] == 1 || kolor[i] == 2 || kolor[i] == 3 || kolor[i] == 12)
- str8 ++;
- }
- if(str8 == 5) value = str8flush + 6;
- }
- }
- return value;
- }
- int checkQuads(card cards[])
- {
- int i, j;
- int value=0;
- int sameCard;
- int kicker;
- int fourOfaKind=0;
- for(i=6;i>=0;i--)
- {
- sameCard = 0;
- for(j=6;j>=0;j--)
- {
- if(cards[i].value == cards[j].value)
- {
- sameCard++;
- fourOfaKind = cards[i].value;
- }
- }
- if (sameCard == 4)
- {
- for(i=6;i>=0;i--)
- {
- if(cards[i].value != fourOfaKind)
- {
- kicker = cards[i].value;
- break;
- }
- }
- value = quads + fourOfaKind*4*5 + kicker;
- break;
- }
- }
- return value;
- }
- int checkFH(card cards[])
- {
- int i, j;
- int value = 0;
- int sameCard;
- int trips = 0;
- int pair = 0;
- for(i=6;i>=0;i--)
- {
- sameCard=0;
- for(j=6;j>=0;j--)
- {
- if(cards[i].value == cards[j].value)
- {
- sameCard ++;
- trips = cards[i].value;
- }
- }
- if(sameCard == 3)
- {
- for(i=6;i>=0;i--)
- {
- sameCard=0;
- for(j=6;j>=0;j--)
- {
- if(cards[i].value != trips)
- {
- if(cards[i].value == cards[j].value)
- {
- sameCard ++;
- pair = cards[i].value;
- }
- }
- }
- if(sameCard == 3)
- {
- if(pair>trips) value = boat + 3*pair+2*trips;
- else if(trips>pair) value = boat + 3*trips + 2*trips;
- break;
- }
- else if(sameCard == 2)
- {
- value = boat + 3*trips + 2*pair;
- break;
- }
- }
- break;
- }
- }
- return value;
- }
- int checkFlush(card cards[])
- {
- int clubs = 0;
- int diamonds = 0;
- int hearts = 0;
- int spades = 0;
- int i;
- int value = 0;
- for(i=0;i<7;i++)
- {
- if(cards[i].suit==0) clubs++;
- else if(cards[i].suit==1) diamonds++;
- else if(cards[i].suit==2) hearts++;
- else if(cards[i].suit==3) spades++;
- }
- int kolor[7]={0};
- if(clubs>=5)
- {
- value=flush;
- for(i=0;i<7;i++)
- {
- if(cards[i].suit==0) kolor[i]=cards[i].value;
- }
- sortowanie(kolor, 7);
- value += kolor[6]*15+kolor[5]+kolor[4]+kolor[3]+kolor[2];
- }
- else if(diamonds>=5)
- {
- value=flush;
- for(i=0;i<7;i++)
- {
- if(cards[i].suit==1) kolor[i]=cards[i].value;
- }
- sortowanie(kolor, 7);
- value += kolor[6]*15+kolor[5]+kolor[4]+kolor[3]+kolor[2];
- }
- else if(hearts>=5)
- {
- value=flush;
- for(i=0;i<7;i++)
- {
- if(cards[i].suit==2) kolor[i]=cards[i].value;
- }
- sortowanie(kolor, 7);
- value += kolor[6]*15+kolor[5]+kolor[4]+kolor[3]+kolor[2];
- }
- else if(spades>=5)
- {
- value=flush;
- for(i=0;i<7;i++)
- {
- if(cards[i].suit==3) kolor[i]=cards[i].value;
- }
- sortowanie(kolor, 7);
- value += kolor[6]*15+kolor[5]+kolor[4]+kolor[3]+kolor[2];
- }
- return value;
- }
- int checkStr8(card cards[])
- {
- int i;
- int j;
- int str8 = 0;
- int value = 0;
- int sameCard = 0;
- for(i=3;i>0;i--)
- {
- str8=0;
- for(j=i+3;j>i-1;j--)
- {
- if(cards[j].value-1==cards[j-1].value) str8++;
- else if(cards[j].value==cards[j-1].value)
- {
- i--;
- sameCard++;
- }
- }
- if(str8==4)
- {
- value = straight;
- if(sameCard == 0)
- {
- value += cards[j+4].value*5-10;
- }
- if(sameCard == 1)
- {
- value += cards[j+5].value*5-10;
- }
- if(sameCard == 2)
- {
- value += cards[j+6].value*5-10;
- }
- break;
- }
- }
- if(value == 0) // strit: A2345
- {
- str8=0;
- for(i=0;i<7;i++)
- {
- if(cards[i].value == 12 || cards[i].value == 0 || cards[i].value == 1 || cards[i].value == 2 || cards[i].value == 3)
- str8 ++;
- }
- for(i=0;i<7;i++)
- {
- for(j=0;j<7;j++)
- {
- if(cards[i].value == cards[j].value && i!=j && (cards[i].value == 12 || cards[i].value == 0 || cards[i].value == 1 || cards[i].value == 2 || cards[i].value == 3))
- {
- str8 --;
- }
- }
- }
- if(str8 == 5)
- {
- value = straight + 6;
- }
- }
- return value;
- }
- int checkTrips(card cards[])
- {
- int i,j;
- int value=0;
- int sameCard;
- int trips;
- int kicker[4];
- for(i=6;i>=0;i--)
- {
- sameCard = 0;
- for(j=6;j>=0;j--)
- {
- if(cards[i].value == cards[j].value)
- {
- sameCard ++;
- trips = cards[i].value;
- }
- }
- if(sameCard == 3)
- {
- j=3;
- for(i=6;i>=0;i--)
- {
- if(cards[i].value != trips)
- {
- kicker[j] = cards[i].value;
- j--;
- }
- }
- value = threeOfaKind + trips*3*6 + kicker[3] + kicker [2];
- break;
- }
- }
- return value;
- }
- int check2Pairs(card cards[])
- {
- int i, j;
- int value = 0;
- int sameCard;
- int pair1=0;
- int pair2=0;
- int kicker;
- for(i=6;i>=0;i--)
- {
- sameCard=0;
- for(j=6;j>=0;j--)
- {
- if(cards[i].value == cards[j].value)
- {
- sameCard ++;
- pair1 = cards[i].value;
- }
- }
- if(sameCard == 2)
- {
- for(i=6;i>=0;i--)
- {
- sameCard = 0;
- for(j=6;j>=0;j--)
- {
- if(cards[i].value != pair1)
- {
- if(cards[i].value == cards[j].value)
- {
- sameCard ++;
- pair2 = cards[i].value;
- }
- }
- }
- if(sameCard == 2)
- {
- for(i=6;i>=0;i--)
- {
- if(cards[i].value != pair1 && cards[i].value != pair2)
- {
- kicker = cards[i].value;
- break;
- }
- }
- value = twopairs + pair1*2*3 + pair2*2*2 + kicker;
- break;
- }
- }
- break;
- }
- }
- return value;
- }
- int checkPair(card cards[])
- {
- int i,j,k;
- int value=0;
- int pair1;
- int sameCard;
- int kicker[5];
- for(i=6;i>=0;i--)
- {
- sameCard = 0;
- for(j=6;j>=0;j--)
- {
- if(cards[i].value == cards[j].value)
- {
- sameCard ++;
- pair1 = cards[i].value;
- }
- }
- if(sameCard == 2)
- {
- k=4;
- for(i=6;i>=0;i--)
- {
- if(cards[i].value != pair1)
- {
- kicker[k] = cards[i].value;
- k--;
- }
- }
- value = pair + pair1*2*10 + kicker[4] + kicker [3] + kicker [2]; // nie zmieniac tego na *20 2 i 10 repreznetuja *2 bo para * 6 zeby 33 z najgorszymi kickerami pokonala 22 z AKQ.
- break;
- }
- }
- return value;
- }
- handStrength showdown(card cards[])
- {
- card Hand1[7];
- card Hand2[7];
- handStrength Sila;
- Sila.hand1 = 0;
- Sila.hand2 = 0;
- int kicker1[5];
- int kicker2[5];
- 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);
- Sila.hand1 = checkStr8Flush(Hand1);
- if(Sila.hand1 == 0) Sila.hand1 = checkQuads(Hand1);
- if(Sila.hand1 == 0) Sila.hand1 = checkFH(Hand1);
- if(Sila.hand1 == 0) Sila.hand1 = checkFlush(Hand1);
- if(Sila.hand1 == 0) Sila.hand1 = checkStr8(Hand1);
- if(Sila.hand1 == 0) Sila.hand1 = checkTrips(Hand1);
- if(Sila.hand1 == 0) Sila.hand1 = check2Pairs(Hand1);
- if(Sila.hand1 == 0) Sila.hand1 = checkPair(Hand1);
- Sila.hand2 = checkStr8Flush(Hand2);
- if(Sila.hand2 == 0) Sila.hand2 = checkQuads(Hand2);
- if(Sila.hand2 == 0) Sila.hand2 = checkFH(Hand2);
- if(Sila.hand2 == 0) Sila.hand2 = checkFlush(Hand2);
- if(Sila.hand2 == 0) Sila.hand2 = checkStr8(Hand2);
- if(Sila.hand2 == 0) Sila.hand2 = checkTrips(Hand2);
- if(Sila.hand2 == 0) Sila.hand2 = check2Pairs(Hand2);
- if(Sila.hand2 == 0) Sila.hand2 = checkPair(Hand2);
- if(Sila.hand1 == 0 && Sila.hand2 == 0)
- {
- for(i=6;i>=2;i--) kicker1[i-2] = Hand1[i].value; // przydzielenie sily rak jezeli reka nie zaweira zadnego ukladu
- for(i=6;i>=2;i--) kicker2[i-2] = Hand2[i].value;
- for(j=4;j>=0;j--)
- {
- Sila.hand1 = kicker1[j];
- Sila.hand2 = kicker2[j];
- if(Sila.hand1 != Sila.hand2) break;
- }
- }
- return Sila;
- }
- game blinds(game round, int blind, int roundnumber)
- {
- round.pot = 0;
- if(roundnumber%2 == 1) // gracz na BB np 1. reka
- {
- if(round.stack1 <= blind/2)
- {
- round.pot = 2* round.stack1;
- round.stack2 -= round.stack1;
- round.stack1 = 0;
- }
- else if(round.stack2 <= blind/2)
- {
- round.pot = 2* round.stack2;
- round.stack1 -= round.stack2;
- round.stack2 = 0;
- }
- else if(round.stack1 >= blind) // gracz na big blindzie
- {
- round.stack1 -= blind;
- round.pot += blind;
- }
- else if(round.stack1 < blind)
- {
- round.pot += round.stack1;
- round.stack1 = 0;
- }
- if (round.stack2 >= blind/2)
- {
- round.stack2 -= blind/2;
- round.pot += blind/2;
- }
- }
- else if(roundnumber%2 == 0)
- {
- if(round.stack1 <= blind/2)
- {
- round.pot = 2* round.stack1;
- round.stack2 -= round.stack1;
- round.stack1 = 0;
- }
- else if(round.stack2 <= blind/2)
- {
- round.pot = 2* round.stack2;
- round.stack1 -= round.stack2;
- round.stack2 = 0;
- }
- else if(round.stack2 >= blind) // komputer na big blindzie
- {
- round.stack2 -= blind;
- round.pot += blind;
- }
- else if(round.stack1 < blind)
- {
- round.pot += round.stack1;
- round.stack2 = 0;
- }
- if (round.stack1 >= blind/2)
- {
- round.stack1 -= blind/2;
- round.pot += blind/2;
- }
- }
- return round;
- }
- game winner(game round, handStrength value)
- {
- if(value.hand1 > value.hand2)
- {
- round.stack1 += round.pot;
- printf("\nyou won the hand\n");
- }
- else if(value.hand1 < value.hand2)
- {
- round.stack2 += round.pot;
- printf("\ncomputer won the hand\n");
- }
- else if(value.hand2 == value.hand1)
- {
- round.stack2 += round.pot/2;
- round.stack1 += round.pot/2;
- }
- return round;
- }
- game preFlopDecision(game round, int blind, int roundnumber)
- {
- int choice;
- int i;
- int previousBet;
- int previousBet2;
- int position;
- int allinstack1 = round.stack1;
- int allinstack2 = round.stack2;
- round.decisionOn = roundnumber%2;
- position = round.decisionOn;
- round.bet = blind/2;
- previousBet = blind;
- while(round.decisionOn == 0 || round.decisionOn == 1)
- {
- if(round.decisionOn == 0 ) // decyzja gracza
- {
- for(i=1;i<2;i++)
- {
- if(round.pot == 2*blind && position == 1 && round.bet < 2*blind ) // preflop in position na big blindzie gdy oppoenent zagral call
- {
- printf(" \n1. fold 2. check 3.raise");
- scanf("%d", &choice);
- if(choice == 1)
- {
- round.stack2 += round.pot;
- round.decisionOn = 3;
- }
- else if(choice == 2 )
- {
- round.bet = 0;
- round.decisionOn = 2;
- }
- else if(choice == 3)
- {
- printf("\n how much to raise: ");
- previousBet = blind;
- round.stack1 += previousBet;
- round.pot -= previousBet;
- previousBet2 = previousBet;
- previousBet = round.bet;
- scanf("%d", &round.bet);
- if(round.bet < 2*blind)
- {
- printf("You must raise min 2BB");
- round.bet = previousBet;
- round.stack1 -= previousBet2;
- round.pot += previousBet2;
- i --;
- }
- else if(round.bet >= 2*blind && round.bet <= round.stack1)
- {
- round.stack1 += previousBet;
- round.stack1 -= round.bet;
- round.pot += round.bet;
- printf("\npot: %d", round.pot);
- round.decisionOn = 1;
- }
- else
- {
- printf("if you wanna raise that much buy more chips... you dont have enough money");
- round.bet = previousBet;
- round.stack1 -= previousBet2;
- round.pot += previousBet2;
- continue;
- }
- }
- else
- {
- printf("wrong choice, pick again");
- i --;
- }
- }
- else if(round.pot == (blind+blind/2) && position == 0) // preflop out of positon na small blindzie
- {
- printf(" 1. fold \n 2. call %d 3. raise", round.bet);
- scanf("%d", &choice);
- if(choice == 1)
- {
- round.stack2 += round.pot;
- round.decisionOn = 3;
- }
- else if(choice == 2)
- {
- round.stack1 -= round.bet;
- round.pot += round.bet;
- printf("pot: %d\n", round.pot);
- round.decisionOn = 1;
- }
- else if(choice == 3)
- {
- printf("\n how much to raise: ");
- previousBet = blind/2;
- previousBet2 = previousBet;
- round.stack1 += previousBet2;
- round.pot -= previousBet2;
- scanf("%d", &round.bet);
- if(round.bet < 2*blind)
- {
- printf("you must raise min 2BB\n");
- round.bet = previousBet;
- round.stack1 -= previousBet2;
- round.pot += previousBet2;
- i --;
- }
- else if(round.bet >= 2*blind && round.bet <= round.stack1)
- {
- round.stack1 -= round.bet;
- round.pot += round.bet;
- round.decisionOn = 1;
- printf("\n pot %d \n \n your stack: %d \n",round.pot, round.stack1);
- }
- else
- {
- printf("if you wanna raise that much buy more chips... you dont have enough money");
- round.bet = previousBet;
- round.stack1 -= previousBet2;
- round.pot += previousBet2;
- i --;
- }
- }
- else
- {
- printf("wrong choice, pick again");
- i --;
- }
- }
- else if(round.pot > 2*blind)
- {
- printf(" 1. fold \n 2. call %d 3. raise", round.bet);
- scanf("%d", &choice);
- if(choice == 1)
- {
- round.stack2 += round.pot;
- round.decisionOn = 3;
- }
- if(choice == 2)
- {
- round.stack1 += previousBet;
- round.pot -= previousBet;
- round.stack1 -= round.bet;
- round.pot += round.bet;
- round.decisionOn = 2;
- }
- if(choice == 3)
- {
- printf("\nhow much to raise: ");
- round.stack1 += previousBet;
- round.pot -= previousBet;
- previousBet2 = previousBet;
- previousBet = round.bet;
- scanf("%d", &round.bet);
- if(round.bet < (previousBet + blind))
- {
- printf("you must raise min previous bet + 1BB");
- round.bet = previousBet;
- round.stack1 -= previousBet2;
- round.pot += previousBet2;
- i--;
- }
- else if(round.bet > round.pot + blind && round.bet <= round.stack1)
- {
- round.stack1 += previousBet;
- round.pot -= previousBet;
- round.stack1 -= round.bet;
- round.pot += round.bet;
- round.decisionOn = 1;
- }
- else
- {
- printf("if you wanna raise that much buy more chips... you dont have enough money");
- round.bet = previousBet;
- round.stack1 -= previousBet2;
- round.pot += previousBet2;
- i--;
- }
- }
- }
- else if(round.pot < (3*blind/2)) round.decisionOn =3;
- }
- }
- else if(round.decisionOn == 1)
- {
- if(round.pot == 2*blind && position == 0 && round.bet < 2*blind ) // komputer na Big blindzie gdy Small blind gra call
- {
- choice = rand()%3 + 1;
- if(choice == 1)
- {
- round.stack1 += round.pot;
- round.decisionOn = 3;
- printf("computer folds. \n");
- }
- else if(choice == 2 )
- {
- round.bet = 0;
- round.decisionOn = 2;
- printf("computer checks. \n");
- }
- else if(choice == 3)
- {
- round.stack2 += 2*round.bet;
- round.pot -= 2*round.bet;
- if(round.stack2 >= round.stack1) round.bet = random(2*blind, round.stack1);
- else if(round.stack2 <= round.stack1) round.bet = random(2*blind, round.stack2);
- round.stack2 -= round.bet;
- round.pot += round.bet;
- round.decisionOn = 0;
- printf("\n computer raises to: %d \n pot is now: %d", round.bet, round.pot);
- }
- }
- else if(round.pot == (blind+blind/2) && position == 1) // komputer na sb
- {
- choice = rand()%3 + 1;
- if(choice == 1)
- {
- round.stack1 += round.pot;
- round.decisionOn = 3;
- printf("computer folds.");
- }
- else if(choice == 2)
- {
- round.stack2 -= round.bet;
- round.pot += round.bet;
- round.decisionOn = 0;
- printf("computer calls pot is now: %d", round.pot);
- }
- else if(choice == 3)
- {
- int open;
- open = rand()%2;
- previousBet = blind;
- round.stack2 += round.bet;
- round.pot -= round.bet;
- if(round.stack2 >= 3*blind && open == 0) round.bet = 3*blind;
- else if(round.stack2 >= round.stack1) round.bet = random(2*blind, allinstack1);
- else if(round.stack2 <= round.stack1) round.bet = random(2*blind, allinstack2);
- round.stack2 -= round.bet;
- round.pot += round.bet;
- round.decisionOn = 0;
- printf("\n computer raises to: %d \n his stack is now: %d pot is now: %d\n", round.bet, round.stack2, round.pot);
- }
- }
- else if(round.pot >= 2*blind)
- {
- choice = rand()%3 + 1;
- if(choice == 1)
- {
- round.stack1 += round.pot;
- round.decisionOn = 3;
- printf("computer folds.\n");
- }
- else if(choice == 2 && round.bet < (round.stack2 + previousBet))
- {
- round.stack2 += previousBet;
- round.pot -= previousBet;
- round.stack2 -= round.bet;
- round.pot += round.bet;
- round.decisionOn = 2;
- printf("computer calls, pot is now: %d", round.pot);
- }
- else if(choice == 2 && round.bet >= allinstack2)
- {
- if( allinstack1 > allinstack2)
- {
- round.stack1 += round.bet;
- round.stack1 -= (round.stack2 + previousBet);
- round.pot -= round.bet;
- round.pot += round.stack2 + previousBet;
- round.pot += round.stack2 + previousBet;
- round.stack2 -= round.stack2;
- }
- else
- {
- round.pot += round.stack1;
- round.pot += round.stack2;
- round.stack1 = 0;
- round.stack2 = 0;
- }
- printf("computer calls and is all in pot is now : %d", round.pot);
- round.decisionOn = 2;
- }
- else if(choice == 3 && round.bet < (round.stack2 + blind) && round.stack1 != 0)
- {
- round.stack2 += previousBet;
- round.pot -= previousBet;
- if(round.stack2 >= round.stack1) round.bet = random(2*blind, allinstack1);
- else if(round.stack2 <= round.stack1) round.bet = random(2*blind, allinstack2);
- round.stack2 -= round.bet;
- round.pot += round.bet;
- printf("computer raises to: %d, pot is now: %d", round.bet, round.pot);
- round.decisionOn = 0;
- }
- else if(choice == 3 && round.bet >= round.stack2)
- {
- if(allinstack1 > allinstack2)
- {
- round.stack1 += round.bet;
- round.stack1 -= (round.stack2 + previousBet);
- round.pot -= round.bet;
- round.pot += round.stack2 + previousBet;
- round.pot += round.stack2 + previousBet;
- round.stack2 -= round.stack2;
- }
- else
- {
- round.pot += round.stack1;
- round.pot += round.stack2;
- round.stack1 = 0;
- round.stack2 = 0;
- }
- printf("computer calls and is all in pot is now : %d", round.pot);
- round.decisionOn = 2;
- }
- else if(choice == 3 && round.stack1 == 0)
- {
- round.stack2 += previousBet;
- round.pot -= previousBet;
- round.stack2 -= round.bet;
- round.pot += round.bet;
- round.decisionOn = 2;
- printf("computer calls, pot is now: %d", round.pot);
- }
- }
- else if(round.pot < (3*blind/2)) round.decisionOn =3;
- }
- }
- return round;
- }
- game postFlopDecision(game round, int blind, int roundnumber)
- {
- int choice;
- int compChoice;
- int i;
- int position;
- int previousBet;
- int allinstack1 = round.stack1;
- int allinstack2 = round.stack2;
- round.decisionOn = roundnumber%2;
- position = round.decisionOn;
- round.bet = 0;
- previousBet = 0;
- int previousBet2;
- while(round.decisionOn == 0 || round.decisionOn == 1)
- {
- if(round.decisionOn == 0)
- {
- for(i=1;i<2;i++)
- {
- if(position == 0 && round.bet == 0)// OOP FLOP DECISION
- {
- printf("\n 1.fold 2.check 3.bet \n");
- scanf("%d", &choice);
- if(choice == 1)
- {
- round.stack2 += round.pot;
- round.decisionOn = 3;
- }
- else if(choice == 2)
- {
- round.decisionOn = 1; //check oop decyzja do komputera
- }
- else if(choice == 3)
- {
- printf("how much to bet: ");
- scanf("%d", &round.bet);
- if(round.bet < blind)
- {
- printf("you must bet min 1bb \n");
- i --;
- }
- else if(round.bet > round.stack1)
- {
- printf("if you wanna raise that much buy more chips... you dont have enough money \n");
- i --;
- }
- else if(round.bet >= blind && round.bet <= round.stack1)
- {
- round.stack1 -= round.bet;
- round.pot += round.bet;
- round.decisionOn = 1;
- }
- }
- }
- else if(position == 0 && round.bet > 0) // oop comp reraised
- {
- printf("\n 1.fold 2.call %d 3.bet \n", round.bet);
- scanf("%d", &choice);
- if(choice == 1)
- {
- round.stack2 += round.pot; // fold
- round.decisionOn = 3;
- }
- else if(choice == 2)
- {
- round.stack1 += previousBet;
- round.pot -= previousBet;
- round.stack1 -= round.bet;
- round.pot += round.bet;
- round.decisionOn = 2; //call back, next street
- }
- else if(choice == 3)
- {
- printf("how much to raise: ");
- round.stack1 += previousBet;
- round.pot -= previousBet;
- previousBet2 = previousBet;
- previousBet = round.bet;
- scanf("%d", &round.bet);
- if(round.bet < (previousBet+blind))
- {
- printf("you have raise to min prev bet + 1bb");
- i --;
- round.bet = previousBet;
- round.stack1 -= previousBet2;
- round.pot += previousBet2;
- }
- else if(round.bet > round.stack1)
- {
- printf("if you wanna raise that much buy more chips... you dont have enough money\n");
- i --;
- round.bet = previousBet;
- round.stack1 -= previousBet2;
- round.pot += previousBet2;
- }
- else
- {
- round.stack1 -= round.bet;
- round.pot += round.bet;
- round.decisionOn = 1;
- printf("your stack is now: %d pot is now: %d", round.stack1, round.pot);
- }
- }
- }
- else if(position == 1) // IP POST FLOP
- {
- if(round.bet == 0) // komputer gral check
- {
- printf("\n 1.fold 2.check 3.bet \n");
- scanf("%d", &choice);
- if(choice == 1)
- {
- round.stack2 += round.pot; // fold
- round.decisionOn = 3;
- }
- else if(choice == 2)
- {
- round.decisionOn = 2; //check back, next street
- }
- else if(choice == 3) // bet IP
- {
- printf("how much to bet: ");
- scanf("%d", &round.bet);
- if(round.bet < blind)
- {
- printf("you must bet min 1bb \n");
- i --;
- }
- else if(round.bet > round.stack1)
- {
- printf("if you wanna raise that much buy more chips... you dont have enough money \n");
- i --;
- }
- else if(round.bet >= blind && round.bet <= round.stack1)
- {
- round.stack1 -= round.bet;
- round.pot += round.bet;
- round.decisionOn = 1;
- printf("your stack is now: %d pot is now: %d", round.stack1, round.pot);
- }
- }
- }
- else if(round.bet > 0) // komp gra bet
- {
- printf("\n 1.fold 2.call %d 3.raise \n", round.bet);
- scanf("%d", &choice);
- if(choice == 1)
- {
- round.stack2 += round.pot; // fold
- round.decisionOn = 3;
- }
- else if(choice == 2)
- {
- round.stack1 -= round.bet;
- round.pot += round.bet;
- printf("pot is now %d \n", round.pot);
- round.decisionOn = 2;
- }
- else if(choice == 3)
- {
- printf("how much to raise: ");
- round.stack1 += previousBet;
- round.pot -= previousBet;
- previousBet2 = previousBet;
- previousBet = round.bet;
- scanf("%d", &round.bet);
- if(round.bet < (previousBet+blind))
- {
- printf("you have raise to min prev bet + 1bb");
- i --;
- round.bet = previousBet;
- round.stack1 -= previousBet2;
- round.pot += previousBet2;
- }
- else if(round.bet > round.stack1)
- {
- printf("if you wanna raise that much buy more chips... you dont have enough money\n");
- i --;
- round.bet = previousBet;
- round.stack1 -= previousBet2;
- round.pot += previousBet2;
- }
- else
- {
- round.stack1 -= round.bet;
- round.pot += round.bet;
- round.decisionOn = 1;
- printf("your stack is now: %d pot is now: %d", round.stack1, round.pot);
- }
- }
- }
- }
- }
- }
- else if(round.decisionOn == 1) // decyzje kompa
- {
- if(position == 1 && round.bet == 0) // OOP BOT DECISION
- {
- compChoice = rand()%2 +1;
- if(compChoice == 1)
- {
- printf("computer checks. \n");
- round.decisionOn = 0;
- }
- else if(compChoice == 2)
- {
- if(round.stack2 >= round.pot/2)
- {
- round.bet = round.pot/2;
- round.stack2 -= round.bet;
- round.pot += round.bet;
- printf("computer bets: %d pot is now: %d", round.bet, round.pot);
- round.decisionOn = 0;
- }
- else
- {
- round.bet = round.stack2;
- round.stack2 -= round.bet;
- round.pot += round.bet;
- printf("computer bets: %d pot is now: %d", round.bet, round.pot);
- round.decisionOn = 0;
- }
- }
- }
- else if(position == 0 && round.bet == 0) // KOMPUTER IP GRACZ GRA X FLOP
- {
- compChoice = rand()%2 +1;
- if(compChoice == 1)
- {
- printf("computer checks.");
- round.decisionOn = 2; // dealing next card;
- }
- else if(compChoice == 2)
- {
- if(round.stack2 >= round.pot/2) //betting always half for balance :P zmien to potem
- {
- round.bet = round.pot/2;
- round.stack2 -= round.bet;
- round.pot += round.bet;
- printf("computer bets: %d pot is now: %d", round.bet, round.pot);
- round.decisionOn = 0;
- }
- else
- {
- round.bet = round.stack2;
- round.stack2 -= round.bet;
- round.pot += round.bet;
- printf("computer bets: %d pot is now: %d", round.bet, round.pot);
- round.decisionOn = 0;
- }
- }
- }
- else if(round.bet > 0) // player bet
- {
- compChoice = rand()%3 +1;
- if(compChoice == 1)
- {
- printf("computer folds.");
- round.stack1 += round.pot;
- round.decisionOn = 3;
- }
- if(compChoice == 2)
- {
- printf("computer calls.");
- round.stack2 += previousBet;
- round.pot -= previousBet;
- round.stack2 -= round.bet;
- round.pot += round.bet;
- printf("computer stack: %d pot: %d", round.stack2, round.pot);
- round.decisionOn = 2; // dealing next card
- }
- if(compChoice == 3)
- {
- round.stack2 += previousBet;
- round.pot -= previousBet;
- if((round.stack1 + previousBet) > round.stack2) round.bet = random(round.bet + blind, round.stack2);
- else if(round.stack2 > (round.stack1 + previousBet)) round.bet = random(round.bet + blind, round.stack1);
- round.stack2 -= round.bet;
- round.pot += round.bet;
- round.decisionOn = 0;
- printf("computer raises to: %d, his stack is now: %d pot is now: %d", round.bet, round.stack2, round.pot);
- }
- }
- }
- }
- return round;
- }
- void dealer(card cards[], int ile)
- {
- printf("Dealing cards... \n");
- int m;
- int i;
- int j;
- int identical;
- 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 randoms;
- randoms=rand()%4;
- cards[i].suit=randoms;
- }
- for(i=0;i<ile;i++)
- {
- 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 ) );
- card cards[9];
- handStrength SilaRak;
- game upDate;
- upDate.stack1 = upDate.stack2 = 5000;
- int i, j;
- int blind = 100;
- int roundnumber = 0;
- printf(" Welcome to 5000 No Limit heads up poker.\n Blinds are: 50/100. \n You will be starting on Big Blind, good luck!!");
- Sleep(3000);
- printf("\n Schuffling deck:\n");
- for(j=0;j<4;j++)
- {
- for(i=0; i<13; i++)
- {
- printf(" %c%c \n",rank[i], suits[j]);
- }
- Sleep(2500);
- }
- while(upDate.stack1>0 && upDate.stack2>0)
- {
- roundnumber ++;
- upDate.bet = blind/2;
- printf("\nYour stack is: %d Your oppoenent's stack is: %d\n", upDate.stack1, upDate.stack2);
- printf("Posting blinds. . .\n");
- Sleep(3000);
- upDate = blinds(upDate, blind, roundnumber);
- dealer(cards, 9);
- Sleep(3000);
- system("cls");
- printf("Your stack is: %d pot is : %d Your oppoenent's stack is: %d\n", upDate.stack1,upDate.pot , upDate.stack2);
- printf("Your hand is:\n ------ ------\n");
- printf("| %c%c | | %c%c |\n", rank[cards[0].value], suits[cards[0].suit], rank[cards[1].value], suits[cards[1].suit]);
- printf("| | | |\n");
- printf("| | | |\n");
- printf(" ------ ------\n");
- upDate = preFlopDecision(upDate, blind, roundnumber); //preflop
- if(upDate.decisionOn == 3) continue; // fold preflop
- else if(upDate.decisionOn == 2 && (upDate.stack1 <= 0 || upDate.stack2 <= 0)) // all in preflop
- {
- 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]);
- printf("Your stack is:%d Your opponent stack is %d\n pot is: %d\n", upDate.stack1, upDate.stack2, upDate.pot);
- printf("board: ");
- for(i=2;i<7;i++) printf("%c%c ", rank[cards[i].value], suits[cards[i].suit]);
- SilaRak = showdown(cards);
- upDate = winner(upDate, SilaRak);
- printf("Your stack is: %d Your oppoenent's stack is: %d\n", upDate.stack1, upDate.stack2);
- Sleep(15000);
- system("cls");
- Sleep(5000);
- }
- else if(upDate.decisionOn == 2 && upDate.stack1 != 0 && upDate.stack2 != 0)
- {
- printf("Your stack is:%d Your opponent stack is %d\n pot is: %d\n", upDate.stack1, upDate.stack2, upDate.pot);
- printf("board: ");
- for(i=2;i<5;i++) printf(" %c%c ", rank[cards[i].value], suits[cards[i].suit]);
- upDate = postFlopDecision(upDate, blind, roundnumber); // flop decisions
- if(upDate.decisionOn == 3) continue; // fold na flopie
- else if(upDate.decisionOn == 2 && (upDate.stack1 <= 0 || upDate.stack2 <= 0)) // all in na flopie
- {
- 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]);
- printf("Your stack is:%d Your opponent stack is %d\n pot is: %d\n", upDate.stack1, upDate.stack2, upDate.pot);
- printf("board: ");
- for(i=2;i<7;i++) printf("%c%c ", rank[cards[i].value], suits[cards[i].suit]);
- SilaRak = showdown(cards);
- upDate = winner(upDate, SilaRak);
- printf("Your stack is: %d Your oppoenent's stack is: %d\n", upDate.stack1, upDate.stack2);
- Sleep(15000);
- system("cls");
- Sleep(5000);
- }
- else if(upDate.decisionOn == 2 && upDate.stack1 != 0 && upDate.stack2 != 0)
- {
- printf("board: ");
- printf("Your stack is:%d Your opponent stack is %d\n pot is: %d\n", upDate.stack1, upDate.stack2, upDate.pot);
- for(i=2;i<6;i++) printf("%c%c ", rank[cards[i].value], suits[cards[i].suit]);
- upDate = postFlopDecision(upDate, blind, roundnumber); // turn decisions
- if(upDate.decisionOn == 3) continue; // fold na turnie
- else if(upDate.decisionOn == 2 && (upDate.stack1 <= 0 || upDate.stack2 <= 0)) // all in na turnie
- {
- 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]);
- printf("Your stack is:%d Your opponent stack is %d\n pot is: %d\n", upDate.stack1, upDate.stack2, upDate.pot);
- printf("board: ");
- for(i=2;i<7;i++) printf("%c%c ", rank[cards[i].value], suits[cards[i].suit]);
- SilaRak = showdown(cards);
- upDate = winner(upDate, SilaRak);
- printf("Your stack is: %d Your oppoenent's stack is: %d\n", upDate.stack1, upDate.stack2);
- Sleep(15000);
- system("cls");
- Sleep(5000);
- }
- else if(upDate.decisionOn == 2 && upDate.stack1 != 0 && upDate.stack2 != 0)
- {
- printf("Your stack is:%d Your opponent stack is %d\n pot is: %d\n", upDate.stack1, upDate.stack2, upDate.pot);
- printf("board: ");
- for(i=2;i<7;i++) printf("%c%c ", rank[cards[i].value], suits[cards[i].suit]);
- upDate = postFlopDecision(upDate, blind, roundnumber); // river decisions
- if(upDate.decisionOn == 3) continue; // fold na riverze
- else if(upDate.decisionOn == 2)
- {
- printf("\nYour opponent hand is: %c%c %c%c\n", rank[cards[7].value], suits[cards[7].suit], rank[cards[8].value], suits[cards[8].suit]);
- SilaRak = showdown(cards);
- upDate = winner(upDate, SilaRak);
- printf("\nYour stack is: %d Your oppoenent's stack is: %d\n", upDate.stack1, upDate.stack2);
- Sleep(15000);
- system("cls");
- Sleep(5000);
- }
- }
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement