Exemple #1
0
        public heroAttribute()
        {
            heroID hero_id = new heroID();
            Dictionary <int, string> hero_id_name = hero_id.getHeroID();
            string s = Path.Combine(Environment.CurrentDirectory, "Properties/dota_hero_info_1.txt");

            string[] lines        = System.IO.File.ReadAllLines(s);
            string[] second_lines = lines;
            int      key          = 0;

            foreach (string line in lines)
            {
                key++;
                string   second_string = string.Empty;
                string[] words         = line.Split('\t');
                hero_attribute[key, 0] = key;
                if (words[1] == "Strength")
                {
                    hero_attribute[key, 1] = 0;
                }
                else if (words[1] == "Agility")
                {
                    hero_attribute[key, 1] = 1;
                }
                else if (words[1] == "Intelligence")
                {
                    hero_attribute[key, 1] = 2;
                }
                for (int i = 2; i < words.Length; i++)
                {
                    double.TryParse(words[i], out hero_attribute[key, i]);
                }
            }
        }
        /*
         *
         */
        public heroGenerateTypes()
        {
            string s = Path.Combine(Environment.CurrentDirectory, "Properties/herotype.txt");

            string[] lines        = System.IO.File.ReadAllLines(s);
            string[] second_lines = lines;
            int      index        = 0;
            heroID   h_ID         = new heroID();

            string[] heroesName = h_ID.getHeroName();
            Dictionary <int, string> ID_table   = h_ID.getHeroID(); // key is ID, value is hero_name;
            Dictionary <string, int> hero_table = h_ID.getIDHero(); // key is hero_name, value is ID;

            foreach (string line in lines)
            {
                if (line.Contains("["))
                {
                    string[] words     = line.Split('\t', '"', '\\');
                    string   role_name = words[0].Replace("[", "");
                    role_name = role_name.Replace("]", "");
                    string explain = words[1].Replace("\"", "");
                    type_explain[role_name] = explain;
                    index = type_explain.Count - 1;
                }
                else
                {
                    string   second_string = string.Empty;
                    string[] words         = line.Split('*');
                    for (int i = 0; i < words.Length; i++)
                    {
                        var r = new Regex(@"(?<=[A-Z])(?=[A-Z][a-z]) | (?<=[^A-Z])(?=[A-Z]) | (?<=[A-Za-z])(?=[^A-Za-z])",
                                          RegexOptions.IgnorePatternWhitespace);

                        string   curName  = r.Replace(words[i], " ");
                        string[] nameList = curName.Split(' ');
                        curName = "";
                        for (int j = nameList.Length - 1; j >= 0; j--)
                        {
                            if (curName.Length > 0)
                            {
                                if (nameList[j].Length > 0)
                                {
                                    curName = nameList[j] + " " + curName;
                                }
                            }
                            else
                            {
                                curName = nameList[j];
                            }

                            if (hero_table.ContainsKey(curName))
                            {
                                hero_generate_type_table[hero_table[curName], index] = 1;
                                break;
                            }
                        }
                    }
                }
            }
        }
        public int item_suggestion_for_live(List <string> items, string myHero)
        {
            Dictionary <int, int> item_ID = new Dictionary <int, int>();
            heroID hid = new heroID();
            Dictionary <int, string> ID_table   = hid.getHeroID();                  // key is ID, value is hero_name;
            Dictionary <string, int> hero_table = hid.getIDfromLowercaseHeroname(); // key is hero_name, value is ID;
            int        hero_cur_id = hero_table[myHero];
            List <int> itemsID     = new List <int>();
            string     item_name   = "";
            string     item_lower  = "";

            foreach (string s in items)
            {
                item_name = s.Replace("item", "");
                item_name = item_name.Replace("_", "");
                if (item_name.Contains("travel"))
                {
                    item_name = "bootsoftravel";
                }
                else if (item_name.Contains("cyclone"))
                {
                    item_name = "eul";
                }
                for (int i = 3; i < 156; i++)
                {
                    item_lower = item_table_info[i, 2].ToLower();
                    item_lower = item_lower.Replace(" ", "");
                    if (item_lower.Contains(item_name))
                    {
                        itemsID.Add(i - 2);
                    }
                }
            }

            for (int i = 0; i < 3; i++)
            {
                if (!itemsID.Contains(item_KB[hero_cur_id, i]))
                {
                    return(item_KB[hero_cur_id, i]);
                }
            }
            return(121);
        }
