Example #1
0
        static void grabMapStats()
        {
            using (SqlConnection eloCon = new SqlConnection(conStr))
            {
                string     queryStr = "Select * FROM Maps";
                SqlCommand cmd      = new SqlCommand(queryStr, eloCon);

                eloCon.Open();
                using (SqlDataReader oReader = cmd.ExecuteReader())
                {
                    while (oReader.Read())
                    {
                        map tempMap = new map(Convert.ToString(oReader[1]), Convert.ToInt32(oReader[2]));
                        heldMaps.Add(tempMap);
                    }
                }
            }
        }
Example #2
0
        static void inputDataFromTextFile()
        {
            using (SqlConnection eloCon = new SqlConnection(conStr))
            {
                eloCon.Open();
                string     queryStr = "DELETE FROM MatchResults";
                SqlCommand cmd      = new SqlCommand(queryStr, eloCon);
                cmd.ExecuteNonQuery();
                eloCon.Close();
            }
            using (SqlConnection eloCon = new SqlConnection(conStr))
            {
                eloCon.Open();
                string     queryStr = "UPDATE PlayerStats SET PlayerElo = 1000";
                SqlCommand cmd      = new SqlCommand(queryStr, eloCon);
                cmd.ExecuteNonQuery();
                eloCon.Close();
            }
            using (SqlConnection eloCon = new SqlConnection(conStr))
            {
                eloCon.Open();
                string     queryStr = "DELETE FROM Player_Maps";
                SqlCommand cmd      = new SqlCommand(queryStr, eloCon);
                cmd.ExecuteNonQuery();
                eloCon.Close();
            }



            string[] prevMatchs = System.IO.File.ReadAllLines(@"K:\\Elo\\EloSystem\\EloSystem\\PrevMatches.txt");

            for (int t = 0; t < prevMatchs.Length; t++)
            {
                heldPlayerStats  = new List <playerStats>();
                matchResultsPrev = new List <matchResults>();
                playersInGame    = new playerStats[8];
                playersInGameL   = new List <playerStats>();
                grabPlayerStats();
                grabPreviousMatchStats();


                string[] subs = prevMatchs[t].Split(',');
                mapChoice     = heldMaps.Find(x => x.mapName.ToUpper() == subs[0].ToUpper());
                team1.player1 = heldPlayerStats.Find(x => x.playerName == subs[1]);
                playersInGameL.Add(team1.player1);
                team1.player2 = heldPlayerStats.Find(x => x.playerName == subs[2]);
                playersInGameL.Add(team1.player2);
                team1.player3 = heldPlayerStats.Find(x => x.playerName == subs[3]);
                playersInGameL.Add(team1.player3);
                team1.player4 = heldPlayerStats.Find(x => x.playerName == subs[4]);
                playersInGameL.Add(team1.player4);
                team2.player1 = heldPlayerStats.Find(x => x.playerName == subs[5]);
                playersInGameL.Add(team2.player1);
                team2.player2 = heldPlayerStats.Find(x => x.playerName == subs[6]);
                playersInGameL.Add(team2.player2);
                team2.player3 = heldPlayerStats.Find(x => x.playerName == subs[7]);
                playersInGameL.Add(team2.player3);
                team2.player4 = heldPlayerStats.Find(x => x.playerName == subs[8]);
                playersInGameL.Add(team2.player4);
                calcPlayerStats();
                team1Wins = Convert.ToDouble(subs[9]);
                team2Wins = Convert.ToDouble(subs[10]);
                draws     = Convert.ToInt32(Math.Abs(team1Wins - team2Wins));
                calculateAndApplyEloChanges();
                matchResults gameResults = new matchResults(mapChoice.mapName, team1.player1, team1.player2, team1.player3, team1.player4, team2.player1, team2.player2, team2.player3, team2.player4
                                                            , team1Wins, team2Wins, DateTime.Now);
                commitMatchResult(gameResults, false);
            }
        }
