Exemplo n.º 1
0
        public bool ReplaceInAllArrays(RoundDebater old, RoundDebater rd)
        {
            // don't rely on the role of old, might have changed.

            // search in AllTeams
            foreach (TeamData team in allTeams)
            {
                for (int i = 0; i < team.Count; i++)
                {
                    if (old.Equals(team[i]))
                    {
                        team[i] = rd;
                        return(true);
                    }
                }
            }
            // search in AllJudges
            for (int i = 0; i < allJudges.Count; i++)
            {
                if (old.Equals(allJudges[i]))
                {
                    allJudges[i] = rd;
                    return(true);
                }
            }
            // none found
            return(false);
        }
Exemplo n.º 2
0
        public RoomData(RoomData room, bool isShown) : this()
        {
            index = room.Index;
            if (!room.Gov.IsEmpty)
            {
                gov = new TeamData(room.Gov, isShown);
            }
            if (!room.Opp.IsEmpty)
            {
                opp = new TeamData(room.Opp, isShown);
            }
            if (room.Chair != null)
            {
                chair = new RoundDebater(room.Chair, isShown);
            }

            foreach (RoundDebater rd in room.FreeSpeakers)
            {
                freeSpeakers.Add(new RoundDebater(rd, isShown));
            }
            foreach (RoundDebater rd in room.Judges)
            {
                judges.Add(new RoundDebater(rd, isShown));
            }
        }
Exemplo n.º 3
0
        public static RoundDebater Dummy()
        {
            RoundDebater rd = new RoundDebater();

            rd.isDummy = true;
            return(rd);
        }
Exemplo n.º 4
0
 public Debater FindDebater(RoundDebater rd)
 {
     // optimize by sort does not seem beneficial...
     if (rd == null || rd.IsEmpty)
     {
         return(null);
     }
     return(debaters.Find(delegate(Debater d) {
         return d.Equals(rd);
     }));
 }
Exemplo n.º 5
0
        public static void Prepare(int randomSeed, int mcSteps, bool cyclic, List <TeamData> t)
        {
            SetTeams(t);
            // just make empty chairs and judges

            for (int i = 0; i < 3 * nRooms; i++)
            {
                chairs[i] = new RoundDebater();
                judges[i] = new List <RoundDebater>();
            }
            SetOthers(randomSeed, mcSteps, true, cyclic);
        }
Exemplo n.º 6
0
 public RoomData()
 {
     index         = -1;
     itemCompleted = false;
     gov           = new TeamData();
     opp           = new TeamData();
     chair         = new RoundDebater();
     freeSpeakers  = new List <RoundDebater>();
     judges        = new List <RoundDebater>();
     bestTeam      = -1;
     bestSpeaker   = -1;
 }
Exemplo n.º 7
0
 public RoomConflict(RoundDebater o)
 {
     owner     = o;
     partners1 = new Dictionary <Type, List <RoundDebater> >();
     foreach (Type t in Enum.GetValues(typeof(Type)))
     {
         partners1[t] = new List <RoundDebater>();
     }
     partners2 = new Dictionary <string, Complex>();
     // Don't init partners2, we reflect that by access methods..
     // we don't know the current number of rooms,
     // Tournament.I.Rounds might be invalid (but I.Debaters is valid!)
 }
Exemplo n.º 8
0
 public RoomData(int i, TeamData g, TeamData o,
                 RoundDebater c, List <RoundDebater> j) : this()
 {
     index = i;
     gov   = g;
     opp   = o;
     // expected to be completely set by Algorithm!
     freeSpeakers.Add(null);
     freeSpeakers.Add(null);
     freeSpeakers.Add(null);
     judges = j;
     if (c != null)
     {
         chair = c;
     }
 }