Exemple #4
0
        public ReplayHighlights(string dataFolderLocation, string myHero)
        {
            heroID hid = new heroID();
            Dictionary <int, string> ID_table   = hid.getHeroID();                  // key is ID, value is hero_name;
            Dictionary <string, int> hero_table = hid.getIDfromLowercaseHeroname(); // key is hero_name, value is ID;

            string timePath   = dataFolderLocation + "time.txt";
            string combatPath = dataFolderLocation + "combat.txt";

            List <String> timeLines = new List <String>(System.IO.File.ReadAllLines(timePath));

            Int32.TryParse(timeLines.First().Split(' ')[2], out this.firstTick);
            float.TryParse(timeLines.Last().Split(' ')[2], out this.lastTick);

            List <String>         combatLines = new List <String>(System.IO.File.ReadAllLines(combatPath));
            List <List <String> > killLines   = GetTeamfight(combatLines);

            this.tickInfo = new Dictionary <int, Tuple <String, List <Tuple <String, String, String> > > >();
            listInfo      = new Dictionary <int, List <Tuple <string, string, string> > >();

            foreach (var kills in killLines)
            {
                listInfo[(int)Double.Parse(kills[0])] = new List <Tuple <string, string, string> >();
                for (int i = 1; i < kills.Count; i++)
                {
                    string[] cont   = kills[i].Split(new char[] { ' ' });
                    string   killed = ID_table[hero_table[ConvertedHeroName.Get(cont[0])]];
                    string   killer = ID_table[hero_table[ConvertedHeroName.Get(cont[1])]];

                    string color = "we";
                    if (killed == myHero)
                    {
                        color = "R";
                    }
                    else if (killer == myHero)
                    {
                        color = "G";
                    }
                    listInfo[(int)Double.Parse(kills[0])].Add(new Tuple <string, string, string>(killer, killed, color));
                }
            }
        }
        public counterpick_info()
        {
            heroID h_ID = new heroID();
            Dictionary <int, string> ID_table   = h_ID.getHeroID(); // key is ID, value is hero_name;
            Dictionary <string, int> hero_table = h_ID.getIDHero(); // key is hero_name, value is ID;
            string s     = Path.Combine(Environment.CurrentDirectory, "Properties/c");
            string s_end = ".txt";
            int    i     = 1;
            string path  = "";

            while (i < 116)
            {
                path = s + i + s_end;
                string[] lines        = System.IO.File.ReadAllLines(path);
                string[] second_lines = lines;
                int      counter      = 0;
                foreach (string line in lines)
                {
                    if (counter == 0)
                    {
                        string[] words       = line.Split('\t');
                        int      length_this = words.Length;
                        string   name        = "";
                        int      count_in    = 0;
                        while (length_this > 1)
                        {
                            name = words[count_in];
                            count_in++;
                            length_this--;
                        }
                        string temp   = words[count_in].Replace('%', ' ');
                        double d_temp = Convert.ToDouble(temp);
                        int    index  = -1;
                        hero_table.TryGetValue(name, out index);
                        if (index != -1)
                        {
                            counter_info_table[i, index] = d_temp;
                        }
                        if (index == 0)
                        {
                            //Console.WriteLine(name);
                        }
                        counter++;
                    }
                    else
                    {
                        counter = 0;
                    }
                }
                i++;
            }

            string path1 = Path.Combine(Environment.CurrentDirectory, "Properties/countertable.txt");

            if (!File.Exists(path1))
            {
                // Create a file to write to.
                using (StreamWriter sw = File.CreateText(path1))
                {
                    int row_number = 0;
                    while (row_number < 116)
                    {
                        double[] nthRow = GetRow(counter_info_table, row_number);
                        sw.WriteLine(convertString(nthRow));
                        row_number++;
                    }
                }
            }
        }
        public Dictionary <int, int> item_suggestion(int money, string dataFolderLocation, string myHero)
        {
            Dictionary <int, int> item_ID = new Dictionary <int, int>();
            heroID hid = new heroID();
            Dictionary <int, string> ID_table   = hid.getHeroID();                  // key is ID, value is hero_name;
            Dictionary <string, int> hero_table = hid.getIDfromLowercaseHeroname(); // key is hero_name, value is ID;
            int    firstTick;
            int    lastTick;
            string timePath   = dataFolderLocation + "time.txt";
            string combatPath = dataFolderLocation + "combat.txt";

            List <String> timeLines = new List <String>(System.IO.File.ReadAllLines(timePath));

            Int32.TryParse(timeLines.First().Split(' ')[0], out firstTick);
            Int32.TryParse(timeLines.Last().Split(' ')[0], out lastTick);
            List <String>         combatLines = new List <String>(System.IO.File.ReadAllLines(combatPath));
            List <List <String> > teamfight   = new List <List <string> >();
            Dictionary <int, List <Tuple <String, String, String> > > tickInfo = new Dictionary <int, List <Tuple <string, string, string> > >();
            int      currInd     = 0;
            TimeSpan prevTime    = new TimeSpan();
            TimeSpan thirty      = TimeSpan.FromSeconds(30);
            string   heroPattern = "hero.*hero";

            foreach (var line in combatLines)
            {
                if (line.Contains("[KILL]"))
                {
                    if (Regex.IsMatch(line, heroPattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase))
                    {
                        if (teamfight.Count < currInd + 1)
                        {
                            teamfight.Add(new List <String>());
                        }

                        List <String> contents = new List <String>(line.Split(new char[] { ' ' }));
                        if (prevTime == new TimeSpan())
                        {
                            prevTime = TimeSpan.FromSeconds(Double.Parse(contents[0]));
                        }

                        TimeSpan currTime = TimeSpan.FromSeconds(Double.Parse(contents[0]));

                        if (prevTime == currTime)
                        {
                            teamfight[currInd].Add(contents[0]);
                            teamfight[currInd].Add(contents[2] + " " + contents[3]);
                        }
                        else if (prevTime.Add(thirty) > currTime)
                        {
                            teamfight[currInd].Add(contents[2] + " " + contents[3]);
                        }
                        else
                        {
                            currInd++;
                            teamfight.Add(new List <String>());
                            prevTime = currTime;
                            teamfight[currInd].Add(contents[0]);
                            teamfight[currInd].Add(contents[2] + " " + contents[3]);
                        }
                    }
                }
            }
            int oneThird = (2 * firstTick + lastTick) / 8;
            int twoThird = (firstTick + 2 * lastTick) / 3;

            foreach (var kills in teamfight)
            {
                tickInfo[(int)Double.Parse(kills[0])] = new List <Tuple <string, string, string> >();
                for (int i = 1; i < kills.Count; i++)
                {
                    string[] cont   = kills[i].Split(new char[] { ' ' });
                    string   killed = ID_table[hero_table[ConvertedHeroName.Get(cont[0])]];
                    string   killer = ID_table[hero_table[ConvertedHeroName.Get(cont[1])]];
                    if (killed == myHero)
                    {
                        int itemInfo;
                        int killedID = hero_table[ConvertedHeroName.Get(killed)];
                        int curtick  = (int)(Double.Parse(kills[0]));
                        if (curtick <= oneThird)
                        {
                            itemInfo = item_KB[killedID, 1];
                        }
                        else if (twoThird > curtick && curtick > oneThird)
                        {
                            itemInfo = item_KB[killedID, 1];
                        }
                        else
                        {
                            itemInfo = item_KB[killedID, 2];
                        }
                        item_ID.Add((int)(Double.Parse(kills[0])), itemInfo);
                    }
                }
            }
            return(item_ID);
        }
