Ejemplo n.º 1
0
        public void Populate(List <Team> teams)
        {
            //Check if there are enough teams for the bracket
            List <Team> teamsTemp = new List <Team>();

            foreach (Team t in teams)
            {
                teamsTemp.Add(t);
            }


            while (teamsTemp.Count < BracketRequiredTeams)
            {
                //Add random Teams
                if (teams[0] is Team2s)
                {
                    Team2s t = new Team2s();
                    t.ID      = -1;
                    t.IsDummy = true;
                    teamsTemp.Add(t);
                }
                else if (teams[0] is Team1s)
                {
                    Team1s t = new Team1s();
                    t.ID      = -1;
                    t.IsDummy = true;
                    teamsTemp.Add(t);
                }
                else if (teams[0] is Team3s)
                {
                    Team3s t = new Team3s();
                    t.ID      = -1;
                    t.IsDummy = true;
                    teamsTemp.Add(t);
                }
                else
                {
                    Console.WriteLine("Not Supported");
                }
            }

            Round       first_round  = Rounds[0];
            Random      rnd          = new Random();
            List <Team> randTeamList = teamsTemp.Select(x => new { value = x, order = rnd.Next() })
                                       .OrderBy(x => x.order).Select(x => x.value).ToList();

            int team_index = 0;

            foreach (Matchup match in first_round.Matchups)
            {
                match.Team1 = randTeamList[team_index];
                match.Team2 = randTeamList[team_index + 1];
                team_index += 2;
            }

            FindEarlyWinners();
        }
        public bool CreateTeams2s()
        {
            //By default we're generating teams for 2s

            List <Player> tempPlayers = new List <Player>();

            foreach (Player p in _players)
            {
                tempPlayers.Add(p);
            }
            tempPlayers.Sort((a, b) => a.Rank._rank.CompareTo(b.Rank._rank));

            _teams.Clear();

            if (tempPlayers.Count % 2 > 0)
            {
                //MessageBox.Show("ZIMA BALE ALLON ENAN XUMA PAIXTH KAI KSANAPATA");
                return(false);
            }


            while (tempPlayers.Count > 0)
            {
                Team2s t = new Team2s();
                t.ID      = _teams.Count;
                t.Player1 = tempPlayers.First();
                t.Player2 = tempPlayers.Last();
                t.Captain = t.Player2; //Always set captain to player 2

                //Remove the entires
                tempPlayers.RemoveAt(0);
                tempPlayers.RemoveAt(tempPlayers.Count - 1);

                _teams.Add(t);
            }

            return(true);
        }