示例#1
0
文件: Debater.cs 项目: julmaxi/opdtab
 public Debater(Debater d) : base(d)
 {
     InitFields();
     // ALWAYS COPY!
     extraInfo    = d.ExtraInfo;
     roundResults = new List <RoundResultData>(d.RoundResults);
     visitedRooms = new MyDictionary <string, int>(d.VisitedRooms);
     blackList.ParsePattern(d.BlackList.ToString());
     whiteList.ParsePattern(d.WhiteList.ToString());
 }
示例#2
0
 bool IsDebaterInList(List <TeamData> list, Debater d)
 {
     return(list.FindLastIndex(delegate(TeamData td) {
         foreach (RoundDebater de in td)
         {
             if (de.Equals(d))
             {
                 return true;
             }
         }
         return false;
     }) != -1);
 }
示例#3
0
 void AddToPartners(List <RoundDebater> l, Debater d, List <Debater> o1, IList <RoundDebater> o2)
 {
     for (int j = 0; j < o1.Count; j++)
     {
         if (o1[j] == null || o2[j] == null || d == o1[j])
         {
             continue;
         }
         if (d.ConflictsWith(o1[j]))
         {
             l.Add(o2[j]);
         }
     }
 }
示例#4
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);
                    }
                }
            }
        }
示例#5
0
 bool IsDebaterInList(List <RoundDebater> list, Debater d)
 {
     return(list.FindLastIndex(delegate(RoundDebater rd) {
         return rd.Equals(d);
     }) != -1);
 }
示例#6
0
 public EditableDebater(Debater d) : base(d)
 {
 }