Exemple #7
0
        /*
         * build up the hero_ID_Client_Team Team
         */
        public void readTeam()
        {
            //count the hero name
            int count = 0;
            //count the hero team
            //int count1 = 0;
            string s = dataFolderLocation + "info.txt";

            string[]                 lines          = System.IO.File.ReadAllLines(s);
            heroIDClient             ID_client      = new heroIDClient();
            Dictionary <string, int> clientID_Dic   = ID_client.getIDHero();
            Dictionary <int, string> clientHero_Dic = ID_client.getHeroID();

            heroID ID_hero = new heroID();
            Dictionary <string, int> ID_Dic   = ID_hero.getIDHero();
            Dictionary <int, string> Hero_Dic = ID_hero.getHeroID();
            var caseInsensitiveDictionary     = new Dictionary <string, int>(
                StringComparer.OrdinalIgnoreCase);

            foreach (string key in clientID_Dic.Keys)
            {
                int value1 = 0;
                clientID_Dic.TryGetValue(key, out value1);
                if (value1 > 0)
                {
                    caseInsensitiveDictionary.Add(key, value1);
                }
            }
            int mode = 0;
            int ban  = 0;

            foreach (string line in lines)
            {
                if (mode == 1)
                {
                    if (ban == 1)
                    {
                        if (line.Contains("team"))
                        {
                            mode = 2;
                            string[] words       = line.Split(' ');
                            int      team_number = -1;
                            if (int.TryParse(words[words.Length - 1], out team_number))
                            {
                                if (team_number == 2)
                                {
                                    hero_ID_Client_Team[count, 2] = 0;
                                }
                                else
                                {
                                    hero_ID_Client_Team[count, 2] = 1;
                                }
                            }
                        }
                    }
                    else
                    {
                        if (line.Contains("team"))
                        {
                            mode = 2;
                            string[] words       = line.Split(' ');
                            int      team_number = -1;
                            if (int.TryParse(words[words.Length - 1], out team_number))
                            {
                                if (team_number == 2)
                                {
                                    hero_ID_Client_Team[count, 2] = 2;
                                }
                                else
                                {
                                    hero_ID_Client_Team[count, 2] = 3;
                                }
                            }
                        }
                    }
                }
                else if (line.Contains("is_pick:"))
                {
                    mode = 1;
                    string[] words = line.Split(' ');
                    if (words[words.Length - 1].Contains("false"))
                    {
                        ban = 1;
                    }
                }
                else if (mode == 2)
                {
                    if (line.Contains("hero_id:"))
                    {
                        mode = 0;
                        string[] words       = line.Split(' ');
                        int      hero_number = -1;
                        if (int.TryParse(words[words.Length - 1], out hero_number))
                        {
                            hero_ID_Client_Team[count, 1] = hero_number;
                            string hero_name   = clientHero_Dic[hero_number];
                            int    hero_id_cur = ID_Dic[hero_name];
                            hero_ID_Client_Team[count, 0] = hero_id_cur;
                            count++;
                            ban = 0;
                        }
                    }
                }
            }

            s = dataFolderLocation + "selection.txt";

            lines = System.IO.File.ReadAllLines(s);
            foreach (string line in lines)
            {
                string[] words = line.Split(' ');
                int      tic   = Int32.Parse(words[0]);
                //int team = 0;
                int heroID = 0;
                heroID = Int32.Parse(words[2]);
                string hero_name = "";
                clientHero_Dic.TryGetValue(heroID, out hero_name);
                int cur_ID = 0;
                ID_Dic.TryGetValue(hero_name, out cur_ID);
                for (int i = 0; i < count; i++)
                {
                    if (hero_ID_Client_Team[i, 0] == cur_ID)
                    {
                        hero_ID_Client_Team[i, 3] = tic;
                    }
                }
            }
        }