Example #3
0
        static void simulateGames(int numGames)
        {
            for (int i = 0; i < numGames; i++)
            {
                Random rand      = new Random();
                int    player1id = rand.Next(0, 25);
                int    player2id = 0;
                int    player3id = 0;
                int    player4id = 0;
                int    player5id = 0;
                int    player6id = 0;
                int    player7id = 0;
                int    player8id = 0;

                int[] bannedId = new int[8];
                bannedId[0] = player1id;
                bool idCheck = true;
                while (idCheck)
                {
                    player2id = rand.Next(0, 25);
                    int pos = Array.IndexOf(bannedId, player2id);

                    if (pos > -1)
                    {
                        continue;
                    }
                    bannedId[1] = player2id;
                    idCheck     = false;
                }
                idCheck = true;
                while (idCheck)
                {
                    player3id = rand.Next(0, 25);
                    int pos = Array.IndexOf(bannedId, player3id);

                    if (pos > -1)
                    {
                        continue;
                    }
                    bannedId[2] = player3id;
                    idCheck     = false;
                }
                idCheck = true;

                while (idCheck)
                {
                    player4id = rand.Next(0, 25);
                    int pos = Array.IndexOf(bannedId, player4id);

                    if (pos > -1)
                    {
                        continue;
                    }
                    bannedId[3] = player4id;
                    idCheck     = false;
                }
                idCheck = true;

                while (idCheck)
                {
                    player5id = rand.Next(0, 25);
                    int pos = Array.IndexOf(bannedId, player5id);

                    if (pos > -1)
                    {
                        continue;
                    }
                    bannedId[4] = player5id;
                    idCheck     = false;
                }
                idCheck = true;

                while (idCheck)
                {
                    player6id = rand.Next(0, 25);
                    int pos = Array.IndexOf(bannedId, player6id);

                    if (pos > -1)
                    {
                        continue;
                    }
                    bannedId[5] = player6id;
                    idCheck     = false;
                }
                idCheck = true;
                while (idCheck)
                {
                    player7id = rand.Next(0, 25);
                    int pos = Array.IndexOf(bannedId, player7id);

                    if (pos > -1)
                    {
                        continue;
                    }
                    bannedId[6] = player7id;
                    idCheck     = false;
                }
                idCheck = true;

                while (idCheck)
                {
                    player8id = rand.Next(0, 25);
                    int pos = Array.IndexOf(bannedId, player8id);

                    if (pos > -1)
                    {
                        continue;
                    }
                    bannedId[7] = player8id;
                    idCheck     = false;
                }

                team1.player1 = heldPlayerStats[player1id];
                team1.player2 = heldPlayerStats[player2id];
                team1.player3 = heldPlayerStats[player3id];
                team1.player4 = heldPlayerStats[player4id];
                team2.player1 = heldPlayerStats[player5id];
                team2.player2 = heldPlayerStats[player6id];
                team2.player3 = heldPlayerStats[player7id];
                team2.player4 = heldPlayerStats[player8id];


                mapChoice = heldMaps[rand.Next(0, 20)];

                team1Wins = rand.Next(0, mapChoice.maps);
                draws     = rand.Next(0, Convert.ToInt32(mapChoice.maps - team1Wins));
                team2Wins = mapChoice.maps - team1Wins - draws;

                calcPlayerStats();

                for (int t = 0; t < draws; t++)
                {
                    team1Wins = team1Wins + 0.5;
                    team2Wins = team2Wins + 0.5;
                }
                calculateAndApplyEloChanges();
                matchResults gameResults = new matchResults(mapChoice.mapName, team1.player1, team1.player2, team1.player3, team1.player4, team2.player1, team2.player2, team2.player3, team2.player4
                                                            , team1Wins, team2Wins, DateTime.Now);
                commitMatchResult(gameResults, true);

                team1Wins = 0;
                team2Wins = 0;
                draws     = 0;
            }
        }
Example #4
0
        static void Main(string[] args)
        {
            //Grabbing data from database
            grabPlayerStats();
            grabPreviousMatchStats();
            grabMapStats();

            Console.WriteLine("---------------------------- Welcome to the Elo zone ---------------------------- \n\n\nWould you like to generate random teams or enter a result? (T/R) ");
            string answer     = "";
            bool   correctAns = true;

            while (correctAns)
            {
                answer = Console.ReadLine();
                if (answer.ToUpper() == "R")
                {
                    grabTeams();

                    Console.WriteLine("Please enter the map played: ");
                    string mapChoiceS = "";
                    bool   nameCheck  = true;
                    while (nameCheck)
                    {
                        mapChoiceS = Console.ReadLine();
                        bool testBool = checkMap(mapChoiceS);
                        if (testBool)
                        {
                            nameCheck = false;
                        }
                        else
                        {
                            Console.WriteLine("No record with that name, please try again: ");
                        }
                    }
                    mapChoice = heldMaps.Find(x => x.mapName.ToUpper() == mapChoiceS.ToUpper());
                    if (mapChoice.maps != 0)
                    {
                        Console.WriteLine("Please enter the rounds won by Team 1 between 1 - " + Convert.ToString(mapChoice.maps) + ": ");
                        team1Wins = Convert.ToDouble(Console.ReadLine());
                    }
                    else
                    {
                        Console.WriteLine("Fatal error");
                        //Add other path that accounts for this big. Not important at all
                    }
                    Console.WriteLine("Please enter the rounds drawn, between 0 - " + Convert.ToString(mapChoice.maps - team1Wins) + ": ");
                    draws     = Convert.ToInt32(Console.ReadLine());
                    team2Wins = mapChoice.maps - team1Wins - draws;
                    team1Wins = team1Wins + draws / 2;
                    team2Wins = team2Wins + draws / 2;
                    calculateAndApplyEloChanges();
                    matchResults gameResults = new matchResults(mapChoice.mapName, team1.player1, team1.player2, team1.player3, team1.player4, team2.player1, team2.player2, team2.player3, team2.player4
                                                                , team1Wins, team2Wins, DateTime.Now);
                    commitMatchResult(gameResults, true);
                    correctAns = false;
                }
                else if (answer.ToUpper() == "T")
                {
                    grabPlayers();
                    makeTeams();
                    correctAns = false;
                }
                else if (answer.ToUpper() == "P")
                {
                    inputDataFromTextFile();
                }
                else
                {
                    Console.WriteLine("Please enter T or R");
                    correctAns = true;
                }
            }
        }