示例#7
0
        public static void UpdateStats()
        {
            // store for roundAvg, 0...8=speakers, 9/10=gov/opp
            Dictionary <string, List <int>[]> store1 = new Dictionary <string, List <int>[]>();

            foreach (RoundData rd in Tournament.I.Rounds)
            {
                store1[rd.RoundName] = new List <int>[] {                // eleven lists for 0...8, and teams
                    new List <int>(), new List <int>(), new List <int>(),
                    new List <int>(), new List <int>(), new List <int>(),
                    new List <int>(), new List <int>(), new List <int>(),
                    new List <int>(), new List <int>()
                };
            }

            // stores for avgSpeaker/avgTeam
            Dictionary <Debater, List <double> > store2 = new Dictionary <Debater, List <double> >();
            Dictionary <string, List <double> >  store3 = new Dictionary <string, List <double> >();

            foreach (Debater d in Tournament.I.Debaters)
            {
                if (d.Role.IsTeamMember)
                {
                    foreach (RoundResultData rr in d.RoundResults)
                    {
                        List <int>[] val;
                        if (store1.TryGetValue(rr.RoundName, out val))
                        {
                            int pos = rr.GetPosition();
                            foreach (int p in rr.SpeakerScores)
                            {
                                if (p >= 0)
                                {
                                    val[pos].Add(p);
                                }
                            }
                            pos = (int)rr.Role + 9;
                            foreach (int p in rr.TeamScores)
                            {
                                if (p >= 0)
                                {
                                    val[pos].Add(p);
                                }
                            }
                        }
                    }
                    // just init, used in following loops
                    store2[d] = new List <double>();
                    store3[d.Role.TeamName] = new List <double>();
                }
                // clear stats
                d.ClearResultStats();
            }

            // calculate averages: per round and per position
            Dictionary <string, double[]> roundAvg = new Dictionary <string, double[]>();

            foreach (string rN in store1.Keys)
            {
                roundAvg[rN] = new double[11];
                // i iterates over positions and teams
                for (int i = 0; i < 11; i++)
                {
                    roundAvg[rN][i] =
                        OPDtabData.MiscHelpers.CalcExactAverage(store1[rN][i]);
                }
            }

            // collect performance of speaker/team per round
            foreach (Debater d in store2.Keys)
            {
                foreach (RoundResultData rr in d.RoundResults)
                {
                    double[] val;
                    if (roundAvg.TryGetValue(rr.RoundName, out val))
                    {
                        int    pos = rr.GetPosition();
                        double avg =
                            OPDtabData.MiscHelpers.CalcExactAverage(rr.SpeakerScores);
                        if (avg >= 0 && val[pos] >= 0)
                        {
                            store2[d].Add(avg - val[pos]);
                        }
                        pos = (int)rr.Role + 9;
                        avg =
                            OPDtabData.MiscHelpers.CalcExactAverage(rr.TeamScores);
                        if (avg >= 0 && val[pos] >= 0)
                        {
                            store3[d.Role.TeamName].Add(avg - val[pos]);
                        }
                    }
                }
            }

            // calculate averages of performance,
            // is used to "predict" performance in selected round
            // compare it with result of judge
            Dictionary <RoundDebater, double> speakerAvg = new Dictionary <RoundDebater, double>();
            Dictionary <string, double>       teamAvg    = new Dictionary <string, double>();

            foreach (string t in store3.Keys)
            {
                teamAvg[t] = OPDtabData.MiscHelpers.CalcExactAverage(store3[t]);
            }
            foreach (Debater d in store2.Keys)
            {
                double avg = OPDtabData.MiscHelpers.CalcExactAverage(store2[d]);
                speakerAvg[new RoundDebater(d)] = avg;
                foreach (RoundResultData rr in d.RoundResults)
                {
                    rr.Stats[0] = avg;
                    rr.Stats[1] = teamAvg[d.Role.TeamName];
                }
            }

            // iterate over rounds and rooms
            // and compare expected points with judge score
            // also save the calculated averages in round per position
            Dictionary <Debater, Dictionary <string, List <double>[]> > store4 =
                new Dictionary <Debater, Dictionary <string, List <double>[]> >();

            foreach (RoundData rd in Tournament.I.Rounds)
            {
                // save the averages, is shown in ShowRanking
                double[] avgPoints;
                if (roundAvg.TryGetValue(rd.RoundName, out avgPoints))
                {
                    rd.AvgPoints = new List <double>(avgPoints);
                }
                // iterate over rooms
                foreach (RoomData room in rd.Rooms)
                {
                    List <object> data = room.AsOrderedObjects();

                    foreach (RoundDebater j in room.Judges)
                    {
                        Debater judge = Tournament.I.FindDebater(j);
                        if (judge == null)
                        {
                            continue;
                        }
                        RoundResultData rr = judge.RoundResults.Find(delegate(RoundResultData rr_) {
                            return(rr_.Equals(rd.RoundName));
                        });
                        if (rr == null)
                        {
                            continue;
                        }

                        // init store4 on the fly
                        Dictionary <string, List <double>[]> dic;
                        if (!store4.TryGetValue(judge, out dic))
                        {
                            dic           = new Dictionary <string, List <double>[]>();
                            store4[judge] = dic;
                        }
                        List <double>[] list;
                        if (!dic.TryGetValue(rd.RoundName, out list))
                        {
                            list = new List <double>[] {
                                new List <double>(), new List <double>()
                            };
                            dic[rd.RoundName] = list;
                        }

                        for (int i = 0; i < 11; i++)
                        {
                            if (data[i] == null)
                            {
                                continue;
                            }

                            if (i < 9)
                            {
                                double correct;
                                if (speakerAvg.TryGetValue((RoundDebater)data[i], out correct))
                                {
                                    double expected = correct + roundAvg[rd.RoundName][i];
                                    int    score    = rr.SpeakerScores[i];
                                    if (score < 0)
                                    {
                                        continue;
                                    }
                                    list[0].Add(score - expected);
                                }
                            }
                            else
                            {
                                double correct;
                                if (teamAvg.TryGetValue((data[i] as TeamData).TeamName, out correct))
                                {
                                    double expected = correct + roundAvg[rd.RoundName][i];
                                    int    score    = rr.TeamScores[i - 9];
                                    if (score < 0)
                                    {
                                        continue;
                                    }
                                    list[1].Add(score - expected);
                                }
                            }
                        }
                    }
                }
            }

            // the final result is the avg/sigma in store4
            foreach (Debater d in store4.Keys)
            {
                foreach (string rN in store4[d].Keys)
                {
                    double sum  = 0;
                    double sum2 = 0;
                    foreach (double num in store4[d][rN][0])
                    {
                        sum  += num;
                        sum2 += num * num;
                    }
                    int    count  = store4[d][rN][0].Count;
                    double mu     = count == 0?double.NaN:sum / count;
                    double mu_err = count == 0?double.NaN:
                                    Math.Sqrt((sum2 / count - mu * mu) / count);
                    // search roundResult and set stats
                    foreach (RoundResultData rr in d.RoundResults)
                    {
                        if (rr.RoundName == rN)
                        {
                            rr.Stats[0] = mu;
                            rr.Stats[1] = mu_err;
                            rr.Stats[2] = OPDtabData.MiscHelpers.CalcExactAverage(store4[d][rN][1]);
                        }
                    }
                }
                // update averages
                d.UpdateStatsAvg();
            }
        }