Esempio n. 1
0
        public static List <RoomData> Generate(RoundData roundData,
                                               List <TeamData> bestTeams,
                                               List <RoundDebater> bestSpeakers
                                               )
        {
            List <RoomData>     round            = new List <RoomData>();
            List <TeamData>     breakingTeams    = new List <TeamData>();
            List <RoundDebater> breakingSpeakers = new List <RoundDebater>();
            int nonEmptyRooms = 0;

            foreach (RoomData room in roundData.Rooms)
            {
                // only rooms with valid bestSpeaker and bestTeam (set by RoundResultSheet)
                if (room.ValidBest)
                {
                    // teams
                    if (room.BestTeam == 0)
                    {
                        breakingTeams.Add(room.Gov);
                    }
                    else
                    {
                        breakingTeams.Add(room.Opp);
                    }
                    // best non-team breaking Speaker
                    breakingSpeakers.Add((RoundDebater)room.AsOrderedObjects()[room.BestSpeaker]);
                }
                if (!room.IsEmpty)
                {
                    nonEmptyRooms++;
                }
            }
            if (nonEmptyRooms % 2 != 0 ||
                breakingTeams.Count == 0 ||
                nonEmptyRooms != breakingTeams.Count)
            {
                throw new Exception("Selected round not valid for creating breakround.");
            }
            // sort teams by ranking
            breakingTeams.Sort(delegate(TeamData td1, TeamData td2) {
                int i1 = bestTeams.FindIndex(delegate(TeamData td) {
                    return(td.Equals(td1));
                });
                int i2 = bestTeams.FindIndex(delegate(TeamData td) {
                    return(td.Equals(td2));
                });
                return(i1.CompareTo(i2));
            });
            // create round by power pairing
            // position of freeSpeakers is rather irrelevant
            for (int i = 0; i < breakingTeams.Count / 2; i++)
            {
                RoomData room = new RoomData(i,
                                             breakingTeams[i],
                                             breakingTeams[breakingTeams.Count - 1 - i]);
                // add two free speakers
                room.FreeSpeakers.Add(breakingSpeakers[2 * i]);
                room.FreeSpeakers.Add(breakingSpeakers[2 * i + 1]);
                round.Add(room);
            }
            return(round);
        }
Esempio n. 2
0
        public static void Prepare(int randomSeed, int mcSteps,
                                   RoundData roundData,
                                   List <RoundDebater> bestSpeakers)
        {
            // copy startConfig from given/current roundData
            startConfig   = new List <RoomData>();
            availSpeakers = new List <RoundDebater>();
            foreach (RoomData room in roundData.Rooms)
            {
                // only consider non-empty
                if (room.IsEmpty)
                {
                    continue;
                }
                // already set FreeSpeakers are added to
                // availSpeakers (no ordering by Ranking)
                foreach (RoundDebater rd in room.FreeSpeakers)
                {
                    availSpeakers.Add(rd);
                }
                // make a hard copy, and clear freespeakers
                RoomData newRoom = new RoomData(room, true);
                newRoom.FreeSpeakers.Clear();
                startConfig.Add(newRoom);
            }
            nRooms = startConfig.Count;
            if (nRooms == 0)
            {
                throw new Exception("No non-empty Rooms found.");
            }

            // determine avail teams from roundData,
            // only the ones completely shown in pool
            // and ordered by ranking!

            foreach (RoundDebater rd in bestSpeakers)
            {
                TeamData td = roundData.AllTeams.Find(delegate(TeamData td_) {
                    return(td_.Equals(rd.Role.TeamName));
                });
                if (td == null)
                {
                    continue;
                }
                // check if debater is shown!
                foreach (RoundDebater rd_ in td)
                {
                    if (rd.Equals(rd_) && !rd_.IsShown)
                    {
                        goto outer;
                    }
                }
                // stop if we have enough free speakers
                if (availSpeakers.Count == 3 * nRooms)
                {
                    break;
                }
                // debater is shown in pool, so add it
                availSpeakers.Add(rd);

                outer :;
            }

            if (availSpeakers.Count < 3 * nRooms)
            {
                throw new Exception("Found " + availSpeakers.Count + " available Speakers, not enough for " + nRooms + " rooms.");
            }

            // sort availSpeakers again by Ranking, since the ones already set in rooms come first in availSpeakers
            // ByRanking relies on correct ordering in availSpeakers
            availSpeakers.Sort(delegate(RoundDebater rd1, RoundDebater rd2) {
                int i1 = bestSpeakers.FindIndex(delegate(RoundDebater rd) {
                    return(rd.Equals(rd1));
                });
                int i2 = bestSpeakers.FindIndex(delegate(RoundDebater rd) {
                    return(rd.Equals(rd2));
                });
                return(i1.CompareTo(i2));
            });
            // some other config, not used by ByRanking
            steps  = mcSteps;
            random = new Random(randomSeed);
        }
Esempio n. 3
0
        // this is really bad coding.
        // but it seems to keep the arrays consistent!
        public void UpdateAllArrays()
        {
            // set all to shown
            foreach (RoundDebater rd in allJudges)
            {
                rd.IsShown = true;
                Debater d = Tournament.I.FindDebater(rd);
                if (d != null)
                {
                    d.SetRoom(roundName, RoomData.Dummy());
                }
            }

            foreach (TeamData td in allTeams)
            {
                foreach (RoundDebater rd in td)
                {
                    rd.IsShown = true;
                    Debater d = Tournament.I.FindDebater(rd);
                    if (d != null)
                    {
                        d.SetRoom(roundName, RoomData.Dummy());
                    }
                }
            }

            // then set roomMembers to false
            foreach (RoomData room in rooms)
            {
                foreach (RoundDebater rd in room.GetRoomMembers())
                {
                    if (rd == null)
                    {
                        continue;
                    }
                    // check both cases
                    if (rd.Role.IsJudge)
                    {
                        RoundDebater judge = allJudges.Find(delegate(RoundDebater rd_) {
                            return(rd_.Equals(rd));
                        });
                        // judge should always be found,
                        // is not shown in pool
                        judge.IsShown = false;
                    }
                    else if (rd.Role.IsTeamMember)
                    {
                        // we need to find the reference of rd in allTeams,
                        // set this one to not shown in pool, since it is in room
                        TeamData td = allTeams.Find(delegate(TeamData td_) {
                            return(td_.Contains(rd));
                        });
                        foreach (RoundDebater rd_ in td)
                        {
                            if (rd_.Equals(rd))
                            {
                                rd_.IsShown = false;
                            }
                        }
                    }
                    // update visited rooms
                    Debater d = Tournament.I.FindDebater(rd);
                    if (d != null)
                    {
                        d.SetRoom(roundName, room);
                    }
                }
            }
        }