SlideShare une entreprise Scribd logo
1  sur  73
Télécharger pour lire hors ligne
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <vector>
#include <fstream>
#include <string>

using namespace std;

# define INPUT_FILE "inputf.txt"
# define DEAL_FILE "deal.txt"
# define DEALS_MONEY "deals_money.txt"
# define RIVER_CARDS "river_cards.txt"
# define CHECKPATTERN_FILE "checkpattern.txt"
# define PRE_FLOP 1
# define FLOP 2
# define FOURTH_STREET 3
# define FIFTH_STREET 4
# define SHOW_DOWN 5
# define SKIP_NEWLINE while(*ptr == 10 || *ptr==13){ptr++;}
# define FIRST (int)'A'
# define CALL (int)'C'
# define RISE (int)'R'
# define FOLD (int)'F'
# define FOLDED (int) '-'
# define BLUFF (int)'B'
# define VERY_GOOD 5
# define GOOD 4
# define AVG 3
# define BAD 2
# define VERY_BAD 1
# define HIGH 1
# define LOW 0
# define OFFENSIVE 1
# define DEFENSIVE 2
# define ULTRA_DEFENSIVE 3

struct player {
         int handCard1;
         int handCard2;
         int team;
         int bet;
         int money_remaining;
};

short int players_data_move[7][5][500]={0};     /* [TEAM NUMBER][STAGE][ROUND] */
short int players_data_bet[7][5][500]={0};      /* [TEAM NUMBER][STAGE][ROUND] */
short int pot_money[7][5][500]={0};                        /* [TEAM
NUMBER][STAGE][ROUND] */
short int players_hand_card_1[7];                    /* [TEAM NUMBER] */
short int players_hand_card_2[7];                          /* [TEAM NUMBER] */
short int river_cards[5],r_count=0;                  /* [STAGE]    */
short int player_p_values[7][5];                   /* [TEAM NUMBER][STAGE] */
short int checkPattern[6][5][4][3][7] ={0};     /*
[PVALUE][ACTION][REACTION][STAGE][TEAMNUMBER] */
int round_number[5];                                              /* [STAGE] */
int p_ratio[6];                  /* [PVALUE] */
int reaction_ratio[5];                                            /* [REACTION] */
bool players_folded[7];                                           /* [TEAM NUMBER] */
short int number_of_folds;                                        /* Stores the Number of
Folds */
short int play_mode;                                              /* 1 :: OFFENSIVE | 2 ::
DEFENSIVE | 3 :: ULTRA DEFENSIVE */
short int number_of_deals;                                        /* Stores the Number of
Deals */
player players[7];
int deal_number;                                                           /* Represents the
nth deal */
bool is_show_down;                                                         /* Tells if its Show
Down or not */
bool stagePlayed[6]={0};                                          /* Bool of Stages Played */
bool playersEliminated[7];                                        /* [TEAM NUMBER] */
short int num_players_eliminated = 0;

void printPlayerDetails(player p);
void read_file(char *name,char *data);
int getInt(char *data);
int decode_input_file(char *data);
int decode_dealsMoney(char *data);
void getString(char *str,char *data);
int decode_dealFile(char *data,int *stage,int *main_pot);
void read_showDown_handCards(char *data);
void get_current_state_players(char *data,int stage,int self_teamNumber,int dealer);
void set_play_mode(int self_team_number);
int defensive_play(int stage,int *all_cards,int n_total_cards,int self_team_number,int dealer);
bool is_bluffsMore(short int team_number);
int get_minimum_raise(short int stage,short int team_number,short int dealer);
short int get_rank(int self_team_number);
void set_p_ratio();
void set_reaction_ratio();
void set_player_folded();
bool is_FirstTurn(short int dealer, short int self_team_number);
short int checkPattern_p(int action,int reaction, int stage ,int team,int detail);
short int checkPattern_action(int p_value,int action,int reaction, int stage ,int team,int detail);
int catagorize_move(int p_move);
void analyze_data(int self_teamNumber,int dealer);
int offensive(int stage,int *cards,int total,int teamno,int dealer);
int getMove(int stage,int phand,int *team,int teamno,int dealer);
int bluff(int rise, int limit);
int lowraise(int bet);
int compare (const void * a, const void * b);
int pcounter(int *cards,int hand,int total);
int highcard(int *hole,int hand);
int pairs(int *cards,int *allpairs,int total);
int twoofakind(int *allpairs,int paircards,int *hole,int hand);
int twopair(int *allpairs,int paircards,int *hole,int hand);
int threeofakind(int *allpairs,int paircards,int *cards,int total,int *hole , int hand);
int straight(int *cards,int total,int *hole,int hand);
int flush(int *cards,int total,int *hole,int hand);
int fullhouse(int *allpairs,int paircards,int *cards,int total,int *hole , int hand );
int fourofakind(int *allpairs,int paircards,int *hole,int hand);
int striaghtflush(int *cards,int total,int *hole,int hand);
int priver(int*cards,int hand,int total);
int pgrader(int probab , int stage);
int ppreflop(int hand1,int hand2);
int pfuture(int *cards,int total);
int futurestraight(int *cards,int total);
int futureflush(int *cards, int total);
int overallp(int*cards,int total,int stage);
void start_deal(char *data,int self_teamNumber,int *players_left);
int anyoppraisehigh(int stage,int round,int firstplayer,int myteamno,int dealer);

void printPlayerDetails(player p)
{
        cout << "n Hand 1 = " << p.handCard1;
        cout << "n Hand 2 = " << p.handCard2;
        cout << "n Team Number = " << p.team;
        cout << "n Current Round Bet = " << p.bet;
}

void read_file(char *name,char *data)
{
        FILE *file;
        file = fopen(name, "rb");
        fread(data,1000,1,file);
        fclose(file);
}

char *ptr;
char *ptr_startReading;

int getInt(char *data)
{
         int temp=0;
         while(*ptr < '0' || *ptr > '9' )
                 ptr++;
         while(*ptr >= '0' && *ptr <= '9')
         {
                 temp = temp*10 + (*ptr - '0');
ptr++;
       }
       return temp;
}



int decode_input_file(char *data)
{
        ptr = data;
        int t1,t2,t3;
        t1 = getInt(data);
        t2 = getInt(data);
        t3 = getInt(data);
        players[t3].team = t3;
        players[t3].handCard1 = t1;
        //cout << "nHAND CARD 1 = " << t1;
        players[t3].handCard2 = t2;
        //cout << "nHAND CARD 2 = " << t2;
        players[t3].bet = getInt(data);
        //cout << "nTEAM NUMBER = " << t3;
        return t3;
}

int decode_dealsMoney(char *data)
{
        ptr = data;
        player *p;
        int temp,deal;
        p = players;
        //deal = getInt(data);
        string read_str;
        ifstream fin;
        fin.open(DEALS_MONEY,ios::in);
        fin >> read_str;
        fin >> read_str;
        deal = atoi(read_str.c_str());
        for(temp=1;temp<=6;temp++)
        {
                 //p->team = getInt(data);
                 //p->money_remaining = getInt(data);
                 //p++;
                 fin >> read_str;
                 fin >> read_str;
                 players[temp].money_remaining= atoi(read_str.c_str());
                 if(players[temp].money_remaining == 0)
                 {
                          playersEliminated[temp]=true;
                          num_players_eliminated++;
                 }
        }
fin.close();
        return deal;
}


void getString(char *str,char *data)
{
        while(!(*ptr == '-' || *ptr == '_' || (*ptr >= 'a' && *ptr <= 'z') || (*ptr >= 'A' && *ptr <= 'Z')))
                ptr++;
        while((*ptr >= 'a' && *ptr <= 'z') || (*ptr >= 'A' && *ptr <= 'Z') || *ptr=='_' || *ptr == '-')
        {
                *str = *ptr;
                str++;
                ptr++;
        }
        *str='0';
}

int decode_dealFile(char *data,int *stage,int *main_pot)
{
        ptr = data;
        int dealer = getInt(data);
        char str[100];
        getString(str,data);
        //cout << "n First Str = ";
        puts(str);
        getString(str,data);
        //cout << "n Second Str = ";
        puts(str);
        if(!strcmp("Show_Down",str))
                  *stage = SHOW_DOWN;
        else if(!strcmp("Pre_Flop",str))
                  *stage = PRE_FLOP;
        else if(!strcmp("Flop",str))
                  *stage = FLOP;
        else if(!strcmp("Fourth_Street",str))
                  *stage = FOURTH_STREET;
        else if(!strcmp("Fifth_Street",str))
                  *stage = FIFTH_STREET;
        *main_pot = getInt(data);
        ptr_startReading = ptr;
        return dealer;

}


void read_showDown_handCards(char *data)
{
        ofstream fout;
        string file_name,temp_file;
        int card;
for(int xx=1;xx<=6;xx++)
        {
                 file_name = "team";
                 string bet_name = "_bet.txt";
                 file_name = file_name + bet_name;
                 temp_file = (char)(xx + 48);
                 file_name = file_name+temp_file;
                 fout.open(file_name.c_str(),ios::app);
                 //fout.open("test.txt",ios::app);
                 card = getInt(data);/* Temp storage for value we dont need */
                 fout << getInt(data) << "n" << getInt(data) << "n";
                 fout.close();
        }
}

/* ptr continues from the previous point.Its a global variable */

void get_current_state_players(char *data,int stage,int self_teamNumber,int dealer)
{
        cout << "n Started Reading Rest of Deal File";
        ptr = ptr_startReading;
        string stage_name;
        int count_new_cards;
        int river[3];
        //int round_count;

        switch(stage)
        {
        case 1:stage_name = "Pre_Flop";count_new_cards = 0;break;
        case 2:stage_name = "Flop";count_new_cards = 3;break;
        case 3:stage_name = "Fourth_Street";count_new_cards = 1;break;
        case 4:stage_name = "Fifth_Street";count_new_cards = 1;break;
        case 5:stage_name = "Show_Down";count_new_cards = 0;break;
        }
        ofstream fout_river;
        string file_name;
        string temp_file;
        string move;
        int bet;
        int t_round = 1;
        int cur_stage = 1;

        ifstream fin;
        fin.open("deal.txt",ios::in);
        string t_str;
        while(t_str != "Pre_Flop")
                 fin >> t_str;

        bool end_round=false;
        bool end_stage=false;
fout_river.open(RIVER_CARDS,ios::out);

fin >> t_str;
int prevv=0;
while(!fin.eof())
{

        int xx;
        xx=atoi(t_str.c_str());

        if(cur_stage == 5)
        {
                 //cout << "nxx = " << xx;
                 cout << "n Reading Hand Cards";
                 fin >> t_str;

                    players_hand_card_1[xx]=atoi(t_str.c_str());
                    fin >> t_str;
                    players_hand_card_2[xx]=atoi(t_str.c_str());
                    if(xx==6)
                    {
                             /*cout << "n";
                             for (int zz = 1;zz<=6;zz++)
                             {
                                       cout <<zz<<" - " << players_hand_card_1[zz];
                                       cout <<" " << players_hand_card_2[zz];
                                       cout << "n";
                             }
                             getch();*/
                             fout_river.close();
                             return;
                    }
                    fin >> t_str;
        }
        else
        {
                    if(xx == dealer)
                             end_round = true;
                    fin >> move;
                    if(move == "End" || t_str == "End")
                    {
                             cout << "nEnd Reached.Stage Should Change";
                             round_number[cur_stage] = t_round;
                             cur_stage++;
                             ofstream fout;
                             fout.open("Round_Counts.txt",ios::app);
                             fout << t_round << "n";
                             fout.close();
                             t_round=1;
                             switch(cur_stage)
                             {
case 1:stage_name = "Pre_Flop";count_new_cards = 0;break;
               case 2:stage_name = "Flop";count_new_cards = 3;break;
               case 3:stage_name = "Fourth_Street";count_new_cards = 1;break;
               case 4:stage_name = "Fifth_Street";count_new_cards = 1;break;
               case 5:stage_name = "Show_Down";count_new_cards = 0;break;
               }
               while(move != stage_name && move != "Show_Down")
                        fin >> move;
               if(move == "Show_Down")
                        {
                                 cur_stage = 5;
                                 count_new_cards=0;
                                 is_show_down = true;
               }
               stagePlayed[cur_stage] = true;
               for(int xx=0;xx<count_new_cards;xx++)
               {
                        fin >> t_str;
                        river[xx] = atoi(t_str.c_str());
                        fout_river << river [xx] << "n";
               }
               fin >> t_str;
        }
        else
        {
               if(move != "-")
               {
                        fin >> t_str;
                        bet = atoi(t_str.c_str());
               }
               else
                        bet = 0;
               cout << "n Move = " << move << " " << bet;
               players_data_move[xx][cur_stage][t_round] = (int)move[0];
               players_data_bet[xx][cur_stage][t_round] = bet;
               pot_money[xx][cur_stage][t_round] = prevv;
               cout << "n Pot Money = " << prevv;
               //getch();
               if(players_data_move[xx][cur_stage][t_round] != FOLD)
                        prevv = bet;
               if(end_round == true)
                        t_round++;
               /*
               }
               */
               end_round = false;
               end_stage = false;
               fin >> t_str;
        }
    }
}
cout << "nStage = " <<stage << " t_round = " << t_round;
        round_number[stage]=t_round;
        fout_river.close();
        //getch();
        return ;

}

void set_play_mode(int self_team_number)
{
        int money_total=0;
        for(int xx=1;xx<=6;xx++)
                 money_total=money_total+players[xx].money_remaining;
        int mean= money_total/(6-num_players_eliminated);
        cout << "nMean Money = " << mean << "n2/3rd of Mean = " <<(2*mean)/3 << "nRank = "
<< get_rank(self_team_number);

       if(players[self_team_number].money_remaining >=500 && ((get_rank(self_team_number)
<=(2*(6-num_players_eliminated))/3) || num_players_eliminated >=3))
                play_mode = OFFENSIVE;
       else
                play_mode = DEFENSIVE;

       cout << "nPlay Mode = "<<play_mode;
       //getch();
       /* SET BRUTEFORE play_mode - Until Rank is Top 3 or until Money doesnt go below 500 or
800 deals */

        // Remove the Comments below to Activate Ultra Defensive modee //

        /*
        play_mode = ULTRA_DEFENSIVE;
        if(get_rank(self_team_number) <=3 || players[self_team_number].money_remaining <=
500 || deal_number >= 800)
        play_mode = OFFENSIVE;
        */
}



/*
stage = The current Stage
all_cards = All cards including hand card and river Card. (First two Cards as Hand Cards
n_total_cards = Total Number of Cards = River Cards + 2 Hand Cards
self_team_number = The team number who has to return a Reply
dealer = the dealer for the current deal
*/
int defensive_play(int stage,int *all_cards,int n_total_cards,int self_team_number,int dealer)
{
         /* An array that stores all the Cards , including Hand Cards (as 1st 2 cards) & and River Cards
to call "overallp" function */
/*static int all_cards[7];                                                             */
        /*all_cards[0] = players_hand_card_1[self_team_number];                      */
        /*all_cards[1] = players_hand_card_2[self_team_number];                      */
        /*for(int xx = 2;xx < 2+n_river_cards;xx++)                                       */
        /*       all_cards[xx] = river_cards[xx-2];                                            */
        int p_hand = overallp(all_cards, n_total_cards, stage);

        if(!(p_hand == VERY_GOOD || p_hand == GOOD)) /* The Case of Fold */
                 return -10;/*fold*/
        return offensive(stage,all_cards,n_total_cards,self_team_number,dealer);
}

/* Returns true or 1 if the player bluffs atleast twice as more else false oe 0 */
bool is_bluffsMore(short int team_number)
{
        int rise_counter=1;
        int bluff_counter=1;
        for(int xx = 1;xx<=6;xx++)
                 for(int yy = 1;yy<5;yy++)
                          for(int zz=1;zz<=round_number[yy];zz++)
                          {
                                   if(players_data_move[xx][yy][zz] == RISE)
                                            rise_counter++;
                                   if(players_data_move[xx][yy][zz] == BLUFF)
                                            bluff_counter++;
                          }
                          if(rise_counter*2 <= bluff_counter)
                                   return true;
                          else
                                   return false;
}

int get_minimum_raise(short int stage,short int team_number,short int dealer)
{
        if(stage == 5)
                 return 0;
        int cur_round=round_number[stage];
        int cur_player=team_number-1;
        int cur_stage = stage;
        cout << "nStart Round = " << cur_round;
        while(cur_round >= 0)
        {
                 if(cur_player == 0)cur_player=6;
                 if(cur_player == dealer)cur_round--;
                 if(cur_round == 0)
                 {
                          cur_stage--;
                          cur_round=round_number[cur_stage];
                 }
cout << "nCur Player = " << cur_player << " cur_stage = " << cur_stage << "
cur_round = " <<cur_round;
                cout << "nPot Money = " << pot_money[cur_player][cur_stage][cur_round];
                cout << "nRaise = " << (players_data_bet[cur_player][cur_stage][cur_round]-
pot_money[cur_player][cur_stage][cur_round]);
                cout << "nRise Amounts = " <<
players_data_bet[cur_player][cur_stage][cur_round];
                if(players_data_move[cur_player][cur_stage][cur_round] == RISE)
                {
                         cout << "nFinally Rise = " <<
players_data_bet[cur_player][cur_stage][cur_round]-
pot_money[cur_player][cur_stage][cur_round];
                         if(players_data_bet[cur_player][cur_stage][cur_round]-
pot_money[cur_player][cur_stage][cur_round] == 0 ||
players_data_bet[cur_player][cur_stage][cur_round]-pot_money[cur_player][cur_stage][cur_round]
== 5)
                                  return 10;
                         //getch();
                         return (players_data_bet[cur_player][cur_stage][cur_round]-
pot_money[cur_player][cur_stage][cur_round]);
                }
                cur_player--;
        }
        return 0;
}


