Exemplo n.º 1
0
        private static bool FindBestTeam()
        {
            Random rand = new Random();


            MatchPlayer        p;
            int                iterations    = 0;
            int                delta         = 0;
            int                minDeltaCount = 0;
            List <MatchPlayer> rTemp;
            List <MatchPlayer> dTemp;

            for (int i = 0; i < m_match.players.Count; i++)
            {
                p = m_match.players[i];
                var team = rand.Next(0, 1);
                if (team == 0 && m_match.radiant.Count < 5)
                {
                    m_match.radiant.Add(p);
                    m_match.radMMR += p.mmr;
                }
                else
                {
                    m_match.dire.Add(p);
                    m_match.direMMR += p.mmr;
                }
            }
            delta = Math.Abs(m_match.radMMR - m_match.direMMR);


            while (true)
            {
                rTemp = m_match.radiant;
                dTemp = m_match.dire;

                var i = rand.Next(0, 4);
                var j = rand.Next(0, 4);

                m_match.radMMR  = m_match.radMMR - rTemp[i].mmr + dTemp[j].mmr;
                m_match.direMMR = m_match.radMMR - dTemp[j].mmr + rTemp[i].mmr;

                int temp = Math.Abs(m_match.radMMR - m_match.direMMR);

                Console.WriteLine($"Update: {m_match.radMMR} - {m_match.direMMR} | {temp}");
                m_match.radiant.ForEach((p) => { Console.Write($"{p.mmr} "); });
                m_match.dire.ForEach((p) => { Console.Write($"{p.mmr} "); });
                Console.WriteLine();

                if (temp < delta)
                {
                    delta = temp;
                    Console.WriteLine($"New Delta: {delta}");
                    MatchPlayer tr = rTemp[i];
                    MatchPlayer td = dTemp[j];
                    m_match.radiant[i] = td;
                    m_match.dire[j]    = tr;
                    minDeltaCount      = 0;
                }
                else
                {
                    m_match.radMMR  = m_match.radMMR + rTemp[i].mmr - dTemp[j].mmr;
                    m_match.direMMR = m_match.radMMR + dTemp[j].mmr - rTemp[i].mmr;
                    if (iterations > 24)
                    {
                        minDeltaCount++;
                    }
                }

                iterations++;

                if (iterations > 49)
                {
                    break;
                }
                else if (minDeltaCount > 5)
                {
                    break;
                }
            }
            Console.WriteLine($"Final: {m_match.radMMR} - {m_match.direMMR} | Diff: {delta} | Iters: {iterations}");
            return(true);
        }
Exemplo n.º 2
0
 public static bool Join(MatchPlayer p)
 {
     m_queue.Add(p);
     p.joinSlot = m_queue.Count;
     return(true);
 }