Exemple #1
0
        }                                      //allows action counter to be persisted

        public GameParser(string line_in, Games g, string streetname, int gameActionCtr, string url, string key, string archivepath, List <Bets> bets)
        {
            //find index of button
            int buttonindex = g.seats.FindIndex(a => a.seatno == g.buttonseat);

            if (line_in.IndexOf(" posts small blind ") > 1)
            {
                for (var i = 0; i < g.seats.Count; i++)
                {
                    int buttonoffset = i <= buttonindex ? buttonindex - i : g.seats.Count() - (i - buttonindex);
                    //Console.WriteLine("Name is {0} and seatindex is {1} and button index is {2} and playercount is {3} and button offset is {4}", g.seats[i].playername, i, buttonindex, g.seats.Count(), buttonoffset);

                    if (buttonoffset <= 1)
                    {
                        //Console.WriteLine("Postion is Late");
                        //todo: assign postion flag
                    }
                    else if (buttonoffset >= (g.seats.Count() - 2))
                    {
                        //Console.WriteLine("Position is Early");
                        //todo: assign postion flag
                    }
                    else
                    {
                        //Console.WriteLine("Position is Middle");
                        //todo: assign postion flag
                    }
                }
            }

            LineParser lp = new LineParser(line_in, streetname, gameActionCtr);

            if (streetname != lp.Streetname)
            {
                bets.Select(u => { u.betsum = 0; return(u); }).ToList();
            }
            Streetname = lp.Streetname;
            int actionFlag = GameActionCtr == lp.GameActionCtr ? 0 : 1;

            GameActionCtr = lp.GameActionCtr;
            Bets b = new Bets();

            if (lp.NewGame == 1)  //start of new game. print Games object from previous game
            {
                //AT THIS POINT ALL GAME DETAILS FROM PREVIOUS GAME ARE IN g
                if (g.gameid != null)
                {
                    ////CosmosDb cosmosDb = new CosmosDb(url, key, g);
                    ////cosmosDb.GetStartedDemo(url, key, g).Wait();
                    ///


                    //using (StreamWriter sw2 = new StreamWriter(archivepath + "JSON\\" + g.gameid + ".json"))
                    //{
                    //    sw2.WriteLine(g);
                    //}

                    //StreamData streamData = new StreamData();
                    ////// cosmosDb.GetStartedDemo(url, key, g).Wait();
                    ////streamData.MainAsync(ga_Payload).Wait();
                    //streamData.MainAsync(g).Wait();

                    WriteOutput writeOutput = new WriteOutput(g, archivepath);

                    //Console.WriteLine(g.ToString());  //WRITE ENTIRE JSON OBJECT AS STRING

                    //MemoryStream ms = new MemoryStream();
                    //DataContractJsonSerializer j = new DataContractJsonSerializer(typeof(Games));
                    //j.WriteObject(ms, g);

                    //ms.Position = 0;
                    //StreamReader str = new StreamReader(ms);
                    //Console.Write("JSON form of Games object: ");
                    //Console.WriteLine(str.ReadToEnd());
                }

                //clear action level vars
                g.actions.Clear();
                g.seats.Clear();
                bets.Clear();

                Streetname    = "Pre-flop";
                GameActionCtr = 0;

                //assign game level vars
                g.gameid    = lp.GameId;
                g.timestamp = lp.TimeStamp;
                g.limits    = lp.Limits;
                g.sitename  = lp.SiteName;

                //TODO: REMOVE AFTER MOVING TO SAME SPOT AS JSON
                //prep output file
                //using (StreamWriter sw3 = new StreamWriter(archivepath + "Text\\" + g.gameid + ".txt"))
                //{
                //    sw3.WriteLine("GameId" + "|" + "Timestamp" + "|" + "SiteName" + "|" + "TableName" + "|" + "Limits" + "|" + "StreetName" + "|" + "GameActionId" + "|" + "Action" + "|" + "Player" + "|" + "Amount");//);

                //}

                ////delete file if it already exists for this game
                //using (StreamWriter sw = new StreamWriter(archivepath + "Verbose\\" + g.gameid + ".txt"))
                //{
                //    sw.WriteLine(line_in);
                //}
            }
            else if (lp.TableName != null)
            {
                g.tablename  = lp.TableName;
                g.buttonseat = lp.ButtonSeat;
            }
            else if (lp.Streetname != "" && lp.Action != null)  //assign Actions values
            {
                if (lp.Action == "SeatInfo")
                {
                    g.Addseats(new Seats {
                        playername = lp.Player, seatno = lp.Seatnumber
                    });
                    b.playername = lp.Player;
                    b.betsum     = 0;
                    bets.Add(b);
                }
                else
                {
                    if (actionFlag == 1)
                    {
                        //write action to output file
                        using (StreamWriter sw3 = new StreamWriter(archivepath + "Text\\" + g.gameid + ".txt", true))
                        {
                            if (lp.Action == "bet" || lp.Action == "blind" || lp.Action == "call" || lp.Action == "raise")
                            {
                                if (lp.Action == "raise")
                                {
                                    decimal raiseamt = lp.Amount - bets.Where(p => p.playername == lp.Player).First().betsum;
                                    bets.Where(p => p.playername == lp.Player).Select(u => { u.betsum = (u.betsum + raiseamt); return(u); }).ToList();
                                    lp.Amount = raiseamt;
                                }
                                else
                                {
                                    bets.Where(p => p.playername == lp.Player).Select(u => { u.betsum = (u.betsum + lp.Amount); return(u); }).ToList();
                                }
                            }

                            //TODO: REPLACE WITH CODE TO DESERIALIZE g (WITH JSON OUTPUT ABOVE)
                            //{
                            //    sw3.WriteLine(g.gameid.ToString() + "|" + g.timestamp.ToString() + "|" + g.sitename + "|" + g.tablename + "|" + g.limits + "|" + lp.Streetname + "|" + lp.GameActionCtr.ToString() + "|" + lp.Action + "|" + lp.Player + "|" + lp.Amount.ToString());//);

                            //    //Added to pass to Azure Event Hub
                            //    ga_payload ga_Payload = new ga_payload();

                            //    ga_Payload.gameid = g.gameid.ToString();
                            //    ga_Payload.timestamp = g.timestamp.ToString();
                            //    ga_Payload.sitename = g.sitename;
                            //    ga_Payload.tablename = g.tablename;
                            //    ga_Payload.limits = g.limits;
                            //    ga_Payload.streetname = lp.Streetname;
                            //    ga_Payload.gameactionid = lp.GameActionCtr;
                            //    ga_Payload.action = lp.Action;
                            //    ga_Payload.player = lp.Player;
                            //    ga_Payload.amount = lp.Amount;

                            //    //StreamData streamData = new StreamData();
                            //    ////// cosmosDb.GetStartedDemo(url, key, g).Wait();
                            //    ////streamData.MainAsync(ga_Payload).Wait();
                            //    //streamData.MainAsync(g).Wait();
                            //}
                        }
                    }

                    g.Addactions(new Actions {
                        GameActionId = lp.GameActionCtr, actor = lp.Player, action = lp.Action, amount = lp.Amount, streetname = lp.Streetname
                    });
                }
            }

            //Console.WriteLine(line_in);  NO NEED TO Write every line
        }