/* Returns your rank on calling */
short int get_rank(int self_team_number)
{
        short int rank=6;
        for(int xx = 1;xx<=6;xx++)
        {
                 if(xx == self_team_number)
                          continue;
                 if(players[xx].money_remaining <=players[self_team_number].money_remaining)
                          rank--;
        }
        return rank;
}


/* Sets the value of all elements in Array p_ratio as 0 */
void set_p_ratio()
{
         for (int xx=0;xx<6; xx++)
                   p_ratio[xx]=0;
}

/* Sets the value of all elements in Array reaction_ratio as 0 */
void set_reaction_ratio()
{
        for (int xx=0;xx<=4; xx++)
                  reaction_ratio[xx]=0;
}

/* Sets the value of all elements in Array players_folded as false */
void set_player_folded()
{
         for(int xx=1;xx<=6;xx++)
                  players_folded[xx] = false;
}

/* Returns 1 or "true" , if our first turn, else returns 0 or "false" */
bool is_FirstTurn(short int dealer, short int self_team_number)
{
        int s_pos = dealer+1;
        while(s_pos != self_team_number && !(s_pos == 7 && self_team_number == 1))
        {
                 if(s_pos == 7)
                          s_pos = 1;
                 if(players_folded[s_pos] == false)
                          return false;
                 s_pos++;
        }
        return true;
}



/* Function Returns the p_value */
/* VERY_GOOD 5          */
/* GOOD 4 */
/* AVG      3 */
/* BAD      2 */
/* VERY_BAD 1 */
short int checkPattern_p(int action,int reaction, int stage ,int team,int detail = LOW)
{
        /* Action :: What the other opponent Do                */
        /* Reaction :: What this team does for the given action */
        /* Stage :: Stage for which data is required          */
        /* Team :: Team number for which the data is required */
        /* Detail :: How much deatil to check the Patter               */
        /*              HIGH - Check exact match                                     */
        /*              LOW - Ignore Stage                                              */

        /* Set p_ratio array as 0 */
        set_p_ratio();

        /* Declare the Array to store CheckPattern */

        short int max;
/* Read the CheckPattern File and save it in the Array */
        FILE *file;
        file = fopen(CHECKPATTERN_FILE,"rb");
        if(file != NULL)
        {
                   fread(checkPattern,sizeof(int)*6*5*4*3*7,1,file);
                   fclose(file);
        }

       if (detail == LOW)
       {
                 max = 0;
                 for(int xx = 1;xx<=5;xx++) /* For What P Value */
                 {
                          p_ratio[xx] = checkPattern[xx][action][reaction][stage][team];
                          if(checkPattern[max][action][reaction][stage][team] <=
checkPattern[xx][action][reaction][stage][team])
                                   max = xx;
                 }
                 return max;
       }
       else
       {
                 max = 0;
                 for(int xx=1; xx<=5; xx++) /* For What P-Value */
                          for(int zz = 0; zz < 4;zz++) /* For Any Stage */
                          {
                                   p_ratio[xx] = checkPattern[xx][action][reaction][zz][team];
                                   if(checkPattern[max][action][reaction][zz][team] <=
checkPattern[xx][action][reaction][zz][team])
                                             max = xx;
                          }
                          return max;
       }
}


/* Function Returns an Action */
/* RISE :: 3 */
/*       FOLD :: 2 */
/*       CALL :: 1 */
/*       BLUFF :: 4 */
/* It is based on priority */
short int checkPattern_action(int p_value,int action, int stage ,int team,int detail = LOW)
{
         /* p_value :: P_Value for which the reaction is reqd */
         /* Action :: What the other opponent Do             */
         /* Reaction :: What this team does for the given action */
         /* Stage :: Stage for which data is required       */
         /* Team :: Team number for which the data is required */
/* Detail :: How much deatil to check the Patter              */
        /*              HIGH - Check exact match                                  */
        /*              LOW - Ignore Stage                                              */

        /* Declare the Array to store CheckPattern */


        /* Set p_ratio array as 0 */
        set_reaction_ratio();


        short int max;

        /* Read the CheckPattern File and save it in the Array */
        FILE *file;
        file = fopen(CHECKPATTERN_FILE,"rb");
        if(file!=NULL)
        {
                  fread(checkPattern,sizeof(int)*6*5*4*3*7,1,file);
                  fclose(file);
        }

       if (detail == LOW)
       {
                 max = 0;
                 for(int xx = 0;xx<4;xx++) /* For What Reaction */
                 {
                          reaction_ratio[xx] = checkPattern[p_value][action][xx][stage][team];
                          if(checkPattern[p_value][action][max][stage][team] <=
checkPattern[p_value][action][xx][stage][team])
                                   max = xx;
                 }
                 return max;
       }
       else
       {
                 max = 0;
                 for(int xx=1; xx<=5; xx++) /* For What Reaction */
                          for(int zz = 1; zz <= 5;zz++) /* For Any Value of P */
                          {
                                   reaction_ratio[xx] = checkPattern[p_value][action][xx][zz][team];
                                   if(checkPattern[zz][action][max][stage][team] <=
checkPattern[p_value][action][xx][zz][team])
                                             max = xx;
                          }
                          return max;
       }
}

int catagorize_move(int p_move)
{
/* KEY INDEX */
        /* RISE :: 3 */
        /*      FOLD :: 2 */
        /*      CALL :: 1 */
        /*      BLUFF :: 4 */

        if(p_move == CALL)
                return 1;
        if(p_move == FOLD)
                return 2;
        if(p_move == BLUFF)
                return 4;
        if(p_move == RISE)
                return 3;
        return 0; /* For error */
}


void analyze_data(int self_team_number,int dealer)
{
        /*cout << "n";
        for (int xx = 1;xx<=6;xx++)
        {
                  cout <<xx<<" - " << players_hand_card_1[xx];
                  cout <<" " << players_hand_card_2[xx];
                  cout << "n";
        }*/
        r_count=0;
        string file_name = "team" ;
        string temp_file;
        string t_str;
        ifstream fin;
        ifstream file1;
        ifstream file2;


        /* Order for Check Pattern :: PValue - Action - Reaction - Stage -Team Number */
        //int cumulative_round_count=0;

        int stage =1,max_stage;
        int move;
        int counter;
        number_of_folds=0;

        /* Get all the Data from the Help Files into the two arrays declared above */

        /* Read the CheckPattern File */
        cout << "nCheck Pattern Read Start";
        FILE *file;
        file = fopen(CHECKPATTERN_FILE,"rb");
        if(file != NULL)
{
        fread(checkPattern,sizeof(int)*6*5*4*3*7,1,file);
        fclose(file);
}
//cout << "nCHECKPATTERN = " << checkPattern[2][2][2][2][2];
cout << "n Check Pattern read complete";
/* Read all the river Cards from the Help Files */
fin.open(RIVER_CARDS,ios::in);
fin >> t_str;
cout << "nRiver Card Read Start";
while(!fin.eof())
{
         river_cards[r_count++]=atoi(t_str.c_str());
         fin >>t_str;
}
fin.close();
cout << "nRiver Card read completenRIVER CARDS :: ";
for(int mm=0;mm<r_count;mm++)
         cout << river_cards[mm] << " ";
/* This File contains the number of rounds played at each stage in the current Deal */
fin.open("Round_Counts.txt",ios::in);

/* Set player_folded array to False */
set_player_folded();

number_of_folds=0;


/* Read all the Round Counts to an Array */
fin >> t_str;
//round_number[stage++]=atoi(t_str.c_str());
while (!fin.eof())
{
         round_number[stage++]=atoi(t_str.c_str());
         fin >>t_str;
}
fin.close();
cout << "n Read Round Numbers complete, stage = " << stage << "n ROUND NUMBERS :: ";
for(int mm=1;mm<stage;mm++)
         cout << round_number[mm] << " ";
max_stage = stage;
//cout << "nSTAGE = " << stage;
/* Read all the opponent moves and Bets from Help Files */
/*for(int xx = 1,yy=0;xx<=6;xx++)
{
stage=0;
//cumulative_round_count = 0;
counter = round_number[stage];
temp_file = (char)(xx + 48);
file1.open((string)(file_name + "_move.txt"),ios::in);
file2.open((string)(file_name + "_bet.txt"),ios::in);
yy = 0;
        while(!file1.eof())
        {
        file1 >> players_data_move[xx][round_number[stage]-counter][yy];
        if(players_data_move[xx][round_number[stage]-counter][yy] == FOLD)
        {
        players_folded[xx]= true;
        number_of_folds++;
        }
        file2 >> players_data_bet[xx][round_number[stage]-counter][yy];
        counter--;
        if(counter == 0)
        {
        yy=0;
        //cumulative_round_count = cumulative_round_count + round_number[stage];
        stage++;
        counter = round_number[stage];
        }
        yy++;
        }
        file1.close();
        file2 >> players_hand_card_1[xx];
        file2 >> players_hand_card_2[xx];
        file2.close();
        stage++;
        }
        */
        for(int xx = 1;xx<=6;xx++)
        {for(int yy = 1;yy<5;yy++)
        {for(int zz=1;zz<=round_number[yy];zz++)
        {if(players_data_move[xx][yy][zz] == FOLD)
        {
                 players_folded[xx]=true;
                 number_of_folds++;
        }}}}
        cout << "nAnalyze Fold Data Complete";
        for(int xx=1;xx<=6;xx++)
                 cout << xx<<":"<<players_folded[xx] << " ";
        players_hand_card_1[self_team_number] = players[self_team_number].handCard1;
        players_hand_card_2[self_team_number] = players[self_team_number].handCard2;
        //getch();
        //cout << "nWILL IT GO THERE ? :O ";
        if(is_show_down == false)/* If the Stage is not ShowDown , we dont have to analyze the
Data. Just store them in Arrays */
                 return ;
        stage = 5;
        //cout << "nCOMES HERE!!!! :D ";

       /* Calculate the P-Values of each player at every round */
       // int preflop_river_cards[5];//Can use this array for sending to the p_value Function //
       int all_cards[7];
for(int yy = 2;yy < 2+r_count;yy++)
         all_cards[yy] = river_cards[yy-2];
cout << "nCalculating All P Values Started";
for(int xx = 1; xx<=6 ; xx++)
{
         all_cards[0] = players_hand_card_1[xx];
         all_cards[1] = players_hand_card_2[xx];

        /* Preflop */
        //if(max_stage >= 1)

        player_p_values[xx][1] = overallp(all_cards,2,1);

        //cout << "n Calculated First pValue";
        /* Flop */
        //if(max_stage >= 2)
        if(stagePlayed[2] == true)
                 player_p_values[xx][2] = overallp(all_cards,5,2);

        //cout << "n Calculated Second pValue";
        /* Fourth Street */
        //if(max_stage >= 3)
        if(stagePlayed[3] == true)
                 player_p_values[xx][3] = overallp(all_cards,6,3);
        //cout << "n Calculated Third pValue";
        /* Fifth Street */
        //if(max_stage >= 4)
        if(stagePlayed[4] == true)
                 player_p_values[xx][4] = overallp(all_cards,7,4);
        //cout << "n Calculated Fourth pValue";
}
/* All data has now been stored in the required arrays */
cout << "nAll PValues Calculated";
for(int xx=1;xx<=6;xx++)
{
         cout << "nPlayer - " << xx << "n";
         for(int yy=1;yy<=4;yy++)
                  cout << player_p_values[xx][yy] << " ";
}
//getch();


/* Start analyzing from the Dealer */
int current_round = 0;
int number_of_rise = 0;
int number_of_call = 0;
int number_of_fold = 0;


/* Loop to Analyze the Data Stored in all Array */
int loop_counter = 0;   /* Counter for position in current Round */
int loop_stage = 0;       /* Counter for Current Stage */
       int loop_start = dealer+3; /* Counter for Player Number */
       int loop_pot_money = 10; /* Stores the Money in Pot for the Current Stage */
       int player_bet;
       int player_move;
       bool isBluff;                /* 1-Bluff 0-Not Bluff */
       int player_action = (int)'A';      /* What other player did, based on priority */
       while(loop_stage != 5)
       {
                if(loop_start >= 7)
                         loop_start = loop_start-6;
                if(loop_start == dealer+1)
                         loop_counter++;
                if(loop_counter == round_number[loop_stage]) /* Stage Over */
                {
                         loop_stage++;
                         loop_counter=0;
                         loop_pot_money = 0;
                         player_action = (int)'A';
                }
                player_bet = players_data_bet[loop_start][loop_stage][loop_counter] -
loop_pot_money;
                pot_money[loop_start][loop_stage][loop_counter] = loop_pot_money;
                if(player_bet <=0)
                         player_bet = 0;
                loop_pot_money = loop_pot_money + player_bet;
                player_move = players_data_move[loop_start][loop_stage][loop_counter];
                if(player_move > player_action && player_action != FOLDED)
                         player_action = player_move;
                if(player_bet != 0 && (player_p_values[loop_start][loop_stage] == BAD ||
player_p_values[loop_start][loop_stage] == VERY_BAD || player_p_values[loop_start][loop_stage]
== AVG))
                {
                         isBluff = true;
                         player_move = BLUFF;
                }
                else
                         isBluff = false;

        checkPattern[player_p_values[loop_start][loop_stage]][catagorize_move(player_action)][ca
tagorize_move(player_move)][loop_stage][loop_start]++;
               if(player_move == BLUFF)

        checkPattern[player_p_values[loop_start][loop_stage]][catagorize_move(player_action)][RI
SE][loop_stage][loop_start]++;
                loop_start++;
        }

       /* Write The CheckPattern back to File */
       cout << "nWRITE CHECKPATTERN FILE STARTED!";
       file = fopen(CHECKPATTERN_FILE,"wb");
fwrite(checkPattern,sizeof(int)*6*5*4*3*7,1,file);
        fclose(file);
        cout << "nWRITE COMPLETE";
        remove("bluff.txt");
        //getch();

}


