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 void getTournamentTeams(MySqlConnection conn, ref Tournament tourney, long tourn_id) { string q = string.Format("SELECT * FROM tournament_teams WHERE tournament_id = '{0}'", tourn_id); MySqlDataReader rdr = ExecuteQuery(conn, q); while (rdr.Read()) { long _uid = rdr.GetInt64(rdr.GetOrdinal("ID")); string _name = rdr.GetString(rdr.GetOrdinal("team_name")); long captain_id = rdr.GetInt64(rdr.GetOrdinal("captain")); Team team; switch (tourney.info.Type) { case TournamentType.SOLO: { team = new Team1s(); team.Name = _name; team.Captain = tourney.getPlayerByUID(captain_id); team.ID = tourney._teams.Count; team.UID = _uid; tourney._teams.Add(team); break; } case TournamentType.DOUBLES: { team = new Team2s(); team.Name = _name; team.Captain = tourney.getPlayerByUID(captain_id); team.ID = tourney._teams.Count; team.UID = _uid; tourney._teams.Add(team); break; } case TournamentType.TRIPLES: { team = new Team3s(); team.Name = _name; team.Captain = tourney.getPlayerByID(captain_id); team.ID = tourney._teams.Count; team.UID = _uid; tourney._teams.Add(team); break; } } } rdr.Close(); }
public bool CreateTeams3s() { //By default we're generating teams for 2s List <Player> tempPlayers = new List <Player>(); foreach (Player p in _players) { tempPlayers.Add(p); } Random rnd = new Random(); List <Player> randPlayerList = tempPlayers.Select(x => new { value = x, order = rnd.Next() }) .OrderBy(x => x.order).Select(x => x.value).ToList(); if (tempPlayers.Count % 3 > 0) { //MessageBox.Show("ZIMA BALE PAIXTES NA BGAINOUN TRIADES"); return(false); } _teams.Clear(); while (tempPlayers.Count > 0) { Team3s t = new Team3s(); t.TournamentID = info.UID; t.ID = _teams.Count; t.Player1 = tempPlayers[0]; t.Player2 = tempPlayers[1]; t.Player3 = tempPlayers[2]; t.Captain = t.Player1; //Always set captain to player 1 (Random anyway) //Remove the entries tempPlayers.RemoveAt(0); tempPlayers.RemoveAt(1); tempPlayers.RemoveAt(2); _teams.Add(t); } return(true); }
public void getTournamentTeams(LiteDatabase db, ref Tournament tourney) { var collection = db.GetCollection <Team>("tournament_teams"); long tourn_id = tourney.info.UID; List <Team> teams = collection.Find(x => x.TournamentID == tourn_id).ToList(); foreach (Team t in teams) { Team team = null; switch (tourney.info.Type) { case TournamentType.SOLO: { team = new Team1s(); break; } case TournamentType.DOUBLES: { team = new Team2s(); break; } case TournamentType.TRIPLES: { team = new Team3s(); break; } } team.Name = t.Name; team.CaptainID = t.CaptainID; team.Captain = tourney.getPlayerByUID(t.CaptainID); team.ID = tourney._teams.Count; team.UID = t.UID; tourney._teams.Add(team); } }