Exemplo n.º 1
0
        private static stateJson getCurrentState()
        {
            stateJson stateJson    = null;
            string    currentState = null;

            try
            {
                var request  = (HttpWebRequest)WebRequest.Create("http://www.saltybet.com/state.json");
                var response = (HttpWebResponse)request.GetResponse();
                using (var responseStream = response.GetResponseStream())
                {
                    if (responseStream != null)
                    {
                        var encoding     = Encoding.GetEncoding("utf-8");
                        var StreamReader = new StreamReader(responseStream, encoding);
                        currentState = StreamReader.ReadToEnd();
                    }
                    response.Close();
                    response.Dispose();
                    request.Abort();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                Console.WriteLine("cannot retrieve current state");
            }

            return(stateJson = JsonConvert.DeserializeObject <stateJson>(currentState));
        }
Exemplo n.º 2
0
        private static betMode setBetMode(stateJson currentState)
        {
            betMode mode = betMode.Exhibitions; //default to exhibitions, our most reserved betting mode

            if (currentState.remaining.Contains("until the next tournament") ||
                currentState.remaining.Contains("Matchmaking mode has been") ||
                currentState.remaining.Contains("Tournament mode will be"))
            {
                //matchmaking
                mode = betMode.Matchmaking;
            }

            else if (currentState.remaining.Contains("characters are left in the bracket") ||
                     currentState.remaining.Contains("Tournament mode start") ||
                     currentState.remaining.Contains("FINAL ROUND"))
            {
                //tournament
                mode = betMode.Tournament;
            }

            return(mode);
        }
Exemplo n.º 3
0
        private static void buildCurrentMatch(CookieContainer cookieContainer)
        {
            //happens when waifu says bets are open
            //add fight to db if it doesn't exist, then wait for win or loss message, update who won.
            //if fight does exist, offer advice on who to bet on, wait for win/loss, update who won.
gameCrash:
            int balance = getBalance(cookieContainer);

            mySqlCon.ConnectionString = mySqlConnectString;
            stateJson      currentState    = getCurrentState();
            matchstatsJson currentMatch    = getCurrentMatchStats(makeCookieContainer());
            List <fighter> currentFighters = buildFighters(currentMatch);
            string         RedTeam         = currentState.p1name;
            string         BlueTeam        = currentState.p2name;
            int            countFighters   = currentFighters.Count;
            double         redChanceToWin  = 0;

            mySqlCon.Open();

            try
            {
                //figure out how to bet by getting bet mode
                currentMode = setBetMode(currentState);
                setBetModifier(currentMode);
            }
            catch (Exception e)
            {
                Console.WriteLine("Cannot set bet modifier");
                Console.WriteLine(e);
            }

            match newMatch = new match(currentFighters);

            redChanceToWin = newMatch.getRedChanceToWin(mySqlCon);
            Console.WriteLine("red chance to win: " + redChanceToWin);


            try
            {
                bool fighting = true;
                Console.WriteLine("Current Salt: " + balance);
                Console.WriteLine("Salt gained/lost on last bet: " + (balance - oldBalance));
                makeBet(cookieContainer, currentFighters, balance, redChanceToWin, currentMode);
                Console.WriteLine("Waiting for winner");
                while (fighting)
                {
                    string message = irc.readMessage();
                    if (message.Contains(waifu))
                    {
                        if (message.Contains(RedTeam) && message.Contains("wins"))
                        {
                            Console.WriteLine(message);
                            updateELOs(newMatch, redChanceToWin, true);
                            isRedTeam = true;
                            recordWL(redChanceToWin);
                            Console.WriteLine("Red wins!");
                            Console.WriteLine("W/L: " + wins + "/" + losses);
                            mySqlCon.Close();
                            fighting = false;
                        }
                        else if (message.Contains(BlueTeam) && message.Contains("wins"))
                        {
                            Console.WriteLine(message);
                            updateELOs(newMatch, redChanceToWin, false);
                            isRedTeam = false;
                            recordWL(redChanceToWin);
                            Console.WriteLine("Blue wins!");
                            Console.WriteLine("W/L: " + wins + "/" + losses);
                            mySqlCon.Close();
                            fighting = false;
                        }
                        else if (message.Contains("Bets are OPEN"))
                        {
                            Console.WriteLine(message);
                            Console.WriteLine("We missed the winner message or the game possibly crashed, start over");
                            fighting = false;
                            mySqlCon.Close();
                            goto gameCrash;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                mySqlCon.Close();
                //Console.WriteLine("Could not Connect to DB");
            }
        }