/* this fnctn shud be called when need to play offensive and it will return the amount of bet */
int offensive(int stage,int *cards,int total,int teamno,int dealer)
{
         /* initialize random seed: */
         /* initialization for rand function */
         srand ( time(NULL) );
         int phand,rise = get_minimum_raise(stage,teamno,dealer);/* rise = minimum available raise
*/

       phand = overallp(cards,total,stage);
       cout << "nP Hand = " << phand;
       //getch();
       int temp = is_FirstTurn(dealer,teamno);/* checking for first turn */
       //cout << "n First Turn True/False = " << temp;
       if(temp == 0)/* opponent raised or called */
       {
               /* is p vgud */
               if(phand == 5)
               {
                        int check = anyoppraisehigh(stage,round_number[stage],dealer +
1,teamno,dealer);/* check if opp raised high */
                        if(check == 1)
                        {
                                /* check stage */
                                if(stage == 1)
                                {
                                         int choice = rand() % 4 + 1;
                                         if((choice == 1)||(choice == 2)||(choice == 3))
                                                  return 0;/* call */
                                         else
                                         {
                                                  /* high raise fnctn */
                                                  int bet = bluff(rise,4);/* 4 for high raise fnctn */
                                                  return bet;
                                         }

                                  }
                                  else if(stage == 2)
                                  {
                                            int choice = rand() % 4 + 1;
                                            if((choice == 1)||(choice ==2))
                                            {
/* high raise fnctn */
                           int bet = bluff(rise,4);
                           return bet;
                  }
                  else
                            return 0;
         }
         else if(stage == 3)
         {
                   int choice = rand() % 4 + 1;
                   if(choice ==1)
                            return 0;
                   else
                   {
                            int bet = bluff(rise,4);/*high raise fnctn*/
                            return bet;
                   }
         }
         else/*last stage */
         {
                   /* high raise fntn */
                   int bet = bluff(rise,4);
                   return bet;
         }
}
else/* low raise or call */
{
         /* stage check */
         if(stage == 4)
         {
                  /* high raise fnctn */
                  int bet = bluff(rise,4);
                  return bet;
         }

         else if(round_number[stage] == 1)/*new card opened */
         {
                  int choice = rand() % 2 + 1;
                  if(choice == 1)
                           return 0;/* call */
                  else
                  {
                           int bet = bluff(rise,4);
                           return bet;
                  }
                  /* high raise fntn */
         }
         else/*no new card */
         {
                  FILE *pt;
                  int bluffcounter = 4;
pt = fopen("bluff.txt","rb");
                                      if(pt != NULL)/* prev raise */
                                      {
                                               fscanf(pt,"%d",&bluffcounter);
                                               fclose(pt);
                                               if(bluffcounter <4)
                                               {
                                                        int bet = bluff(rise,4);
                                                        return bet;
                                               }
                                      }
                                      else
                                      {
                                               int choice = rand() % 2 +1;
                                               if(choice == 1)
                                                        return 0;/* call */
                                               else
                                               {
                                                        /* high raise fntn */
                                                        int bet = bluff(rise,4);
                                                        return bet;
                                               }
                                      }
                              }
                      }
               }

              /* p is gud */
              if(phand == 4)
              {
                       //cout << "n Case of Pgood";
                       int value=1;
                       int check = anyoppraisehigh(stage,round_number[stage],dealer +
1,teamno,dealer);/* check if opp raised high */
                       //cout << "nDid Any opponent Raise High? " << check;
                       if(check == 1)
                       {

                              int temp = teamno-1;
                              int cur_round = round_number[stage];
                              do
                              {

                                      if(temp == 0)
                                               temp = 6;
                                      if(temp == dealer)
                                               cur_round--;
                                      if(cur_round <=0)
                                      {value = 0;break;}
                                      if(players_data_move[temp][stage][cur_round] == RISE)
                                      {
int rise = players_data_bet[temp][stage][cur_round]
- pot_money[temp][stage][cur_round];
                                               if(rise > 50)
                                               {
                                                         int faltu;
                                                         faltu = is_bluffsMore(temp);
                                                         if(faltu==0)
                                                                   value = faltu;
                                               }
                                       }
                                       temp--;
                              }while(temp != teamno);
                              if(value == 0)
                              {
                                       int pla = 6 - number_of_folds;/* gets no of players playing
on the table */

                                       if(pla <= 3)/* check pattern fntn */
                                       {
                                                int zz=dealer+1;
                                                int ppos=0;
                                                int still_in_play[3]={0};
                                                do
                                                {
                                                          if(zz==7)
                                                                   zz=1;
                                                          if(players_folded[zz] == false)
                                                                   still_in_play[ppos++]=zz;
                                                          zz++;
                                                }while(zz != dealer && !(zz==7 && dealer==1));
                                                if(ppos==2)
                                                {still_in_play[ppos++]=0;}

                                             return
getMove(stage,phand,still_in_play,teamno,dealer);
                                      }

                                       else
                                       {
                                               int count = 0;
                                               int temp=teamno-1;
                                               int still_in_play[3]={0};
                                               int zz=0;
                                               int cur_round = round_number[stage];
                                               do
                                               {

                                                       int value;
                                                       if(temp==0)
                                                                temp = 6;
                                                       if(temp == dealer)
cur_round--;
                                                        if(cur_round <=0)
                                                                 break;

        if((players_data_move[temp][stage][cur_round] ==
CALL)&&(players_data_bet[temp][stage][cur_round] - pot_money[temp][stage][cur_round] > 50))
                                                                   value = is_bluffsMore(temp);
                                                          if(value == 0)
                                                          {
                                                                   count++;
                                                                   still_in_play[zz++]=temp;
                                                          }
                                                          temp--;
                                                }while(temp!=teamno);
                                                still_in_play[zz++]=teamno;
                                                if(zz==3)
                                                {still_in_play[zz++]=0;}
                                                pla = count; /* no of players who raises high and
doesn;t bluff */
                                                if(pla <= 2)
                                                          return
getMove(stage,phand,still_in_play,teamno,dealer);
                                                else /* check pattern */
                                                {
                                                          int choice = rand() % 2 + 1;
                                                          if(choice == 1)
                                                                   return 0;
                                                          else
                                                                   return -10;/* fold */
                                                }
                                       }
                               }
                               else/* means opponent bluffs a lot */
                               {
                                       int players = 6 - number_of_folds;/* no of players playing at
the table */
                                       if(players <= 3)
                                       {

                                                int zz=dealer+1;
                                                int ppos=0;
                                                int still_in_play[3]={0};
                                                do
                                                {
                                                          if(zz==7)
                                                                   zz=1;
                                                          if(players_folded[zz] == false)
                                                                   still_in_play[ppos++]=zz;
                                                          zz++;
                                                }while(zz != dealer && !(zz==7 && dealer==1));
                                                if(ppos==2)
{still_in_play[ppos++]=0;}
                                                  return
getMove(stage,phand,still_in_play,teamno,dealer);
                                                  /* check pattern */
                                        }
                                        else
                                        {
                                                  return 0;/*call*/
                                        }
                               }
                      }
                      else /* low call or call*/
                      {
                               int players = 6 - number_of_folds;/* no of players laying at the table
*/
                               //cout << "nReached the case of chek = 0, players = "<<players;
                               if(players <= 3)                       /*-----------editing left-----------*/
                               {
                                        int zz=dealer+1;
                                        int ppos=0;
                                        int still_in_play[3]={0};
                                        do
                                        {
                                                  if(zz==7)
                                                            zz=1;
                                                  if(players_folded[zz] == false)
                                                            still_in_play[ppos++]=zz;
                                                  zz++;
                                        }while(zz != dealer && !(zz==7 && dealer==1));
                                        if(ppos==2)
                                        {still_in_play[ppos++]=0;}
                                        return getMove(stage,phand,still_in_play,teamno,dealer);
                                        /* check pattern */

                                  }
                                  else
                                  {
                                           cout << "nPlayers Greater than 3";
                                           int lowcheck=0,count=0;
                                           int temp = teamno-1;
                                           if(temp == 0 )
                                                     temp = 6;
                                           int still_in_play[7]={0};
                                           int zz =0;
                                           int cur_round = round_number[stage];
                                           cout << "ncur_round = " << cur_round;
                                           do
                                           {


                                                    if(temp == 0)
temp = 6;
                                                  if(temp == dealer)
                                                           cur_round--;
                                                  if(cur_round == 0)
                                                           break;
                                                  cout << "ntemp = " << temp << " cur_round = " <<
cur_round << " stage = " << stage;
                                                  if(players_data_move[temp][stage][cur_round] ==
RISE)
                                                  {
                                                          count++;
                                                          still_in_play[zz++] = temp;
                                                          lowcheck = 1;
                                                }
                                                temp--;
                                      }while(temp != teamno);
                                      //cout << "nNumber of Rise = " << count;
                                      //cout << "nlow check = " << lowcheck;
                                      //getch();
                                      still_in_play[zz++] = teamno;
                                      if(zz==3)
                                      {still_in_play[zz]=0;zz++;}
                                      if(lowcheck == 1)
                                      {
                                                //cout <<"nEnter Low Check";
                                                int pla = count;/*no of players who raised low */
                                                if(pla <= 2)
                                                {
                                                         //cout << "n Here ????";
                                                         return
getMove(stage,phand,still_in_play,teamno,dealer);
                                                }
                                                else
                                                {
                                                         int choice = rand() % 2 + 1;
                                                         if(choice == 1)
                                                                  return 0;/* call */
                                                         else
                                                         {
                                                                  //cout << "nLow Raise ? ";
                                                                  int bet = lowraise(rise);/* low raise
call */
                                                                  return bet;
                                                         }
                                                }
                                      }
                                      else/*opponent called */
                                      {
                                                int choice = rand()%2 + 1;
                                                if(choice == 1)
                                                         return 0;/* call */
else/* low raise */
                                                {
                                                         int bet = lowraise(rise);
                                                         return bet;
                                                }
                                        }
                                }
                       }
              }
              if(phand == 3)
              {
                       int bet,value;
                       int check = anyoppraisehigh(stage,round_number[stage],dealer +
1,teamno,dealer);/* check if opp raised high */
                       if(check == 1)/* raises high */
                       {
                                if((stage == 1)||(stage == 2))
                                {
                                         int temp=teamno-1;/*checking bluffs a lot*/
                                         int cur_round = round_number[stage];
                                         do
                                         {

                                                if(temp == 0)
                                                         temp = 6;
                                                if(temp == dealer)
                                                         cur_round--;
                                                if(cur_round <= 0)
                                                         break;
                                                if(players_data_move[temp][stage][cur_round] ==
RISE)
                                                {
                                                       int rise =
players_data_bet[temp][stage][cur_round] - pot_money[temp][stage][cur_round];
                                                       if(rise <= 50)
                                                       {
                                                                 int faltu;
                                                                 faltu = is_bluffsMore(temp);
                                                                 if(faltu==0)
                                                                           value = faltu;
                                                       }
                                              }
                                              temp--;
                                     }while(temp != teamno);
                                     if(value == 1)
                                     {
                                              int choice = rand()%3 +1;
                                              if((choice == 1)||(choice == 2))
                                                       return 0;/* call */
                                              else
                                                       return -10;/*fold*/
}
                                           else
                                           {
                                                   int choice = rand()%3 +1;
                                                   if((choice == 1)||(choice == 2))
                                                            return -10;/* fold */
                                                   else
                                                            return 0;/*call*/
                                          }
                                  }
                                  else/*stage 3rd or 4 */
                                  {
                                          if(round_number[stage]==1)/*new cards opened */
                                          {
                                                  int choice = rand()%2 +1;
                                                  if(choice == 1)/* bluff */
                                                  {
                                                           int bet = bluff(rise,2);
                                                           cout <<"n1 Bet = " << bet;
                                                           //getch();
                                                           return bet;
                                                  }
                                                  else
                                                           return -10;/*fold*/

                                           }
                                           else/* no new card opened */
                                           {

       if(players_data_move[teamno][stage][round_number[stage]-1]==RISE)
                                                  {
                                                                   int bet = bluff(rise,2);/* bluff if
allowed */
                                                  if(bet != 0)
                                                           {cout <<"n1 Bet = " << bet;
                                                           //getch();
                                                           return bet;}
                                                  }
                                                  else
                                                           return -10; /* fold */
                                         }
                                }
                       }
                       else /* low raise or call */
                       {
                                if((stage==1)||(stage==2))
                                {
                                         if(round_number[stage]==1)/*new card opened */
                                         {
                                                  int choice = rand()%2 +1;
                                                  if(choice == 1)
{
                                              int bet = bluff(rise,2);
                                              cout <<"n1 Bet = " << bet;
                                              //getch();
                                              return bet;
                                      }
                                      else
                                              return 0;/*call*/

                              }
                              else/* no new card opened */
                              {

if(players_data_move[teamno][stage][round_number[stage]-1]==RISE)
                                      {
                                            int bet = bluff(rise,2);
                                            cout <<"n1 Bet = " << bet;
                                            //getch();
                                            return bet;
                                      }
                                      else
                                      {
                                            return 0;/*call*/
                                      }
                             }

                       }
                       else /* stage 3 or 4 */
                       {
                                if(round_number[stage]==1)/* new card opened */
                                {
                                        int choice = rand()%3 +1;
                                        if(choice == 1)
                                                 return 0;/* call */
                                        else if(choice == 2)
                                                 return -10;/*fold*/
                                        else
                                        {
                                                 int bet = bluff(rise,2);
                                                 cout <<"n1 Bet = " << bet;
                                                 //getch();
                                                 return bet;
                                        }

                              }
                              else/* no new card opened */
                              {

if(players_data_move[teamno][stage][round_number[stage]-1]==RISE)
                                      {
                                            int bet = bluff(rise,2);
cout <<"n1 Bet = " << bet;
                                                      //getch();
                                                      return bet;
                                               }
                                               else
                                               {
                                                      int choice = rand()%2 +1;
                                                      if(choice == 1)
                                                               return 0;/* call */
                                                      else
                                                               return -10;/*fold*/

                                               }
                                        }
                                }
                       }
              }
              if(phand == 2)/* p bad */
              { int check = anyoppraisehigh(stage,round_number[stage],dealer +
1,teamno,dealer);/* check if opp raised high */
              if(check == 1)/*opponent raised high*/
              {
                       if(stage == 1)
                       {
                                 int choice = rand()%4 +1;
                                 if((choice == 1)||(choice == 2)||(choice == 3))
                                          return 0;/* call */
                                 else
                                          return -10;/*fold*/
                       }
                       else if(stage == 2)
                       {
                                 int choice = rand()%3 +1;
                                 if(choice == 1)
                                          return 0;/* call */
                                 else
                                          return -10;/*fold*/
                       }
                       else if(stage == 3)
                       {
                                 int choice = rand()%4 +1;
                                 if((choice == 1)||(choice == 2)||(choice == 3))
                                          return -10;/* fold */
                                 else
                                          return 0;/*call*/

                       }
                       else/*stage 4*/
                               return -10;/*fold*/
               }
               else/*low raise or call */
{

              if((stage==1)||(stage==2))
              {
                       if(round_number[stage]==1)/*new card opened */
                       {
                               int choice = rand()%2 +1;
                               if(choice == 1)
                               {
                                        int bet = bluff(rise,2);
                                        cout <<"n1 Bet = " << bet;
                                        //getch();
                                        return bet;

                             }
                             else
                                     return 0;/*call*/

                      }
                      else/* no new card opened */
                      {

if(players_data_move[teamno][stage][round_number[stage]-1]==RISE)
                             {
                                      int bet = bluff(rise,2);
                                      cout <<"n1 Bet = " << bet;
                                      //getch();
                                      return bet;
                             }
                             else
                             {
                                      return 0;/*call*/
                             }
                       }

              }
              else /* stage 3 or 4 */
              {
                       if(round_number[stage]==1)/* new card opened */
                       {
                               int choice = rand()%4 +1;
                               if(choice == 1)
                                        return 0;/* call */
                               else if(choice == 2 || choice == 3)
                                        return -10;/*fold*/
                               else
                               {
                                        int bet = bluff(rise,2);
                                        cout <<"n1 Bet = " << bet;
                                        //getch();
                                        return bet;
}

                              }
                              else/* no new card opened */
                              {

       if(players_data_move[teamno][stage][round_number[stage]-1]==RISE)
                                    {
                                             int bet = bluff(rise,2);
                                             return bet;
                                    }
                                    else
                                    {
                                             int choice = rand()%2 +1;
                                             if(choice == 1)
                                                      return 0;/* call */
                                             else
                                                      return -10;/*fold*/

                                      }
                              }
                       }
              }
              }
              else/* phand == 1 *//* p is vbad */
              {
                       int check = anyoppraisehigh(stage,round_number[stage],dealer +
1,teamno,dealer);/* check if opp raised high */
                       if(check == 1)
                       {

                              cout << "nYes Some player Rises";
                              //getch();
                              if(stage == 1)
                              {
                                        int choice = rand() % 4 + 1;
                                        if ((choice==1)||(choice==2)||(choice==3))
                                                 return 0;/*call*/
                                        else
                                                 return -10;/*fold */
                              }
                              else if(stage == 2)
                              {
                                        int choice = rand()%4 +1;
                                        cout<<"nchoice "<<choice<<"n";
                                        //getch();
                                        if(choice == 2)
                                                 return 0;/* call */
                                        else
                                                 return -10;/* fold */
}
                      else if(stage == 3)
                      {
                                int choice = rand() % 5 +1;
                                if((choice == 1)||(choice == 2)||(choice == 3)||(choice == 4))
                                         return -10;/* fold */
                                else
                                         return 0;/* call */
                      }
                      else/* stage == 4 */
                                return -10;/* fold */
               }
               else/*opponent raised low or called */
               {
                      cout << "n Opponent Raised Low";
                      if(round_number[stage]==1)/* new card opened */
                      {
                              if(stage == 4)
                              {
                                       int choice = rand()%2 +1;
                                       if(choice == 1)
                                       {
                                                /* bluff fnctn */
                                                int bet = bluff(rise,2);
                                                return bet;
                                       }
                                       else
                                                return -10;/* fold */
                              }
                              else
                              {
                                       int choice = rand() % 2 + 1;
                                       if (choice == 1)
                                       {
                                                /*bluff fnctn */
                                                int bet = bluff(rise,2);
                                                return bet;
                                       }
                                       else
                                                return 0;/* call */
                              }
                      }
                      else/* no new cards opened */
                      {

if(players_data_move[teamno][stage][round_number[stage]-1] == RISE)/*previous bluff*/
                             {
                                      int bet = bluff(rise,2);
                                      return bet;
                             }
                             else
{
                                                 int choice = rand() % 2 + 1;
                                                 if(choice == 1)
                                                          return 0;/*call*/
                                                 else
                                                          return -10;/*fold*/
                                       }
                             }
                   }
         }
}

/*--------------------------- checked till here ----------------------*/


else/* first turn is ours */
{
         if(phand == 5)/* p hand is very gud */
         {
                  if(stage == 1)
                  {
                            int choice = rand() % 4 +1;
                            if((choice == 1)||(choice == 2))
                                     return 0;/* call */
                            else
                            {
                                     /* high raise */
                                     int bet = bluff(rise,4);
                                     return bet;
                            }
                  }
                  else if((stage == 2)||(stage == 3))
                  {
                            int choice = rand() % 3 + 1;
                            if(choice == 1)
                            {
                                     /* raise fnctn */
                                     int bet = bluff(rise,4);
                                     return bet;
                            }
                            else
                                     return 0;/* call */
                  }
                  else/* stage 4 */
                  {
                            int choice = rand() % 2 + 1;
                            if(choice == 1)
                                     return 0;/* call */
                            else
                            {
                                     /* bluff fnctn */
int bet = bluff(rise,2);
                                        return bet;
                               }
                       }
               }
               else if(phand == 4)
               {
                        if(stage == 1)
                        {
                                 int players = 6 - number_of_folds;/* no of players playing at the
table atm */
                               if(players <= 3)
                               {
                                        int zz=dealer+1;
                                        int ppos=0;
                                        int still_in_play[3]={0};
                                        do
                                        {
                                                  if(zz==7)
                                                           zz=1;
                                                  if(players_folded[zz] == false)
                                                           still_in_play[ppos++]=zz;
                                                  zz++;
                                        }while(zz != dealer && !(zz==7 && dealer==1));
                                        if(ppos==2)
                                        {still_in_play[ppos++]=0;}
                                        return getMove(stage,phand,still_in_play,teamno,dealer);

                                       /* check pattern */
                               }
                               else/* players > 3 */
                               {
                                       int choice = rand() % 4 + 1;
                                       if((choice == 1)||(choice == 2))
                                                return 0;/* call */
                                       else if(choice == 3)
                                       {
                                                /* bluff fnctn */
                                                int bet = bluff(rise,4);
                                                return bet;
                                       }
                                       else
                                       {
                                                /* raise fnctn */
                                                int bet = lowraise(rise);
                                                return bet;
                                       }
                               }
                       }
                       else if((stage == 3)||(stage == 2))
                       {
int players = 6 - number_of_folds;/* no of players playing the
current bet */
                         if(players <= 3)
                         {
                                  int zz=dealer+1;
                                  int ppos=0;
                                  int still_in_play[3]={0};
                                  do
                                  {
                                            if(zz==7)
                                                     zz=1;
                                            if(players_folded[zz] == false)
                                                     still_in_play[ppos++]=zz;
                                            zz++;
                                  }while(zz != dealer && !(zz==7 && dealer==1));
                                  if(ppos==2)
                                  {still_in_play[ppos++]=0;}
                                  return getMove(stage,phand,still_in_play,teamno,dealer);

                                 /* check pattern */
                         }
                         else/* players > 3 */
                         {
                                 int choice = rand() % 3 + 1;
                                 if(choice == 1)
                                 {
                                          /* bluff fnctn */
                                          int bet = bluff(rise,2);
                                          return bet;
                                 }
                                 else
                                          return 0;/* call */
                         }
                 }
                 else/* stage == 4 */
                 {
                         int players = 6 - number_of_folds;/* no of players playing the deal
*/
                         if(players <=3)
                         {
                                  int zz=dealer+1;
                                  int ppos=0;
                                  int still_in_play[3]={0};
                                  do
                                  {
                                            if(zz==7)
                                                     zz=1;
                                            if(players_folded[zz] == false)
                                                     still_in_play[ppos++]=zz;
                                            zz++;
                                  }while(zz != dealer && !(zz==7 && dealer==1));
if(ppos==2)
                                           {still_in_play[ppos++]=0;}
                                           return getMove(stage,phand,still_in_play,teamno,dealer);

                                          /*check pattern */
                                  }
                                  else/* players > 3 */
                                  {
                                          int choice = rand() % 3 + 1;
                                          if (choice == 1)
                                          {
                                                   /* bluff fnctn */
                                                   int bet = bluff(rise,2);
                                                   return bet;
                                          }
                                          else
                                                   return 0;/* call */
                                  }
                           }
                  }
                  else if(phand = 3)/* phand == avg */
                  {
                           if(stage == 1)
                           {
                                    int players = 6 - number_of_folds;/* no of players playing the
current deal */
                                  if(players <= 3)
                                  {
                                           int zz=dealer+1;
                                           int ppos=0;
                                           int still_in_play[3]={0};
                                           do
                                           {
                                                     if(zz==7)
                                                              zz=1;
                                                     if(players_folded[zz] == false)
                                                              still_in_play[ppos++]=zz;
                                                     zz++;
                                           }while(zz != dealer && !(zz==7 && dealer==1));
                                           if(ppos==2)
                                           {still_in_play[ppos++]=0;}
                                           return getMove(stage,phand,still_in_play,teamno,dealer);

                                           /* check pattern */
                                  }
                                  else/* players > 3 */
                                  {
                                          int choice = rand() %3 + 1;
                                          if(choice == 1)
                                          {
                                                   /* bluff fnctn */
int bet = bluff(rise,2);
                                           return bet;
                                  }
                                  else
                                           return 0;/* call */
                          }
                  }
                  else if((stage == 2)||(stage == 3))
                  {
                            int players = 6 - number_of_folds;/* no of players playing the
current deal */
                          if(players <= 3)
                          {
                                   int zz=dealer+1;
                                   int ppos=0;
                                   int still_in_play[3]={0};
                                   do
                                   {
                                             if(zz==7)
                                                      zz=1;
                                             if(players_folded[zz] == false)
                                                      still_in_play[ppos++]=zz;
                                             zz++;
                                   }while(zz != dealer && !(zz==7 && dealer==1));
                                   if(ppos==2)
                                   {still_in_play[ppos++]=0;}
                                   return getMove(stage,phand,still_in_play,teamno,dealer);

                                  /* check pattern */
                          }
                          else/* players > 3 */
                          {
                                  int choice = rand() %3 + 1;
                                  if(choice == 1)
                                  {
                                           /*bluff fnctn */
                                           int bet = bluff(rise,2);
                                           return bet;
                                  }
                                  else
                                           return 0;
                          }
                  }
                  else/* stage = 4 */
                  {
                          if(players_data_move[teamno][stage][round_number[stage]-1] ==
RISE)
                          {
                                  int zz=dealer+1;
                                  int ppos=0;
                                  int still_in_play[3]={0};
do
                                       {
                                                 if(zz==7)
                                                          zz=1;
                                                 if(players_folded[zz] == false)
                                                          still_in_play[ppos++]=zz;
                                                 zz++;
                                       }while(zz != dealer && !(zz==7 && dealer==1));
                                       if(ppos==2)
                                       {still_in_play[ppos++]=0;}
                                       return getMove(stage,phand,still_in_play,teamno,dealer);

                                       /* check pattern */
                                       /* can call or bluff */
                                       /* never fold here */
                               }
                               else/* previous wasn;t a bluff*/
                               {

                                       int players = 6 - number_of_folds;/* no of players playing
the current deal */
                                      if(players <= 3)
                                      {
                                               int zz=dealer+1;
                                               int ppos=0;
                                               int still_in_play[3]={0};
                                               do
                                               {
                                                         if(zz==7)
                                                                  zz=1;
                                                         if(players_folded[zz] == false)
                                                                  still_in_play[ppos++]=zz;
                                                         zz++;
                                               }while(zz != dealer && !(zz==7 && dealer==1));
                                               if(ppos==2)
                                               {still_in_play[ppos++]=0;}
                                               return
getMove(stage,phand,still_in_play,teamno,dealer);

                                               /* check pattern */
                                       }
                                       else/* players > 3 */
                                       {
                                               int choice = rand() %3 + 1;
                                               if(choice == 1)
                                               {
                                                        /*bluff fnctn */
                                                        int bet = bluff(rise,2);
                                                        return bet;
                                               }
                                               else
return 0;/*call*/
                          }
                 }
        }
}
if(phand == 2)/* phand = bad */
{
        int players = 6 - number_of_folds;/* no of players playing the current deal */
        if(stage == 1)
        {
                 if(players <= 3)
                 {
                          int zz=dealer+1;
                          int ppos=0;
                          int still_in_play[3]={0};
                          do
                          {
                                    if(zz==7)
                                             zz=1;
                                    if(players_folded[zz] == false)
                                             still_in_play[ppos++]=zz;
                                    zz++;
                          }while(zz != dealer && !(zz==7 && dealer==1));
                          if(ppos==2)
                          {still_in_play[ppos++]=0;}
                          return getMove(stage,phand,still_in_play,teamno,dealer);

                          /* check pattern */
                 }
                 else
                 {
                          int choice = rand() % 2 + 1;
                          if(choice == 1)
                                   return 0;/* call */
                          else
                          {
                                   /* bluff fnctn */
                                   int bet = bluff(rise,2);
                                   return bet;
                          }
                 }
        }
        else if((stage == 2)||(stage == 3))
        {
                  if (players <=3)
                  {
                           int zz=dealer+1;
                           int ppos=0;
                           int still_in_play[3]={0};
                           do
                           {
if(zz==7)
                                  zz=1;
                         if(players_folded[zz] == false)
                                  still_in_play[ppos++]=zz;
                         zz++;
               }while(zz != dealer && !(zz==7 && dealer==1));
               if(ppos==2)
               {still_in_play[ppos++]=0;}
               return getMove(stage,phand,still_in_play,teamno,dealer);

               /*check pattern */
       }
       else
       {
               int choice = rand() % 3 + 1;
               if(choice == 1)
               {
                        /* bluff fnctn */
                        int bet = bluff(rise,2);
                        return bet;
               }
               else
                        return 0; /* call */
       }
}
else/*stage = 4 */
{
        if (players <= 3)
        {
                 int zz=dealer+1;
                 int ppos=0;
                 int still_in_play[3]={0};
                 do
                 {
                           if(zz==7)
                                    zz=1;
                           if(players_folded[zz] == false)
                                    still_in_play[ppos++]=zz;
                           zz++;
                 }while(zz != dealer && !(zz==7 && dealer==1));
                 if(ppos==2)
                 {still_in_play[ppos++]=0;}
                 return getMove(stage,phand,still_in_play,teamno,dealer);

               /* check pattern */
       }
       else
       {
               int choice = rand()%4 + 1;
               if(choice == 1)
               {
/* bluff fnctn */
                                 int bet = bluff(rise,2);
                                 return bet;
                         }
                         else
                                 return 0;
                }
        }
}
else/* phand = 1 and vbad */
{
        int pla = 6 - number_of_folds;/* no of players playing the current deal */
        if(stage == 1)
        {
                 if(pla <= 3)
                 {
                          int zz=dealer+1;
                          int ppos=0;
                          int still_in_play[3]={0};
                          do
                          {
                                    if(zz==7)
                                             zz=1;
                                    if(players_folded[zz] == false)
                                             still_in_play[ppos++]=zz;
                                    zz++;
                          }while(zz != dealer && !(zz==7 && dealer==1));
                          if(ppos==2)
                          {still_in_play[ppos++]=0;}
                          return getMove(stage,phand,still_in_play,teamno,dealer);

                         /* check pattern */
                }
                else
                {
                         int choice = rand() % 3 + 1;
                         if((choice == 1)||(choice == 2))
                                  return 0;/* call */
                         else
                         {
                                  /* bluff fnctn */
                                  int bet = bluff(rise,2);
                                  return bet;
                         }
                  }
        }
        else if((stage == 2)||(stage == 3))
        {
                  if (pla <=3)
                  {
                           int zz=dealer+1;
int ppos=0;
               int still_in_play[3]={0};
               do
               {
                         if(zz==7)
                                  zz=1;
                         if(players_folded[zz] == false)
                                  still_in_play[ppos++]=zz;
                         zz++;
               }while(zz != dealer && !(zz==7 && dealer==1));
               if(ppos==2)
               {still_in_play[ppos++]=0;}
               return getMove(stage,phand,still_in_play,teamno,dealer);

               /*check pattern */
       }
       else
       {
               int choice = rand() % 4 + 1;
               if(choice == 1)
               {
                        /* bluff fnctn */
                        int bet = bluff(rise,2);
                        return bet;
               }
               else
                        return 0; /* call */
        }
}
else/*stage = 4 */
{
        if (pla <= 3)
        {
                 int zz=dealer+1;
                 int ppos=0;
                 int still_in_play[3]={0};
                 do
                 {
                           if(zz==7)
                                    zz=1;
                           if(players_folded[zz] == false)
                                    still_in_play[ppos++]=zz;
                           zz++;
                 }while(zz != dealer && !(zz==7 && dealer==1));
                 if(ppos==2)
                 {still_in_play[ppos++]=0;}
                 return getMove(stage,phand,still_in_play,teamno,dealer);

               /* check pattern */
       }
       else
{
                                       int choice = rand()%5 + 1;
                                       if(choice == 1)
                                       {
                                                /* bluff fnctn */
                                                int bet = bluff(rise,2);
                                                return bet;
                                       }
                                       else
                                                return 0;
                               }
                       }
               }
       }
}