Exemplo n.º 9
0
        public bool ReplaceRoomMember(RoundDebater old, RoundDebater rd)
        {
            // don't rely on the role of old, might have changed.
            // search gov/opp

            for (int i = 0; i < 3; i++)
            {
                if (old.Equals(gov[i]))
                {
                    Console.WriteLine("Gov: " + old + " -> " + rd);
                    gov[i] = rd;
                    return(true);
                }
                if (old.Equals(opp[i]))
                {
                    Console.WriteLine("Opp: " + old + " -> " + rd);
                    opp[i] = rd;
                    return(true);
                }
            }
            // search free
            for (int i = 0; i < freeSpeakers.Count; i++)
            {
                if (old.Equals(freeSpeakers[i]))
                {
                    Console.WriteLine("Free: " + old + " -> " + rd);
                    freeSpeakers[i] = rd;
                    return(true);
                }
            }
            // search chair and judges
            if (old.Equals(chair))
            {
                Console.WriteLine("Chair: " + old + " -> " + rd);
                chair = rd;
            }
            for (int i = 0; i < judges.Count; i++)
            {
                if (old.Equals(judges[i]))
                {
                    Console.WriteLine("Judge: " + old + " -> " + rd);
                    judges[i] = rd;
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 10
0
        public static void AddMemberToTeamList(List <TeamData> teams, RoundDebater d)
        {
            TeamData teamData =
                teams.FindLast(delegate(TeamData td) {
                return(td.Equals(d.Role.TeamName));
            });

            if (teamData != null)
            {
                // this might throw an exception
                teamData.AddMember(d);
            }
            else
            {
                teams.Add(new TeamData(d));
            }
        }
Exemplo n.º 11
0
        public void Update()
        {
            availRounds = new Dictionary <string, bool>();
            teams       = new List <RankingDataItem>();
            speakers    = new List <RankingDataItem>();
            // temporary aggregation for teams
            List <TeamData> tmp1 = new List <TeamData>();
            List <List <RoundResultData> > tmp2 = new List <List <RoundResultData> >();

            foreach (Debater d in Tournament.I.Debaters)
            {
                if (!d.Role.IsTeamMember)
                {
                    continue;
                }
                RoundDebater rd = new RoundDebater(d, true);
                speakers.Add(new RankingDataItem(rd, d.RoundResults));

                // aggregate teams
                int i = tmp1.FindLastIndex(delegate(TeamData td) {
                    return(td.Equals(d.Role.TeamName));
                });

                if (i < 0)
                {
                    tmp1.Add(new TeamData(rd));
                    tmp2.Add(new List <RoundResultData>(d.RoundResults));
                }
                else
                {
                    tmp1[i].AddMember(rd);
                    tmp2[i].AddRange(d.RoundResults);
                }
            }
            // aggregate availRounds
            foreach (RoundData rd in Tournament.I.Rounds)
            {
                availRounds[rd.RoundName] = true;
            }

            for (int i = 0; i < tmp1.Count; i++)
            {
                teams.Add(new RankingDataItem(tmp1[i], tmp2[i]));
            }
        }
Exemplo n.º 12
0
 public override bool Equals(object obj)
 {
     // handle possible dummy debater
     if (obj is RoundDebater)
     {
         RoundDebater rd = (RoundDebater)obj;
         if (rd.isDummy && isDummy)
         {
             // two dummies equal
             return(true);
         }
         else if (rd.isDummy || isDummy)
         {
             // dummy never equals non-dummy debater
             return(false);
         }
     }
     // by default, let base class decide
     return(base.Equals(obj));
 }
Exemplo n.º 13
0
        static int SearchConflicts(List <RoomData>[] rounds, int round, RoundDebater rd1, RoundDebater rd2)
        {
            int conflicts = 0;

            for (int otherRound = 0; otherRound < rounds.Length; otherRound++)
            {
                if (otherRound == round)
                {
                    continue;
                }
                foreach (RoomData otherRoom in rounds[otherRound])
                {
                    List <RoundDebater> rd = otherRoom.GetRoomMembers();
                    int n = 0;
                    foreach (RoundDebater rd_ in rd)
                    {
                        if (rd_ == null)
                        {
                            continue;
                        }
                        if (rd_.Equals(rd1))
                        {
                            n++;
                        }
                        if (rd_.Equals(rd2))
                        {
                            n++;
                        }
                        if (n == 2)
                        {
                            conflicts++;
                            goto nextRound;
                        }
                    }
                }
                nextRound :;
            }
            return(conflicts);
        }
Exemplo n.º 14
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);
                    }
                }
            }
        }