Пример #1
0
 /*
 Bd	White	Result	Black	Handicap
 1	Davis.A(1)	?:?	Jones.B(2)	0
  */
 public void ReadResults(int rnd)
 {
     List<Pairing> actualPairs = new List<Pairing> ();
     char[] c = { '\t','\v'};
     char[] c1 = { '(',')','?'};
     int[] LUT = new int[AllPlayers.Count];
     int[] CNT = new int[AllPlayers.Count];
     for (int i = 0; i < AllPlayers.Count; i++){
         if(Verbose)
             Console.WriteLine("ReadResults()i:" + i + ":S:" + AllPlayers[i].Seed);
         LUT[AllPlayers[i].Seed - 1] = i;
     }
     using (StreamReader sr = new StreamReader(workDirectory + "Round" + rnd + "Results.txt"))
     {
         sr.ReadLine ();
         sr.ReadLine ();
         string s;
         while (sr.EndOfStream == false) {
             try{
                 s = sr.ReadLine (); s.Trim (); }
             catch(Exception e){ s = "";
             }
             if (s.Length >2 ) {
                 string[] split = s.Split (c);
                 string[] split2 = split [1].Split (c1);
                 int white = int.Parse (split2 [1]) -1;
                 split2 = split [3].Split (c1);
                 int black = int.Parse (split2 [1]) -1;
                 int handicap = int.Parse (split [4].Replace ("h", ""));
                 int result = 0;
                 if (split [2].Equals ("1:0"))
                     result = 1;
                 if (split [2].Equals ("0:1"))
                     result = 2;
                 if (split [2].Equals ("0.5:0.5"))
                     result = 3;
                 if (split [2].Equals ("0:0"))
                         result = 7;
                 if(Verbose)
                     Console.WriteLine("Read Pairing: " + AllPlayers[LUT[white]].Seed + ":" + AllPlayers[LUT[black]].Seed);
                 Pairing p = new Pairing (AllPlayers [LUT [white]], AllPlayers [LUT [black]], handicap, result);
                 CNT [LUT [white]]++;
                 CNT [LUT [black]]++;
                 if (actualPairs.Contains (p) == false)
                     if (CNT [LUT [white]] == 1 && CNT [LUT [black]] == 1)
                         actualPairs.Add (p);
                     else
                         throw new Exception ("A player played more than one game in this round.");
                 else
                     Console.WriteLine ("A duplicate pairing result was detected " + p.ToFile ());
             }
         }
         //and if we did not hit an exception
         Console.WriteLine("Finished reading in results for Round " + rnd);
         RoundPairings = actualPairs;
         AllPairings.AddRange(actualPairs);
     }
 }