int getMove(int stage,int phand,int *team,int teamno,int dealer)
{
        int final;
        int rise;
        int *ptr,flag;
        int xx1res,xx2res;
        cout << "nTeam 1 = " << *team << " Team 2 = " << *(team +1) << " Team 3 = " << *(team+2)
;
        if(*team == 0 || *(team + 1)==0||*(team + 2)==0)
        {
                  //cout << "nIs it HERE ? ";
                  //getch();
                  flag = 0;
                  for(int temp=1;temp <= 3 ;temp++)
                  {
                            ptr = team;
                            if(*ptr == teamno)
                            {
                                     continue;
                                     flag = 1;
                            }
                            else if(*ptr == 0)
                            {
                                     continue;
                            }
                            else
                            {
                                     if(flag == 0)
                                     {
                                               int pop =
checkPattern_p(FIRST,players_data_move[*ptr][stage][round_number[stage]],stage,*ptr);
                                               if(phand == VERY_BAD||phand == BAD || phand == AVG)
                                               {
                                                       int cal,rez,foiled;
                                                       checkPattern_action(pop,RISE,stage,*ptr);
/* RISE :: 3 */
                                              /*       FOLD :: 2 */
                                              /*       CALL :: 1 */
                                              /*       BLUFF :: 4 */
                                              cal = reaction_ratio[1];
                                              foiled = reaction_ratio[2];
                                              rez = reaction_ratio[3];
                                              if(foiled<=cal || foiled<=rez)
                                                       return -10;/* fold */
                                              else
                                              {
                                                       rise =
get_minimum_raise(stage,teamno,dealer);
                                                      cout << "n Minimum Raise 1= " << rise;
                                                      int bet = bluff(rise,2);
                                                      cout << "n Final Return 1= " << bet;
                                                      //getch();
                                                      return bet;
                                             }
                                     }
                                     else/* phand is very gud */
                                     {
                                             int calfold,rezfold;
                                             checkPattern_action(pop,CALL,stage,temp);
                                             /* RISE :: 3 */
                                             /*       FOLD :: 2 */
                                             /*       CALL :: 1 */
                                             /*       BLUFF :: 4 */
                                             calfold = reaction_ratio[2];
                                             checkPattern_action(pop,RISE,stage,temp);
                                             /* RISE :: 3 */
                                             /*       FOLD :: 2 */
                                             /*       CALL :: 1 */
                                             /*       BLUFF :: 4 */
                                             rezfold = reaction_ratio[2];
                                             if(calfold < rezfold)
                                                      return 0;/* call */
                                             else
                                             {
                                                      rise =
get_minimum_raise(stage,teamno,dealer);
                                                      cout << "n Minimum Raise2 = " << rise;
                                                      int bet = bluff(rise,2);
                                                      cout << "n Final Return 2= " << bet;
                                                      //getch();
                                                      return bet;/*raise bluff */
                                             }
                                     }
                            }
                            else/* flag == 1 */
                            {
AI For Texam Hold'em poker
AI For Texam Hold'em poker
AI For Texam Hold'em poker
AI For Texam Hold'em poker
AI For Texam Hold'em poker
AI For Texam Hold'em poker
AI For Texam Hold'em poker
AI For Texam Hold'em poker
AI For Texam Hold'em poker
AI For Texam Hold'em poker
AI For Texam Hold'em poker
AI For Texam Hold'em poker
AI For Texam Hold'em poker
AI For Texam Hold'em poker
AI For Texam Hold'em poker
AI For Texam Hold'em poker
AI For Texam Hold'em poker
AI For Texam Hold'em poker
AI For Texam Hold'em poker
AI For Texam Hold'em poker
AI For Texam Hold'em poker
AI For Texam Hold'em poker
AI For Texam Hold'em poker
AI For Texam Hold'em poker
AI For Texam Hold'em poker
AI For Texam Hold'em poker
AI For Texam Hold'em poker
AI For Texam Hold'em poker

Contenu connexe

Tendances

AI CHALLENGE ADMIN
AI CHALLENGE ADMINAI CHALLENGE ADMIN
AI CHALLENGE ADMIN
Ankit Gupta
 
c++ program for Railway reservation
c++ program for Railway reservationc++ program for Railway reservation
c++ program for Railway reservation
Swarup Kumar Boro
 
Dns server clients (actual program)
Dns server clients (actual program)Dns server clients (actual program)
Dns server clients (actual program)
Youssef Dirani
 

Tendances (19)

C++ L01-Variables
C++ L01-VariablesC++ L01-Variables
C++ L01-Variables
 
C++ L03-Control Structure
C++ L03-Control StructureC++ L03-Control Structure
C++ L03-Control Structure
 
C++ Lambda and concurrency
C++ Lambda and concurrencyC++ Lambda and concurrency
C++ Lambda and concurrency
 
C++ L06-Pointers
C++ L06-PointersC++ L06-Pointers
C++ L06-Pointers
 
AI CHALLENGE ADMIN
AI CHALLENGE ADMINAI CHALLENGE ADMIN
AI CHALLENGE ADMIN
 
Dpsm simu.cpp
Dpsm simu.cppDpsm simu.cpp
Dpsm simu.cpp
 
c++ program for Railway reservation
c++ program for Railway reservationc++ program for Railway reservation
c++ program for Railway reservation
 
C++ L02-Conversion+enum+Operators
C++ L02-Conversion+enum+OperatorsC++ L02-Conversion+enum+Operators
C++ L02-Conversion+enum+Operators
 
Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...
Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...
Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...
 
3 1-1
3 1-13 1-1
3 1-1
 
Get Kata
Get KataGet Kata
Get Kata
 
Usp
UspUsp
Usp
 
Add an interactive command line to your C++ application
Add an interactive command line to your C++ applicationAdd an interactive command line to your C++ application
Add an interactive command line to your C++ application
 
Npc14
Npc14Npc14
Npc14
 
Lập trình Python cơ bản
Lập trình Python cơ bảnLập trình Python cơ bản
Lập trình Python cơ bản
 
Enlace iax2
Enlace iax2Enlace iax2
Enlace iax2
 
Php radomize
Php radomizePhp radomize
Php radomize
 
Opp compile
Opp compileOpp compile
Opp compile
 
Dns server clients (actual program)
Dns server clients (actual program)Dns server clients (actual program)
Dns server clients (actual program)
 

Similaire à AI For Texam Hold'em poker

calc3build# calc3bison -y -d calc3.yflex calc3.lgcc -c .docx
calc3build# calc3bison -y -d calc3.yflex calc3.lgcc -c .docxcalc3build# calc3bison -y -d calc3.yflex calc3.lgcc -c .docx
calc3build# calc3bison -y -d calc3.yflex calc3.lgcc -c .docx
RAHUL126667
 
#include stdio.h#include stdlib.htypedef FILE stream.docx
#include stdio.h#include stdlib.htypedef FILE stream.docx#include stdio.h#include stdlib.htypedef FILE stream.docx
#include stdio.h#include stdlib.htypedef FILE stream.docx
katherncarlyle
 
The following is my code for a connectn program. When I run my code .pdf
The following is my code for a connectn program. When I run my code .pdfThe following is my code for a connectn program. When I run my code .pdf
The following is my code for a connectn program. When I run my code .pdf
eyelineoptics
 
assign4assign4_part1bonnie.c This is a file system ben.docx
assign4assign4_part1bonnie.c  This is a file system ben.docxassign4assign4_part1bonnie.c  This is a file system ben.docx
assign4assign4_part1bonnie.c This is a file system ben.docx
festockton
 
I have the following code and I need to know why I am receiving the .pdf
I have the following code and I need to know why I am receiving the .pdfI have the following code and I need to know why I am receiving the .pdf
I have the following code and I need to know why I am receiving the .pdf
ezzi552
 
includestdio.h #includestdlib.h int enqueue(struct node ,.pdf
includestdio.h #includestdlib.h int enqueue(struct node ,.pdfincludestdio.h #includestdlib.h int enqueue(struct node ,.pdf
includestdio.h #includestdlib.h int enqueue(struct node ,.pdf
galagirishp
 
Program of sorting using shell sort #include stdio.h #de.pdf
 Program of sorting using shell sort  #include stdio.h #de.pdf Program of sorting using shell sort  #include stdio.h #de.pdf
Program of sorting using shell sort #include stdio.h #de.pdf
anujmkt
 
Add a 3rd field help that contains a short help string for each of t.pdf
Add a 3rd field help that contains a short help string for each of t.pdfAdd a 3rd field help that contains a short help string for each of t.pdf
Add a 3rd field help that contains a short help string for each of t.pdf
info245627
 
Ifgqueue.h#ifndef LFGQUEUE_H #define LFGQUEUE_H#include pl.pdf
Ifgqueue.h#ifndef LFGQUEUE_H #define LFGQUEUE_H#include pl.pdfIfgqueue.h#ifndef LFGQUEUE_H #define LFGQUEUE_H#include pl.pdf
Ifgqueue.h#ifndef LFGQUEUE_H #define LFGQUEUE_H#include pl.pdf
fazilfootsteps
 
The main class of the tictoe game looks like.public class Main {.pdf
The main class of the tictoe game looks like.public class Main {.pdfThe main class of the tictoe game looks like.public class Main {.pdf
The main class of the tictoe game looks like.public class Main {.pdf
asif1401
 
package com.tictactoe; public class Main {public void play() {.pdf
package com.tictactoe; public class Main {public void play() {.pdfpackage com.tictactoe; public class Main {public void play() {.pdf
package com.tictactoe; public class Main {public void play() {.pdf
info430661
 
#include stdio.h#include stdlib.h#include string.h#inclu.pdf
#include stdio.h#include stdlib.h#include string.h#inclu.pdf#include stdio.h#include stdlib.h#include string.h#inclu.pdf
#include stdio.h#include stdlib.h#include string.h#inclu.pdf
apleather
 
Start with the inclusion of libraries#include iostream .docx
 Start with the inclusion of libraries#include iostream .docx Start with the inclusion of libraries#include iostream .docx
Start with the inclusion of libraries#include iostream .docx
MARRY7
 
Getting the following errorsError 1 error C2436 {ctor} mem.pdf
Getting the following errorsError 1 error C2436 {ctor}  mem.pdfGetting the following errorsError 1 error C2436 {ctor}  mem.pdf
Getting the following errorsError 1 error C2436 {ctor} mem.pdf
herminaherman
 
RightTrianglerightTriangle.cppRightTrianglerightTriangle.cpp.docx
RightTrianglerightTriangle.cppRightTrianglerightTriangle.cpp.docxRightTrianglerightTriangle.cppRightTrianglerightTriangle.cpp.docx
RightTrianglerightTriangle.cppRightTrianglerightTriangle.cpp.docx
joellemurphey
 

Similaire à AI For Texam Hold'em poker (20)

calc3build# calc3bison -y -d calc3.yflex calc3.lgcc -c .docx
calc3build# calc3bison -y -d calc3.yflex calc3.lgcc -c .docxcalc3build# calc3bison -y -d calc3.yflex calc3.lgcc -c .docx
calc3build# calc3bison -y -d calc3.yflex calc3.lgcc -c .docx
 
#include stdio.h#include stdlib.htypedef FILE stream.docx
#include stdio.h#include stdlib.htypedef FILE stream.docx#include stdio.h#include stdlib.htypedef FILE stream.docx
#include stdio.h#include stdlib.htypedef FILE stream.docx
 
c programming
c programmingc programming
c programming
 
The following is my code for a connectn program. When I run my code .pdf
The following is my code for a connectn program. When I run my code .pdfThe following is my code for a connectn program. When I run my code .pdf
The following is my code for a connectn program. When I run my code .pdf
 
assign4assign4_part1bonnie.c This is a file system ben.docx
assign4assign4_part1bonnie.c  This is a file system ben.docxassign4assign4_part1bonnie.c  This is a file system ben.docx
assign4assign4_part1bonnie.c This is a file system ben.docx
 
I have the following code and I need to know why I am receiving the .pdf
I have the following code and I need to know why I am receiving the .pdfI have the following code and I need to know why I am receiving the .pdf
I have the following code and I need to know why I am receiving the .pdf
 
DS Code (CWH).docx
DS Code (CWH).docxDS Code (CWH).docx
DS Code (CWH).docx
 
Game unleashedjavascript
Game unleashedjavascriptGame unleashedjavascript
Game unleashedjavascript
 
includestdio.h #includestdlib.h int enqueue(struct node ,.pdf
includestdio.h #includestdlib.h int enqueue(struct node ,.pdfincludestdio.h #includestdlib.h int enqueue(struct node ,.pdf
includestdio.h #includestdlib.h int enqueue(struct node ,.pdf
 
Program of sorting using shell sort #include stdio.h #de.pdf
 Program of sorting using shell sort  #include stdio.h #de.pdf Program of sorting using shell sort  #include stdio.h #de.pdf
Program of sorting using shell sort #include stdio.h #de.pdf
 
Add a 3rd field help that contains a short help string for each of t.pdf
Add a 3rd field help that contains a short help string for each of t.pdfAdd a 3rd field help that contains a short help string for each of t.pdf
Add a 3rd field help that contains a short help string for each of t.pdf
 
Ifgqueue.h#ifndef LFGQUEUE_H #define LFGQUEUE_H#include pl.pdf
Ifgqueue.h#ifndef LFGQUEUE_H #define LFGQUEUE_H#include pl.pdfIfgqueue.h#ifndef LFGQUEUE_H #define LFGQUEUE_H#include pl.pdf
Ifgqueue.h#ifndef LFGQUEUE_H #define LFGQUEUE_H#include pl.pdf
 
The main class of the tictoe game looks like.public class Main {.pdf
The main class of the tictoe game looks like.public class Main {.pdfThe main class of the tictoe game looks like.public class Main {.pdf
The main class of the tictoe game looks like.public class Main {.pdf
 
package com.tictactoe; public class Main {public void play() {.pdf
package com.tictactoe; public class Main {public void play() {.pdfpackage com.tictactoe; public class Main {public void play() {.pdf
package com.tictactoe; public class Main {public void play() {.pdf
 
c++ project on restaurant billing
c++ project on restaurant billing c++ project on restaurant billing
c++ project on restaurant billing
 
#include stdio.h#include stdlib.h#include string.h#inclu.pdf
#include stdio.h#include stdlib.h#include string.h#inclu.pdf#include stdio.h#include stdlib.h#include string.h#inclu.pdf
#include stdio.h#include stdlib.h#include string.h#inclu.pdf
 
Start with the inclusion of libraries#include iostream .docx
 Start with the inclusion of libraries#include iostream .docx Start with the inclusion of libraries#include iostream .docx
Start with the inclusion of libraries#include iostream .docx
 
Getting the following errorsError 1 error C2436 {ctor} mem.pdf
Getting the following errorsError 1 error C2436 {ctor}  mem.pdfGetting the following errorsError 1 error C2436 {ctor}  mem.pdf
Getting the following errorsError 1 error C2436 {ctor} mem.pdf
 
COnnect4Game
COnnect4GameCOnnect4Game
COnnect4Game
 
RightTrianglerightTriangle.cppRightTrianglerightTriangle.cpp.docx
RightTrianglerightTriangle.cppRightTrianglerightTriangle.cpp.docxRightTrianglerightTriangle.cppRightTrianglerightTriangle.cpp.docx
RightTrianglerightTriangle.cppRightTrianglerightTriangle.cpp.docx
 

Dernier

Desi Bhabhi Call Girls In Goa 💃 730 02 72 001💃desi Bhabhi Escort Goa
Desi Bhabhi Call Girls  In Goa  💃 730 02 72 001💃desi Bhabhi Escort GoaDesi Bhabhi Call Girls  In Goa  💃 730 02 72 001💃desi Bhabhi Escort Goa
Desi Bhabhi Call Girls In Goa 💃 730 02 72 001💃desi Bhabhi Escort Goa
russian goa call girl and escorts service
 
Zirakpur Call Girls👧 Book Now📱8146719683 📞👉Mohali Call Girl Service No Advanc...
Zirakpur Call Girls👧 Book Now📱8146719683 📞👉Mohali Call Girl Service No Advanc...Zirakpur Call Girls👧 Book Now📱8146719683 📞👉Mohali Call Girl Service No Advanc...
Zirakpur Call Girls👧 Book Now📱8146719683 📞👉Mohali Call Girl Service No Advanc...
rajveermohali2022
 
Nayabad Call Girls ✔ 8005736733 ✔ Hot Model With Sexy Bhabi Ready For Sex At ...
Nayabad Call Girls ✔ 8005736733 ✔ Hot Model With Sexy Bhabi Ready For Sex At ...Nayabad Call Girls ✔ 8005736733 ✔ Hot Model With Sexy Bhabi Ready For Sex At ...
Nayabad Call Girls ✔ 8005736733 ✔ Hot Model With Sexy Bhabi Ready For Sex At ...
aamir
 
CHEAP Call Girls in Malviya Nagar, (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in  Malviya Nagar, (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in  Malviya Nagar, (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Malviya Nagar, (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Dernier (20)

VIP Model Call Girls Koregaon Park ( Pune ) Call ON 8005736733 Starting From ...
VIP Model Call Girls Koregaon Park ( Pune ) Call ON 8005736733 Starting From ...VIP Model Call Girls Koregaon Park ( Pune ) Call ON 8005736733 Starting From ...
VIP Model Call Girls Koregaon Park ( Pune ) Call ON 8005736733 Starting From ...
 
Behala ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Ready ...
Behala ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Ready ...Behala ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Ready ...
Behala ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Ready ...
 
Desi Bhabhi Call Girls In Goa 💃 730 02 72 001💃desi Bhabhi Escort Goa
Desi Bhabhi Call Girls  In Goa  💃 730 02 72 001💃desi Bhabhi Escort GoaDesi Bhabhi Call Girls  In Goa  💃 730 02 72 001💃desi Bhabhi Escort Goa
Desi Bhabhi Call Girls In Goa 💃 730 02 72 001💃desi Bhabhi Escort Goa
 
Zirakpur Call Girls👧 Book Now📱8146719683 📞👉Mohali Call Girl Service No Advanc...
Zirakpur Call Girls👧 Book Now📱8146719683 📞👉Mohali Call Girl Service No Advanc...Zirakpur Call Girls👧 Book Now📱8146719683 📞👉Mohali Call Girl Service No Advanc...
Zirakpur Call Girls👧 Book Now📱8146719683 📞👉Mohali Call Girl Service No Advanc...
 
Bhimtal ❤CALL GIRL 8617697112 ❤CALL GIRLS IN Bhimtal ESCORT SERVICE❤CALL GIRL
Bhimtal ❤CALL GIRL 8617697112 ❤CALL GIRLS IN Bhimtal ESCORT SERVICE❤CALL GIRLBhimtal ❤CALL GIRL 8617697112 ❤CALL GIRLS IN Bhimtal ESCORT SERVICE❤CALL GIRL
Bhimtal ❤CALL GIRL 8617697112 ❤CALL GIRLS IN Bhimtal ESCORT SERVICE❤CALL GIRL
 
Model Call Girls In Velappanchavadi WhatsApp Booking 7427069034 call girl ser...
Model Call Girls In Velappanchavadi WhatsApp Booking 7427069034 call girl ser...Model Call Girls In Velappanchavadi WhatsApp Booking 7427069034 call girl ser...
Model Call Girls In Velappanchavadi WhatsApp Booking 7427069034 call girl ser...
 
Nayabad Call Girls ✔ 8005736733 ✔ Hot Model With Sexy Bhabi Ready For Sex At ...
Nayabad Call Girls ✔ 8005736733 ✔ Hot Model With Sexy Bhabi Ready For Sex At ...Nayabad Call Girls ✔ 8005736733 ✔ Hot Model With Sexy Bhabi Ready For Sex At ...
Nayabad Call Girls ✔ 8005736733 ✔ Hot Model With Sexy Bhabi Ready For Sex At ...
 
Model Call Girls In Ariyalur WhatsApp Booking 7427069034 call girl service 24...
Model Call Girls In Ariyalur WhatsApp Booking 7427069034 call girl service 24...Model Call Girls In Ariyalur WhatsApp Booking 7427069034 call girl service 24...
Model Call Girls In Ariyalur WhatsApp Booking 7427069034 call girl service 24...
 
Verified Trusted Call Girls Ambattur Chennai ✔✔7427069034 Independent Chenna...
Verified Trusted Call Girls Ambattur Chennai ✔✔7427069034  Independent Chenna...Verified Trusted Call Girls Ambattur Chennai ✔✔7427069034  Independent Chenna...
Verified Trusted Call Girls Ambattur Chennai ✔✔7427069034 Independent Chenna...
 
Kanpur call girls 📞 8617697112 At Low Cost Cash Payment Booking
Kanpur call girls 📞 8617697112 At Low Cost Cash Payment BookingKanpur call girls 📞 8617697112 At Low Cost Cash Payment Booking
Kanpur call girls 📞 8617697112 At Low Cost Cash Payment Booking
 
Hotel And Home Service Available Kolkata Call Girls Howrah ✔ 6297143586 ✔Call...
Hotel And Home Service Available Kolkata Call Girls Howrah ✔ 6297143586 ✔Call...Hotel And Home Service Available Kolkata Call Girls Howrah ✔ 6297143586 ✔Call...
Hotel And Home Service Available Kolkata Call Girls Howrah ✔ 6297143586 ✔Call...
 
Independent Sonagachi Escorts ✔ 9332606886✔ Full Night With Room Online Booki...
Independent Sonagachi Escorts ✔ 9332606886✔ Full Night With Room Online Booki...Independent Sonagachi Escorts ✔ 9332606886✔ Full Night With Room Online Booki...
Independent Sonagachi Escorts ✔ 9332606886✔ Full Night With Room Online Booki...
 
Sonagachi ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...
Sonagachi ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...Sonagachi ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...
Sonagachi ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...
 
Model Call Girls In Pazhavanthangal WhatsApp Booking 7427069034 call girl ser...
Model Call Girls In Pazhavanthangal WhatsApp Booking 7427069034 call girl ser...Model Call Girls In Pazhavanthangal WhatsApp Booking 7427069034 call girl ser...
Model Call Girls In Pazhavanthangal WhatsApp Booking 7427069034 call girl ser...
 
Call Girls Manjri Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Manjri Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Manjri Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Manjri Call Me 7737669865 Budget Friendly No Advance Booking
 
Science City Kolkata ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sex...
Science City Kolkata ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sex...Science City Kolkata ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sex...
Science City Kolkata ( Call Girls ) Kolkata ✔ 6297143586 ✔ Hot Model With Sex...
 
Top Rated Pune Call Girls Dhayari ⟟ 6297143586 ⟟ Call Me For Genuine Sex Ser...
Top Rated  Pune Call Girls Dhayari ⟟ 6297143586 ⟟ Call Me For Genuine Sex Ser...Top Rated  Pune Call Girls Dhayari ⟟ 6297143586 ⟟ Call Me For Genuine Sex Ser...
Top Rated Pune Call Girls Dhayari ⟟ 6297143586 ⟟ Call Me For Genuine Sex Ser...
 
Hotel And Home Service Available Kolkata Call Girls South End Park ✔ 62971435...
Hotel And Home Service Available Kolkata Call Girls South End Park ✔ 62971435...Hotel And Home Service Available Kolkata Call Girls South End Park ✔ 62971435...
Hotel And Home Service Available Kolkata Call Girls South End Park ✔ 62971435...
 
CHEAP Call Girls in Malviya Nagar, (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in  Malviya Nagar, (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in  Malviya Nagar, (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Malviya Nagar, (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
VIP Model Call Girls Vijayawada ( Pune ) Call ON 8005736733 Starting From 5K ...
VIP Model Call Girls Vijayawada ( Pune ) Call ON 8005736733 Starting From 5K ...VIP Model Call Girls Vijayawada ( Pune ) Call ON 8005736733 Starting From 5K ...
VIP Model Call Girls Vijayawada ( Pune ) Call ON 8005736733 Starting From 5K ...
 

AI For Texam Hold'em poker

  • 1. #include <stdio.h> #include <conio.h> #include <stdlib.h> #include <time.h> #include <iostream> #include <algorithm> #include <string.h> #include <vector> #include <fstream> #include <string> using namespace std; # define INPUT_FILE "inputf.txt" # define DEAL_FILE "deal.txt" # define DEALS_MONEY "deals_money.txt" # define RIVER_CARDS "river_cards.txt" # define CHECKPATTERN_FILE "checkpattern.txt" # define PRE_FLOP 1 # define FLOP 2 # define FOURTH_STREET 3 # define FIFTH_STREET 4 # define SHOW_DOWN 5 # define SKIP_NEWLINE while(*ptr == 10 || *ptr==13){ptr++;} # define FIRST (int)'A' # define CALL (int)'C' # define RISE (int)'R' # define FOLD (int)'F' # define FOLDED (int) '-' # define BLUFF (int)'B' # define VERY_GOOD 5 # define GOOD 4 # define AVG 3 # define BAD 2 # define VERY_BAD 1 # define HIGH 1 # define LOW 0 # define OFFENSIVE 1 # define DEFENSIVE 2 # define ULTRA_DEFENSIVE 3 struct player { int handCard1; int handCard2; int team; int bet; int money_remaining; }; short int players_data_move[7][5][500]={0}; /* [TEAM NUMBER][STAGE][ROUND] */ short int players_data_bet[7][5][500]={0}; /* [TEAM NUMBER][STAGE][ROUND] */
  • 2. short int pot_money[7][5][500]={0}; /* [TEAM NUMBER][STAGE][ROUND] */ short int players_hand_card_1[7]; /* [TEAM NUMBER] */ short int players_hand_card_2[7]; /* [TEAM NUMBER] */ short int river_cards[5],r_count=0; /* [STAGE] */ short int player_p_values[7][5]; /* [TEAM NUMBER][STAGE] */ short int checkPattern[6][5][4][3][7] ={0}; /* [PVALUE][ACTION][REACTION][STAGE][TEAMNUMBER] */ int round_number[5]; /* [STAGE] */ int p_ratio[6]; /* [PVALUE] */ int reaction_ratio[5]; /* [REACTION] */ bool players_folded[7]; /* [TEAM NUMBER] */ short int number_of_folds; /* Stores the Number of Folds */ short int play_mode; /* 1 :: OFFENSIVE | 2 :: DEFENSIVE | 3 :: ULTRA DEFENSIVE */ short int number_of_deals; /* Stores the Number of Deals */ player players[7]; int deal_number; /* Represents the nth deal */ bool is_show_down; /* Tells if its Show Down or not */ bool stagePlayed[6]={0}; /* Bool of Stages Played */ bool playersEliminated[7]; /* [TEAM NUMBER] */ short int num_players_eliminated = 0; void printPlayerDetails(player p); void read_file(char *name,char *data); int getInt(char *data); int decode_input_file(char *data); int decode_dealsMoney(char *data); void getString(char *str,char *data); int decode_dealFile(char *data,int *stage,int *main_pot); void read_showDown_handCards(char *data); void get_current_state_players(char *data,int stage,int self_teamNumber,int dealer); void set_play_mode(int self_team_number); int defensive_play(int stage,int *all_cards,int n_total_cards,int self_team_number,int dealer); bool is_bluffsMore(short int team_number); int get_minimum_raise(short int stage,short int team_number,short int dealer); short int get_rank(int self_team_number); void set_p_ratio(); void set_reaction_ratio(); void set_player_folded(); bool is_FirstTurn(short int dealer, short int self_team_number); short int checkPattern_p(int action,int reaction, int stage ,int team,int detail); short int checkPattern_action(int p_value,int action,int reaction, int stage ,int team,int detail); int catagorize_move(int p_move); void analyze_data(int self_teamNumber,int dealer); int offensive(int stage,int *cards,int total,int teamno,int dealer); int getMove(int stage,int phand,int *team,int teamno,int dealer);
  • 3. int bluff(int rise, int limit); int lowraise(int bet); int compare (const void * a, const void * b); int pcounter(int *cards,int hand,int total); int highcard(int *hole,int hand); int pairs(int *cards,int *allpairs,int total); int twoofakind(int *allpairs,int paircards,int *hole,int hand); int twopair(int *allpairs,int paircards,int *hole,int hand); int threeofakind(int *allpairs,int paircards,int *cards,int total,int *hole , int hand); int straight(int *cards,int total,int *hole,int hand); int flush(int *cards,int total,int *hole,int hand); int fullhouse(int *allpairs,int paircards,int *cards,int total,int *hole , int hand ); int fourofakind(int *allpairs,int paircards,int *hole,int hand); int striaghtflush(int *cards,int total,int *hole,int hand); int priver(int*cards,int hand,int total); int pgrader(int probab , int stage); int ppreflop(int hand1,int hand2); int pfuture(int *cards,int total); int futurestraight(int *cards,int total); int futureflush(int *cards, int total); int overallp(int*cards,int total,int stage); void start_deal(char *data,int self_teamNumber,int *players_left); int anyoppraisehigh(int stage,int round,int firstplayer,int myteamno,int dealer); void printPlayerDetails(player p) { cout << "n Hand 1 = " << p.handCard1; cout << "n Hand 2 = " << p.handCard2; cout << "n Team Number = " << p.team; cout << "n Current Round Bet = " << p.bet; } void read_file(char *name,char *data) { FILE *file; file = fopen(name, "rb"); fread(data,1000,1,file); fclose(file); } char *ptr; char *ptr_startReading; int getInt(char *data) { int temp=0; while(*ptr < '0' || *ptr > '9' ) ptr++; while(*ptr >= '0' && *ptr <= '9') { temp = temp*10 + (*ptr - '0');
  • 4. ptr++; } return temp; } int decode_input_file(char *data) { ptr = data; int t1,t2,t3; t1 = getInt(data); t2 = getInt(data); t3 = getInt(data); players[t3].team = t3; players[t3].handCard1 = t1; //cout << "nHAND CARD 1 = " << t1; players[t3].handCard2 = t2; //cout << "nHAND CARD 2 = " << t2; players[t3].bet = getInt(data); //cout << "nTEAM NUMBER = " << t3; return t3; } int decode_dealsMoney(char *data) { ptr = data; player *p; int temp,deal; p = players; //deal = getInt(data); string read_str; ifstream fin; fin.open(DEALS_MONEY,ios::in); fin >> read_str; fin >> read_str; deal = atoi(read_str.c_str()); for(temp=1;temp<=6;temp++) { //p->team = getInt(data); //p->money_remaining = getInt(data); //p++; fin >> read_str; fin >> read_str; players[temp].money_remaining= atoi(read_str.c_str()); if(players[temp].money_remaining == 0) { playersEliminated[temp]=true; num_players_eliminated++; } }
  • 5. fin.close(); return deal; } void getString(char *str,char *data) { while(!(*ptr == '-' || *ptr == '_' || (*ptr >= 'a' && *ptr <= 'z') || (*ptr >= 'A' && *ptr <= 'Z'))) ptr++; while((*ptr >= 'a' && *ptr <= 'z') || (*ptr >= 'A' && *ptr <= 'Z') || *ptr=='_' || *ptr == '-') { *str = *ptr; str++; ptr++; } *str='0'; } int decode_dealFile(char *data,int *stage,int *main_pot) { ptr = data; int dealer = getInt(data); char str[100]; getString(str,data); //cout << "n First Str = "; puts(str); getString(str,data); //cout << "n Second Str = "; puts(str); if(!strcmp("Show_Down",str)) *stage = SHOW_DOWN; else if(!strcmp("Pre_Flop",str)) *stage = PRE_FLOP; else if(!strcmp("Flop",str)) *stage = FLOP; else if(!strcmp("Fourth_Street",str)) *stage = FOURTH_STREET; else if(!strcmp("Fifth_Street",str)) *stage = FIFTH_STREET; *main_pot = getInt(data); ptr_startReading = ptr; return dealer; } void read_showDown_handCards(char *data) { ofstream fout; string file_name,temp_file; int card;
  • 6. for(int xx=1;xx<=6;xx++) { file_name = "team"; string bet_name = "_bet.txt"; file_name = file_name + bet_name; temp_file = (char)(xx + 48); file_name = file_name+temp_file; fout.open(file_name.c_str(),ios::app); //fout.open("test.txt",ios::app); card = getInt(data);/* Temp storage for value we dont need */ fout << getInt(data) << "n" << getInt(data) << "n"; fout.close(); } } /* ptr continues from the previous point.Its a global variable */ void get_current_state_players(char *data,int stage,int self_teamNumber,int dealer) { cout << "n Started Reading Rest of Deal File"; ptr = ptr_startReading; string stage_name; int count_new_cards; int river[3]; //int round_count; switch(stage) { case 1:stage_name = "Pre_Flop";count_new_cards = 0;break; case 2:stage_name = "Flop";count_new_cards = 3;break; case 3:stage_name = "Fourth_Street";count_new_cards = 1;break; case 4:stage_name = "Fifth_Street";count_new_cards = 1;break; case 5:stage_name = "Show_Down";count_new_cards = 0;break; } ofstream fout_river; string file_name; string temp_file; string move; int bet; int t_round = 1; int cur_stage = 1; ifstream fin; fin.open("deal.txt",ios::in); string t_str; while(t_str != "Pre_Flop") fin >> t_str; bool end_round=false; bool end_stage=false;
  • 7. fout_river.open(RIVER_CARDS,ios::out); fin >> t_str; int prevv=0; while(!fin.eof()) { int xx; xx=atoi(t_str.c_str()); if(cur_stage == 5) { //cout << "nxx = " << xx; cout << "n Reading Hand Cards"; fin >> t_str; players_hand_card_1[xx]=atoi(t_str.c_str()); fin >> t_str; players_hand_card_2[xx]=atoi(t_str.c_str()); if(xx==6) { /*cout << "n"; for (int zz = 1;zz<=6;zz++) { cout <<zz<<" - " << players_hand_card_1[zz]; cout <<" " << players_hand_card_2[zz]; cout << "n"; } getch();*/ fout_river.close(); return; } fin >> t_str; } else { if(xx == dealer) end_round = true; fin >> move; if(move == "End" || t_str == "End") { cout << "nEnd Reached.Stage Should Change"; round_number[cur_stage] = t_round; cur_stage++; ofstream fout; fout.open("Round_Counts.txt",ios::app); fout << t_round << "n"; fout.close(); t_round=1; switch(cur_stage) {
  • 8. case 1:stage_name = "Pre_Flop";count_new_cards = 0;break; case 2:stage_name = "Flop";count_new_cards = 3;break; case 3:stage_name = "Fourth_Street";count_new_cards = 1;break; case 4:stage_name = "Fifth_Street";count_new_cards = 1;break; case 5:stage_name = "Show_Down";count_new_cards = 0;break; } while(move != stage_name && move != "Show_Down") fin >> move; if(move == "Show_Down") { cur_stage = 5; count_new_cards=0; is_show_down = true; } stagePlayed[cur_stage] = true; for(int xx=0;xx<count_new_cards;xx++) { fin >> t_str; river[xx] = atoi(t_str.c_str()); fout_river << river [xx] << "n"; } fin >> t_str; } else { if(move != "-") { fin >> t_str; bet = atoi(t_str.c_str()); } else bet = 0; cout << "n Move = " << move << " " << bet; players_data_move[xx][cur_stage][t_round] = (int)move[0]; players_data_bet[xx][cur_stage][t_round] = bet; pot_money[xx][cur_stage][t_round] = prevv; cout << "n Pot Money = " << prevv; //getch(); if(players_data_move[xx][cur_stage][t_round] != FOLD) prevv = bet; if(end_round == true) t_round++; /* } */ end_round = false; end_stage = false; fin >> t_str; } } }
  • 9. cout << "nStage = " <<stage << " t_round = " << t_round; round_number[stage]=t_round; fout_river.close(); //getch(); return ; } void set_play_mode(int self_team_number) { int money_total=0; for(int xx=1;xx<=6;xx++) money_total=money_total+players[xx].money_remaining; int mean= money_total/(6-num_players_eliminated); cout << "nMean Money = " << mean << "n2/3rd of Mean = " <<(2*mean)/3 << "nRank = " << get_rank(self_team_number); if(players[self_team_number].money_remaining >=500 && ((get_rank(self_team_number) <=(2*(6-num_players_eliminated))/3) || num_players_eliminated >=3)) play_mode = OFFENSIVE; else play_mode = DEFENSIVE; cout << "nPlay Mode = "<<play_mode; //getch(); /* SET BRUTEFORE play_mode - Until Rank is Top 3 or until Money doesnt go below 500 or 800 deals */ // Remove the Comments below to Activate Ultra Defensive modee // /* play_mode = ULTRA_DEFENSIVE; if(get_rank(self_team_number) <=3 || players[self_team_number].money_remaining <= 500 || deal_number >= 800) play_mode = OFFENSIVE; */ } /* stage = The current Stage all_cards = All cards including hand card and river Card. (First two Cards as Hand Cards n_total_cards = Total Number of Cards = River Cards + 2 Hand Cards self_team_number = The team number who has to return a Reply dealer = the dealer for the current deal */ int defensive_play(int stage,int *all_cards,int n_total_cards,int self_team_number,int dealer) { /* An array that stores all the Cards , including Hand Cards (as 1st 2 cards) & and River Cards to call "overallp" function */
  • 10. /*static int all_cards[7]; */ /*all_cards[0] = players_hand_card_1[self_team_number]; */ /*all_cards[1] = players_hand_card_2[self_team_number]; */ /*for(int xx = 2;xx < 2+n_river_cards;xx++) */ /* all_cards[xx] = river_cards[xx-2]; */ int p_hand = overallp(all_cards, n_total_cards, stage); if(!(p_hand == VERY_GOOD || p_hand == GOOD)) /* The Case of Fold */ return -10;/*fold*/ return offensive(stage,all_cards,n_total_cards,self_team_number,dealer); } /* Returns true or 1 if the player bluffs atleast twice as more else false oe 0 */ bool is_bluffsMore(short int team_number) { int rise_counter=1; int bluff_counter=1; for(int xx = 1;xx<=6;xx++) for(int yy = 1;yy<5;yy++) for(int zz=1;zz<=round_number[yy];zz++) { if(players_data_move[xx][yy][zz] == RISE) rise_counter++; if(players_data_move[xx][yy][zz] == BLUFF) bluff_counter++; } if(rise_counter*2 <= bluff_counter) return true; else return false; } int get_minimum_raise(short int stage,short int team_number,short int dealer) { if(stage == 5) return 0; int cur_round=round_number[stage]; int cur_player=team_number-1; int cur_stage = stage; cout << "nStart Round = " << cur_round; while(cur_round >= 0) { if(cur_player == 0)cur_player=6; if(cur_player == dealer)cur_round--; if(cur_round == 0) { cur_stage--; cur_round=round_number[cur_stage]; }
  • 11. cout << "nCur Player = " << cur_player << " cur_stage = " << cur_stage << " cur_round = " <<cur_round; cout << "nPot Money = " << pot_money[cur_player][cur_stage][cur_round]; cout << "nRaise = " << (players_data_bet[cur_player][cur_stage][cur_round]- pot_money[cur_player][cur_stage][cur_round]); cout << "nRise Amounts = " << players_data_bet[cur_player][cur_stage][cur_round]; if(players_data_move[cur_player][cur_stage][cur_round] == RISE) { cout << "nFinally Rise = " << players_data_bet[cur_player][cur_stage][cur_round]- pot_money[cur_player][cur_stage][cur_round]; if(players_data_bet[cur_player][cur_stage][cur_round]- pot_money[cur_player][cur_stage][cur_round] == 0 || players_data_bet[cur_player][cur_stage][cur_round]-pot_money[cur_player][cur_stage][cur_round] == 5) return 10; //getch(); return (players_data_bet[cur_player][cur_stage][cur_round]- pot_money[cur_player][cur_stage][cur_round]); } cur_player--; } return 0; } /* Returns your rank on calling */ short int get_rank(int self_team_number) { short int rank=6; for(int xx = 1;xx<=6;xx++) { if(xx == self_team_number) continue; if(players[xx].money_remaining <=players[self_team_number].money_remaining) rank--; } return rank; } /* Sets the value of all elements in Array p_ratio as 0 */ void set_p_ratio() { for (int xx=0;xx<6; xx++) p_ratio[xx]=0; } /* Sets the value of all elements in Array reaction_ratio as 0 */ void set_reaction_ratio()
  • 12. { for (int xx=0;xx<=4; xx++) reaction_ratio[xx]=0; } /* Sets the value of all elements in Array players_folded as false */ void set_player_folded() { for(int xx=1;xx<=6;xx++) players_folded[xx] = false; } /* Returns 1 or "true" , if our first turn, else returns 0 or "false" */ bool is_FirstTurn(short int dealer, short int self_team_number) { int s_pos = dealer+1; while(s_pos != self_team_number && !(s_pos == 7 && self_team_number == 1)) { if(s_pos == 7) s_pos = 1; if(players_folded[s_pos] == false) return false; s_pos++; } return true; } /* Function Returns the p_value */ /* VERY_GOOD 5 */ /* GOOD 4 */ /* AVG 3 */ /* BAD 2 */ /* VERY_BAD 1 */ short int checkPattern_p(int action,int reaction, int stage ,int team,int detail = LOW) { /* Action :: What the other opponent Do */ /* Reaction :: What this team does for the given action */ /* Stage :: Stage for which data is required */ /* Team :: Team number for which the data is required */ /* Detail :: How much deatil to check the Patter */ /* HIGH - Check exact match */ /* LOW - Ignore Stage */ /* Set p_ratio array as 0 */ set_p_ratio(); /* Declare the Array to store CheckPattern */ short int max;
  • 13. /* Read the CheckPattern File and save it in the Array */ FILE *file; file = fopen(CHECKPATTERN_FILE,"rb"); if(file != NULL) { fread(checkPattern,sizeof(int)*6*5*4*3*7,1,file); fclose(file); } if (detail == LOW) { max = 0; for(int xx = 1;xx<=5;xx++) /* For What P Value */ { p_ratio[xx] = checkPattern[xx][action][reaction][stage][team]; if(checkPattern[max][action][reaction][stage][team] <= checkPattern[xx][action][reaction][stage][team]) max = xx; } return max; } else { max = 0; for(int xx=1; xx<=5; xx++) /* For What P-Value */ for(int zz = 0; zz < 4;zz++) /* For Any Stage */ { p_ratio[xx] = checkPattern[xx][action][reaction][zz][team]; if(checkPattern[max][action][reaction][zz][team] <= checkPattern[xx][action][reaction][zz][team]) max = xx; } return max; } } /* Function Returns an Action */ /* RISE :: 3 */ /* FOLD :: 2 */ /* CALL :: 1 */ /* BLUFF :: 4 */ /* It is based on priority */ short int checkPattern_action(int p_value,int action, int stage ,int team,int detail = LOW) { /* p_value :: P_Value for which the reaction is reqd */ /* Action :: What the other opponent Do */ /* Reaction :: What this team does for the given action */ /* Stage :: Stage for which data is required */ /* Team :: Team number for which the data is required */
  • 14. /* Detail :: How much deatil to check the Patter */ /* HIGH - Check exact match */ /* LOW - Ignore Stage */ /* Declare the Array to store CheckPattern */ /* Set p_ratio array as 0 */ set_reaction_ratio(); short int max; /* Read the CheckPattern File and save it in the Array */ FILE *file; file = fopen(CHECKPATTERN_FILE,"rb"); if(file!=NULL) { fread(checkPattern,sizeof(int)*6*5*4*3*7,1,file); fclose(file); } if (detail == LOW) { max = 0; for(int xx = 0;xx<4;xx++) /* For What Reaction */ { reaction_ratio[xx] = checkPattern[p_value][action][xx][stage][team]; if(checkPattern[p_value][action][max][stage][team] <= checkPattern[p_value][action][xx][stage][team]) max = xx; } return max; } else { max = 0; for(int xx=1; xx<=5; xx++) /* For What Reaction */ for(int zz = 1; zz <= 5;zz++) /* For Any Value of P */ { reaction_ratio[xx] = checkPattern[p_value][action][xx][zz][team]; if(checkPattern[zz][action][max][stage][team] <= checkPattern[p_value][action][xx][zz][team]) max = xx; } return max; } } int catagorize_move(int p_move) {
  • 15. /* KEY INDEX */ /* RISE :: 3 */ /* FOLD :: 2 */ /* CALL :: 1 */ /* BLUFF :: 4 */ if(p_move == CALL) return 1; if(p_move == FOLD) return 2; if(p_move == BLUFF) return 4; if(p_move == RISE) return 3; return 0; /* For error */ } void analyze_data(int self_team_number,int dealer) { /*cout << "n"; for (int xx = 1;xx<=6;xx++) { cout <<xx<<" - " << players_hand_card_1[xx]; cout <<" " << players_hand_card_2[xx]; cout << "n"; }*/ r_count=0; string file_name = "team" ; string temp_file; string t_str; ifstream fin; ifstream file1; ifstream file2; /* Order for Check Pattern :: PValue - Action - Reaction - Stage -Team Number */ //int cumulative_round_count=0; int stage =1,max_stage; int move; int counter; number_of_folds=0; /* Get all the Data from the Help Files into the two arrays declared above */ /* Read the CheckPattern File */ cout << "nCheck Pattern Read Start"; FILE *file; file = fopen(CHECKPATTERN_FILE,"rb"); if(file != NULL)
  • 16. { fread(checkPattern,sizeof(int)*6*5*4*3*7,1,file); fclose(file); } //cout << "nCHECKPATTERN = " << checkPattern[2][2][2][2][2]; cout << "n Check Pattern read complete"; /* Read all the river Cards from the Help Files */ fin.open(RIVER_CARDS,ios::in); fin >> t_str; cout << "nRiver Card Read Start"; while(!fin.eof()) { river_cards[r_count++]=atoi(t_str.c_str()); fin >>t_str; } fin.close(); cout << "nRiver Card read completenRIVER CARDS :: "; for(int mm=0;mm<r_count;mm++) cout << river_cards[mm] << " "; /* This File contains the number of rounds played at each stage in the current Deal */ fin.open("Round_Counts.txt",ios::in); /* Set player_folded array to False */ set_player_folded(); number_of_folds=0; /* Read all the Round Counts to an Array */ fin >> t_str; //round_number[stage++]=atoi(t_str.c_str()); while (!fin.eof()) { round_number[stage++]=atoi(t_str.c_str()); fin >>t_str; } fin.close(); cout << "n Read Round Numbers complete, stage = " << stage << "n ROUND NUMBERS :: "; for(int mm=1;mm<stage;mm++) cout << round_number[mm] << " "; max_stage = stage; //cout << "nSTAGE = " << stage; /* Read all the opponent moves and Bets from Help Files */ /*for(int xx = 1,yy=0;xx<=6;xx++) { stage=0; //cumulative_round_count = 0; counter = round_number[stage]; temp_file = (char)(xx + 48); file1.open((string)(file_name + "_move.txt"),ios::in); file2.open((string)(file_name + "_bet.txt"),ios::in);
  • 17. yy = 0; while(!file1.eof()) { file1 >> players_data_move[xx][round_number[stage]-counter][yy]; if(players_data_move[xx][round_number[stage]-counter][yy] == FOLD) { players_folded[xx]= true; number_of_folds++; } file2 >> players_data_bet[xx][round_number[stage]-counter][yy]; counter--; if(counter == 0) { yy=0; //cumulative_round_count = cumulative_round_count + round_number[stage]; stage++; counter = round_number[stage]; } yy++; } file1.close(); file2 >> players_hand_card_1[xx]; file2 >> players_hand_card_2[xx]; file2.close(); stage++; } */ for(int xx = 1;xx<=6;xx++) {for(int yy = 1;yy<5;yy++) {for(int zz=1;zz<=round_number[yy];zz++) {if(players_data_move[xx][yy][zz] == FOLD) { players_folded[xx]=true; number_of_folds++; }}}} cout << "nAnalyze Fold Data Complete"; for(int xx=1;xx<=6;xx++) cout << xx<<":"<<players_folded[xx] << " "; players_hand_card_1[self_team_number] = players[self_team_number].handCard1; players_hand_card_2[self_team_number] = players[self_team_number].handCard2; //getch(); //cout << "nWILL IT GO THERE ? :O "; if(is_show_down == false)/* If the Stage is not ShowDown , we dont have to analyze the Data. Just store them in Arrays */ return ; stage = 5; //cout << "nCOMES HERE!!!! :D "; /* Calculate the P-Values of each player at every round */ // int preflop_river_cards[5];//Can use this array for sending to the p_value Function // int all_cards[7];
  • 18. for(int yy = 2;yy < 2+r_count;yy++) all_cards[yy] = river_cards[yy-2]; cout << "nCalculating All P Values Started"; for(int xx = 1; xx<=6 ; xx++) { all_cards[0] = players_hand_card_1[xx]; all_cards[1] = players_hand_card_2[xx]; /* Preflop */ //if(max_stage >= 1) player_p_values[xx][1] = overallp(all_cards,2,1); //cout << "n Calculated First pValue"; /* Flop */ //if(max_stage >= 2) if(stagePlayed[2] == true) player_p_values[xx][2] = overallp(all_cards,5,2); //cout << "n Calculated Second pValue"; /* Fourth Street */ //if(max_stage >= 3) if(stagePlayed[3] == true) player_p_values[xx][3] = overallp(all_cards,6,3); //cout << "n Calculated Third pValue"; /* Fifth Street */ //if(max_stage >= 4) if(stagePlayed[4] == true) player_p_values[xx][4] = overallp(all_cards,7,4); //cout << "n Calculated Fourth pValue"; } /* All data has now been stored in the required arrays */ cout << "nAll PValues Calculated"; for(int xx=1;xx<=6;xx++) { cout << "nPlayer - " << xx << "n"; for(int yy=1;yy<=4;yy++) cout << player_p_values[xx][yy] << " "; } //getch(); /* Start analyzing from the Dealer */ int current_round = 0; int number_of_rise = 0; int number_of_call = 0; int number_of_fold = 0; /* Loop to Analyze the Data Stored in all Array */ int loop_counter = 0; /* Counter for position in current Round */
  • 19. int loop_stage = 0; /* Counter for Current Stage */ int loop_start = dealer+3; /* Counter for Player Number */ int loop_pot_money = 10; /* Stores the Money in Pot for the Current Stage */ int player_bet; int player_move; bool isBluff; /* 1-Bluff 0-Not Bluff */ int player_action = (int)'A'; /* What other player did, based on priority */ while(loop_stage != 5) { if(loop_start >= 7) loop_start = loop_start-6; if(loop_start == dealer+1) loop_counter++; if(loop_counter == round_number[loop_stage]) /* Stage Over */ { loop_stage++; loop_counter=0; loop_pot_money = 0; player_action = (int)'A'; } player_bet = players_data_bet[loop_start][loop_stage][loop_counter] - loop_pot_money; pot_money[loop_start][loop_stage][loop_counter] = loop_pot_money; if(player_bet <=0) player_bet = 0; loop_pot_money = loop_pot_money + player_bet; player_move = players_data_move[loop_start][loop_stage][loop_counter]; if(player_move > player_action && player_action != FOLDED) player_action = player_move; if(player_bet != 0 && (player_p_values[loop_start][loop_stage] == BAD || player_p_values[loop_start][loop_stage] == VERY_BAD || player_p_values[loop_start][loop_stage] == AVG)) { isBluff = true; player_move = BLUFF; } else isBluff = false; checkPattern[player_p_values[loop_start][loop_stage]][catagorize_move(player_action)][ca tagorize_move(player_move)][loop_stage][loop_start]++; if(player_move == BLUFF) checkPattern[player_p_values[loop_start][loop_stage]][catagorize_move(player_action)][RI SE][loop_stage][loop_start]++; loop_start++; } /* Write The CheckPattern back to File */ cout << "nWRITE CHECKPATTERN FILE STARTED!"; file = fopen(CHECKPATTERN_FILE,"wb");
  • 20. fwrite(checkPattern,sizeof(int)*6*5*4*3*7,1,file); fclose(file); cout << "nWRITE COMPLETE"; remove("bluff.txt"); //getch(); } /* this fnctn shud be called when need to play offensive and it will return the amount of bet */ int offensive(int stage,int *cards,int total,int teamno,int dealer) { /* initialize random seed: */ /* initialization for rand function */ srand ( time(NULL) ); int phand,rise = get_minimum_raise(stage,teamno,dealer);/* rise = minimum available raise */ phand = overallp(cards,total,stage); cout << "nP Hand = " << phand; //getch(); int temp = is_FirstTurn(dealer,teamno);/* checking for first turn */ //cout << "n First Turn True/False = " << temp; if(temp == 0)/* opponent raised or called */ { /* is p vgud */ if(phand == 5) { int check = anyoppraisehigh(stage,round_number[stage],dealer + 1,teamno,dealer);/* check if opp raised high */ if(check == 1) { /* check stage */ if(stage == 1) { int choice = rand() % 4 + 1; if((choice == 1)||(choice == 2)||(choice == 3)) return 0;/* call */ else { /* high raise fnctn */ int bet = bluff(rise,4);/* 4 for high raise fnctn */ return bet; } } else if(stage == 2) { int choice = rand() % 4 + 1; if((choice == 1)||(choice ==2)) {
  • 21. /* high raise fnctn */ int bet = bluff(rise,4); return bet; } else return 0; } else if(stage == 3) { int choice = rand() % 4 + 1; if(choice ==1) return 0; else { int bet = bluff(rise,4);/*high raise fnctn*/ return bet; } } else/*last stage */ { /* high raise fntn */ int bet = bluff(rise,4); return bet; } } else/* low raise or call */ { /* stage check */ if(stage == 4) { /* high raise fnctn */ int bet = bluff(rise,4); return bet; } else if(round_number[stage] == 1)/*new card opened */ { int choice = rand() % 2 + 1; if(choice == 1) return 0;/* call */ else { int bet = bluff(rise,4); return bet; } /* high raise fntn */ } else/*no new card */ { FILE *pt; int bluffcounter = 4;
  • 22. pt = fopen("bluff.txt","rb"); if(pt != NULL)/* prev raise */ { fscanf(pt,"%d",&bluffcounter); fclose(pt); if(bluffcounter <4) { int bet = bluff(rise,4); return bet; } } else { int choice = rand() % 2 +1; if(choice == 1) return 0;/* call */ else { /* high raise fntn */ int bet = bluff(rise,4); return bet; } } } } } /* p is gud */ if(phand == 4) { //cout << "n Case of Pgood"; int value=1; int check = anyoppraisehigh(stage,round_number[stage],dealer + 1,teamno,dealer);/* check if opp raised high */ //cout << "nDid Any opponent Raise High? " << check; if(check == 1) { int temp = teamno-1; int cur_round = round_number[stage]; do { if(temp == 0) temp = 6; if(temp == dealer) cur_round--; if(cur_round <=0) {value = 0;break;} if(players_data_move[temp][stage][cur_round] == RISE) {
  • 23. int rise = players_data_bet[temp][stage][cur_round] - pot_money[temp][stage][cur_round]; if(rise > 50) { int faltu; faltu = is_bluffsMore(temp); if(faltu==0) value = faltu; } } temp--; }while(temp != teamno); if(value == 0) { int pla = 6 - number_of_folds;/* gets no of players playing on the table */ if(pla <= 3)/* check pattern fntn */ { int zz=dealer+1; int ppos=0; int still_in_play[3]={0}; do { if(zz==7) zz=1; if(players_folded[zz] == false) still_in_play[ppos++]=zz; zz++; }while(zz != dealer && !(zz==7 && dealer==1)); if(ppos==2) {still_in_play[ppos++]=0;} return getMove(stage,phand,still_in_play,teamno,dealer); } else { int count = 0; int temp=teamno-1; int still_in_play[3]={0}; int zz=0; int cur_round = round_number[stage]; do { int value; if(temp==0) temp = 6; if(temp == dealer)
  • 24. cur_round--; if(cur_round <=0) break; if((players_data_move[temp][stage][cur_round] == CALL)&&(players_data_bet[temp][stage][cur_round] - pot_money[temp][stage][cur_round] > 50)) value = is_bluffsMore(temp); if(value == 0) { count++; still_in_play[zz++]=temp; } temp--; }while(temp!=teamno); still_in_play[zz++]=teamno; if(zz==3) {still_in_play[zz++]=0;} pla = count; /* no of players who raises high and doesn;t bluff */ if(pla <= 2) return getMove(stage,phand,still_in_play,teamno,dealer); else /* check pattern */ { int choice = rand() % 2 + 1; if(choice == 1) return 0; else return -10;/* fold */ } } } else/* means opponent bluffs a lot */ { int players = 6 - number_of_folds;/* no of players playing at the table */ if(players <= 3) { int zz=dealer+1; int ppos=0; int still_in_play[3]={0}; do { if(zz==7) zz=1; if(players_folded[zz] == false) still_in_play[ppos++]=zz; zz++; }while(zz != dealer && !(zz==7 && dealer==1)); if(ppos==2)
  • 25. {still_in_play[ppos++]=0;} return getMove(stage,phand,still_in_play,teamno,dealer); /* check pattern */ } else { return 0;/*call*/ } } } else /* low call or call*/ { int players = 6 - number_of_folds;/* no of players laying at the table */ //cout << "nReached the case of chek = 0, players = "<<players; if(players <= 3) /*-----------editing left-----------*/ { int zz=dealer+1; int ppos=0; int still_in_play[3]={0}; do { if(zz==7) zz=1; if(players_folded[zz] == false) still_in_play[ppos++]=zz; zz++; }while(zz != dealer && !(zz==7 && dealer==1)); if(ppos==2) {still_in_play[ppos++]=0;} return getMove(stage,phand,still_in_play,teamno,dealer); /* check pattern */ } else { cout << "nPlayers Greater than 3"; int lowcheck=0,count=0; int temp = teamno-1; if(temp == 0 ) temp = 6; int still_in_play[7]={0}; int zz =0; int cur_round = round_number[stage]; cout << "ncur_round = " << cur_round; do { if(temp == 0)
  • 26. temp = 6; if(temp == dealer) cur_round--; if(cur_round == 0) break; cout << "ntemp = " << temp << " cur_round = " << cur_round << " stage = " << stage; if(players_data_move[temp][stage][cur_round] == RISE) { count++; still_in_play[zz++] = temp; lowcheck = 1; } temp--; }while(temp != teamno); //cout << "nNumber of Rise = " << count; //cout << "nlow check = " << lowcheck; //getch(); still_in_play[zz++] = teamno; if(zz==3) {still_in_play[zz]=0;zz++;} if(lowcheck == 1) { //cout <<"nEnter Low Check"; int pla = count;/*no of players who raised low */ if(pla <= 2) { //cout << "n Here ????"; return getMove(stage,phand,still_in_play,teamno,dealer); } else { int choice = rand() % 2 + 1; if(choice == 1) return 0;/* call */ else { //cout << "nLow Raise ? "; int bet = lowraise(rise);/* low raise call */ return bet; } } } else/*opponent called */ { int choice = rand()%2 + 1; if(choice == 1) return 0;/* call */
  • 27. else/* low raise */ { int bet = lowraise(rise); return bet; } } } } } if(phand == 3) { int bet,value; int check = anyoppraisehigh(stage,round_number[stage],dealer + 1,teamno,dealer);/* check if opp raised high */ if(check == 1)/* raises high */ { if((stage == 1)||(stage == 2)) { int temp=teamno-1;/*checking bluffs a lot*/ int cur_round = round_number[stage]; do { if(temp == 0) temp = 6; if(temp == dealer) cur_round--; if(cur_round <= 0) break; if(players_data_move[temp][stage][cur_round] == RISE) { int rise = players_data_bet[temp][stage][cur_round] - pot_money[temp][stage][cur_round]; if(rise <= 50) { int faltu; faltu = is_bluffsMore(temp); if(faltu==0) value = faltu; } } temp--; }while(temp != teamno); if(value == 1) { int choice = rand()%3 +1; if((choice == 1)||(choice == 2)) return 0;/* call */ else return -10;/*fold*/
  • 28. } else { int choice = rand()%3 +1; if((choice == 1)||(choice == 2)) return -10;/* fold */ else return 0;/*call*/ } } else/*stage 3rd or 4 */ { if(round_number[stage]==1)/*new cards opened */ { int choice = rand()%2 +1; if(choice == 1)/* bluff */ { int bet = bluff(rise,2); cout <<"n1 Bet = " << bet; //getch(); return bet; } else return -10;/*fold*/ } else/* no new card opened */ { if(players_data_move[teamno][stage][round_number[stage]-1]==RISE) { int bet = bluff(rise,2);/* bluff if allowed */ if(bet != 0) {cout <<"n1 Bet = " << bet; //getch(); return bet;} } else return -10; /* fold */ } } } else /* low raise or call */ { if((stage==1)||(stage==2)) { if(round_number[stage]==1)/*new card opened */ { int choice = rand()%2 +1; if(choice == 1)
  • 29. { int bet = bluff(rise,2); cout <<"n1 Bet = " << bet; //getch(); return bet; } else return 0;/*call*/ } else/* no new card opened */ { if(players_data_move[teamno][stage][round_number[stage]-1]==RISE) { int bet = bluff(rise,2); cout <<"n1 Bet = " << bet; //getch(); return bet; } else { return 0;/*call*/ } } } else /* stage 3 or 4 */ { if(round_number[stage]==1)/* new card opened */ { int choice = rand()%3 +1; if(choice == 1) return 0;/* call */ else if(choice == 2) return -10;/*fold*/ else { int bet = bluff(rise,2); cout <<"n1 Bet = " << bet; //getch(); return bet; } } else/* no new card opened */ { if(players_data_move[teamno][stage][round_number[stage]-1]==RISE) { int bet = bluff(rise,2);
  • 30. cout <<"n1 Bet = " << bet; //getch(); return bet; } else { int choice = rand()%2 +1; if(choice == 1) return 0;/* call */ else return -10;/*fold*/ } } } } } if(phand == 2)/* p bad */ { int check = anyoppraisehigh(stage,round_number[stage],dealer + 1,teamno,dealer);/* check if opp raised high */ if(check == 1)/*opponent raised high*/ { if(stage == 1) { int choice = rand()%4 +1; if((choice == 1)||(choice == 2)||(choice == 3)) return 0;/* call */ else return -10;/*fold*/ } else if(stage == 2) { int choice = rand()%3 +1; if(choice == 1) return 0;/* call */ else return -10;/*fold*/ } else if(stage == 3) { int choice = rand()%4 +1; if((choice == 1)||(choice == 2)||(choice == 3)) return -10;/* fold */ else return 0;/*call*/ } else/*stage 4*/ return -10;/*fold*/ } else/*low raise or call */
  • 31. { if((stage==1)||(stage==2)) { if(round_number[stage]==1)/*new card opened */ { int choice = rand()%2 +1; if(choice == 1) { int bet = bluff(rise,2); cout <<"n1 Bet = " << bet; //getch(); return bet; } else return 0;/*call*/ } else/* no new card opened */ { if(players_data_move[teamno][stage][round_number[stage]-1]==RISE) { int bet = bluff(rise,2); cout <<"n1 Bet = " << bet; //getch(); return bet; } else { return 0;/*call*/ } } } else /* stage 3 or 4 */ { if(round_number[stage]==1)/* new card opened */ { int choice = rand()%4 +1; if(choice == 1) return 0;/* call */ else if(choice == 2 || choice == 3) return -10;/*fold*/ else { int bet = bluff(rise,2); cout <<"n1 Bet = " << bet; //getch(); return bet;
  • 32. } } else/* no new card opened */ { if(players_data_move[teamno][stage][round_number[stage]-1]==RISE) { int bet = bluff(rise,2); return bet; } else { int choice = rand()%2 +1; if(choice == 1) return 0;/* call */ else return -10;/*fold*/ } } } } } else/* phand == 1 *//* p is vbad */ { int check = anyoppraisehigh(stage,round_number[stage],dealer + 1,teamno,dealer);/* check if opp raised high */ if(check == 1) { cout << "nYes Some player Rises"; //getch(); if(stage == 1) { int choice = rand() % 4 + 1; if ((choice==1)||(choice==2)||(choice==3)) return 0;/*call*/ else return -10;/*fold */ } else if(stage == 2) { int choice = rand()%4 +1; cout<<"nchoice "<<choice<<"n"; //getch(); if(choice == 2) return 0;/* call */ else return -10;/* fold */
  • 33. } else if(stage == 3) { int choice = rand() % 5 +1; if((choice == 1)||(choice == 2)||(choice == 3)||(choice == 4)) return -10;/* fold */ else return 0;/* call */ } else/* stage == 4 */ return -10;/* fold */ } else/*opponent raised low or called */ { cout << "n Opponent Raised Low"; if(round_number[stage]==1)/* new card opened */ { if(stage == 4) { int choice = rand()%2 +1; if(choice == 1) { /* bluff fnctn */ int bet = bluff(rise,2); return bet; } else return -10;/* fold */ } else { int choice = rand() % 2 + 1; if (choice == 1) { /*bluff fnctn */ int bet = bluff(rise,2); return bet; } else return 0;/* call */ } } else/* no new cards opened */ { if(players_data_move[teamno][stage][round_number[stage]-1] == RISE)/*previous bluff*/ { int bet = bluff(rise,2); return bet; } else
  • 34. { int choice = rand() % 2 + 1; if(choice == 1) return 0;/*call*/ else return -10;/*fold*/ } } } } } /*--------------------------- checked till here ----------------------*/ else/* first turn is ours */ { if(phand == 5)/* p hand is very gud */ { if(stage == 1) { int choice = rand() % 4 +1; if((choice == 1)||(choice == 2)) return 0;/* call */ else { /* high raise */ int bet = bluff(rise,4); return bet; } } else if((stage == 2)||(stage == 3)) { int choice = rand() % 3 + 1; if(choice == 1) { /* raise fnctn */ int bet = bluff(rise,4); return bet; } else return 0;/* call */ } else/* stage 4 */ { int choice = rand() % 2 + 1; if(choice == 1) return 0;/* call */ else { /* bluff fnctn */
  • 35. int bet = bluff(rise,2); return bet; } } } else if(phand == 4) { if(stage == 1) { int players = 6 - number_of_folds;/* no of players playing at the table atm */ if(players <= 3) { int zz=dealer+1; int ppos=0; int still_in_play[3]={0}; do { if(zz==7) zz=1; if(players_folded[zz] == false) still_in_play[ppos++]=zz; zz++; }while(zz != dealer && !(zz==7 && dealer==1)); if(ppos==2) {still_in_play[ppos++]=0;} return getMove(stage,phand,still_in_play,teamno,dealer); /* check pattern */ } else/* players > 3 */ { int choice = rand() % 4 + 1; if((choice == 1)||(choice == 2)) return 0;/* call */ else if(choice == 3) { /* bluff fnctn */ int bet = bluff(rise,4); return bet; } else { /* raise fnctn */ int bet = lowraise(rise); return bet; } } } else if((stage == 3)||(stage == 2)) {
  • 36. int players = 6 - number_of_folds;/* no of players playing the current bet */ if(players <= 3) { int zz=dealer+1; int ppos=0; int still_in_play[3]={0}; do { if(zz==7) zz=1; if(players_folded[zz] == false) still_in_play[ppos++]=zz; zz++; }while(zz != dealer && !(zz==7 && dealer==1)); if(ppos==2) {still_in_play[ppos++]=0;} return getMove(stage,phand,still_in_play,teamno,dealer); /* check pattern */ } else/* players > 3 */ { int choice = rand() % 3 + 1; if(choice == 1) { /* bluff fnctn */ int bet = bluff(rise,2); return bet; } else return 0;/* call */ } } else/* stage == 4 */ { int players = 6 - number_of_folds;/* no of players playing the deal */ if(players <=3) { int zz=dealer+1; int ppos=0; int still_in_play[3]={0}; do { if(zz==7) zz=1; if(players_folded[zz] == false) still_in_play[ppos++]=zz; zz++; }while(zz != dealer && !(zz==7 && dealer==1));
  • 37. if(ppos==2) {still_in_play[ppos++]=0;} return getMove(stage,phand,still_in_play,teamno,dealer); /*check pattern */ } else/* players > 3 */ { int choice = rand() % 3 + 1; if (choice == 1) { /* bluff fnctn */ int bet = bluff(rise,2); return bet; } else return 0;/* call */ } } } else if(phand = 3)/* phand == avg */ { if(stage == 1) { int players = 6 - number_of_folds;/* no of players playing the current deal */ if(players <= 3) { int zz=dealer+1; int ppos=0; int still_in_play[3]={0}; do { if(zz==7) zz=1; if(players_folded[zz] == false) still_in_play[ppos++]=zz; zz++; }while(zz != dealer && !(zz==7 && dealer==1)); if(ppos==2) {still_in_play[ppos++]=0;} return getMove(stage,phand,still_in_play,teamno,dealer); /* check pattern */ } else/* players > 3 */ { int choice = rand() %3 + 1; if(choice == 1) { /* bluff fnctn */
  • 38. int bet = bluff(rise,2); return bet; } else return 0;/* call */ } } else if((stage == 2)||(stage == 3)) { int players = 6 - number_of_folds;/* no of players playing the current deal */ if(players <= 3) { int zz=dealer+1; int ppos=0; int still_in_play[3]={0}; do { if(zz==7) zz=1; if(players_folded[zz] == false) still_in_play[ppos++]=zz; zz++; }while(zz != dealer && !(zz==7 && dealer==1)); if(ppos==2) {still_in_play[ppos++]=0;} return getMove(stage,phand,still_in_play,teamno,dealer); /* check pattern */ } else/* players > 3 */ { int choice = rand() %3 + 1; if(choice == 1) { /*bluff fnctn */ int bet = bluff(rise,2); return bet; } else return 0; } } else/* stage = 4 */ { if(players_data_move[teamno][stage][round_number[stage]-1] == RISE) { int zz=dealer+1; int ppos=0; int still_in_play[3]={0};
  • 39. do { if(zz==7) zz=1; if(players_folded[zz] == false) still_in_play[ppos++]=zz; zz++; }while(zz != dealer && !(zz==7 && dealer==1)); if(ppos==2) {still_in_play[ppos++]=0;} return getMove(stage,phand,still_in_play,teamno,dealer); /* check pattern */ /* can call or bluff */ /* never fold here */ } else/* previous wasn;t a bluff*/ { int players = 6 - number_of_folds;/* no of players playing the current deal */ if(players <= 3) { int zz=dealer+1; int ppos=0; int still_in_play[3]={0}; do { if(zz==7) zz=1; if(players_folded[zz] == false) still_in_play[ppos++]=zz; zz++; }while(zz != dealer && !(zz==7 && dealer==1)); if(ppos==2) {still_in_play[ppos++]=0;} return getMove(stage,phand,still_in_play,teamno,dealer); /* check pattern */ } else/* players > 3 */ { int choice = rand() %3 + 1; if(choice == 1) { /*bluff fnctn */ int bet = bluff(rise,2); return bet; } else
  • 40. return 0;/*call*/ } } } } if(phand == 2)/* phand = bad */ { int players = 6 - number_of_folds;/* no of players playing the current deal */ if(stage == 1) { if(players <= 3) { int zz=dealer+1; int ppos=0; int still_in_play[3]={0}; do { if(zz==7) zz=1; if(players_folded[zz] == false) still_in_play[ppos++]=zz; zz++; }while(zz != dealer && !(zz==7 && dealer==1)); if(ppos==2) {still_in_play[ppos++]=0;} return getMove(stage,phand,still_in_play,teamno,dealer); /* check pattern */ } else { int choice = rand() % 2 + 1; if(choice == 1) return 0;/* call */ else { /* bluff fnctn */ int bet = bluff(rise,2); return bet; } } } else if((stage == 2)||(stage == 3)) { if (players <=3) { int zz=dealer+1; int ppos=0; int still_in_play[3]={0}; do {
  • 41. if(zz==7) zz=1; if(players_folded[zz] == false) still_in_play[ppos++]=zz; zz++; }while(zz != dealer && !(zz==7 && dealer==1)); if(ppos==2) {still_in_play[ppos++]=0;} return getMove(stage,phand,still_in_play,teamno,dealer); /*check pattern */ } else { int choice = rand() % 3 + 1; if(choice == 1) { /* bluff fnctn */ int bet = bluff(rise,2); return bet; } else return 0; /* call */ } } else/*stage = 4 */ { if (players <= 3) { int zz=dealer+1; int ppos=0; int still_in_play[3]={0}; do { if(zz==7) zz=1; if(players_folded[zz] == false) still_in_play[ppos++]=zz; zz++; }while(zz != dealer && !(zz==7 && dealer==1)); if(ppos==2) {still_in_play[ppos++]=0;} return getMove(stage,phand,still_in_play,teamno,dealer); /* check pattern */ } else { int choice = rand()%4 + 1; if(choice == 1) {
  • 42. /* bluff fnctn */ int bet = bluff(rise,2); return bet; } else return 0; } } } else/* phand = 1 and vbad */ { int pla = 6 - number_of_folds;/* no of players playing the current deal */ if(stage == 1) { if(pla <= 3) { int zz=dealer+1; int ppos=0; int still_in_play[3]={0}; do { if(zz==7) zz=1; if(players_folded[zz] == false) still_in_play[ppos++]=zz; zz++; }while(zz != dealer && !(zz==7 && dealer==1)); if(ppos==2) {still_in_play[ppos++]=0;} return getMove(stage,phand,still_in_play,teamno,dealer); /* check pattern */ } else { int choice = rand() % 3 + 1; if((choice == 1)||(choice == 2)) return 0;/* call */ else { /* bluff fnctn */ int bet = bluff(rise,2); return bet; } } } else if((stage == 2)||(stage == 3)) { if (pla <=3) { int zz=dealer+1;
  • 43. int ppos=0; int still_in_play[3]={0}; do { if(zz==7) zz=1; if(players_folded[zz] == false) still_in_play[ppos++]=zz; zz++; }while(zz != dealer && !(zz==7 && dealer==1)); if(ppos==2) {still_in_play[ppos++]=0;} return getMove(stage,phand,still_in_play,teamno,dealer); /*check pattern */ } else { int choice = rand() % 4 + 1; if(choice == 1) { /* bluff fnctn */ int bet = bluff(rise,2); return bet; } else return 0; /* call */ } } else/*stage = 4 */ { if (pla <= 3) { int zz=dealer+1; int ppos=0; int still_in_play[3]={0}; do { if(zz==7) zz=1; if(players_folded[zz] == false) still_in_play[ppos++]=zz; zz++; }while(zz != dealer && !(zz==7 && dealer==1)); if(ppos==2) {still_in_play[ppos++]=0;} return getMove(stage,phand,still_in_play,teamno,dealer); /* check pattern */ } else
  • 44. { int choice = rand()%5 + 1; if(choice == 1) { /* bluff fnctn */ int bet = bluff(rise,2); return bet; } else return 0; } } } } } int getMove(int stage,int phand,int *team,int teamno,int dealer) { int final; int rise; int *ptr,flag; int xx1res,xx2res; cout << "nTeam 1 = " << *team << " Team 2 = " << *(team +1) << " Team 3 = " << *(team+2) ; if(*team == 0 || *(team + 1)==0||*(team + 2)==0) { //cout << "nIs it HERE ? "; //getch(); flag = 0; for(int temp=1;temp <= 3 ;temp++) { ptr = team; if(*ptr == teamno) { continue; flag = 1; } else if(*ptr == 0) { continue; } else { if(flag == 0) { int pop = checkPattern_p(FIRST,players_data_move[*ptr][stage][round_number[stage]],stage,*ptr); if(phand == VERY_BAD||phand == BAD || phand == AVG) { int cal,rez,foiled; checkPattern_action(pop,RISE,stage,*ptr);
  • 45. /* RISE :: 3 */ /* FOLD :: 2 */ /* CALL :: 1 */ /* BLUFF :: 4 */ cal = reaction_ratio[1]; foiled = reaction_ratio[2]; rez = reaction_ratio[3]; if(foiled<=cal || foiled<=rez) return -10;/* fold */ else { rise = get_minimum_raise(stage,teamno,dealer); cout << "n Minimum Raise 1= " << rise; int bet = bluff(rise,2); cout << "n Final Return 1= " << bet; //getch(); return bet; } } else/* phand is very gud */ { int calfold,rezfold; checkPattern_action(pop,CALL,stage,temp); /* RISE :: 3 */ /* FOLD :: 2 */ /* CALL :: 1 */ /* BLUFF :: 4 */ calfold = reaction_ratio[2]; checkPattern_action(pop,RISE,stage,temp); /* RISE :: 3 */ /* FOLD :: 2 */ /* CALL :: 1 */ /* BLUFF :: 4 */ rezfold = reaction_ratio[2]; if(calfold < rezfold) return 0;/* call */ else { rise = get_minimum_raise(stage,teamno,dealer); cout << "n Minimum Raise2 = " << rise; int bet = bluff(rise,2); cout << "n Final Return 2= " << bet; //getch(); return bet;/*raise bluff */ } } } else/* flag == 1 */ {