Пример #1
0
        public void DRAW(int start=0)
        {
            Player top = plys [start];
            Pairing tmp;
            if(Verbose)	Console.WriteLine ("Calling SimpleDraw() start:" + start);
            bool found = false;
            for (int i = start+1; i <= plys.Count -1; i++) { //foreachPlayer
                if (LookUpBull [i] == true) {
                    found = true;
                }
                else
                    found =false;
                while (found == false) {
                    foreach (McLayer mcl in BigM) { //foreachLayer
                        if(found==false)
                            for (int j = 0; j < mcl.Length; j++) {
                                tmp = new Pairing (plys[mcl.GetAt (j)], top);
                                //Is this path really accurate?
                                tryPath = path + " " + top.Deed + "," + plys[mcl.GetAt(j)].Deed;
                                if (plys[mcl.GetAt(j)].Deed != top.Deed)
                                if (LookUpBull[plys[mcl.GetAt(j)].Deed] == false)
                                if(ValidPath(tryPath)==true)
                                if (History.Contains(tmp) == false) //cannot allow repeat pairing
                                    {
                                    LookUpBull[top.Deed ] = true;
                                    LookUpBull[plys[mcl.GetAt (j)].Deed] = true;
                                    path += " " + top.Deed + "," + plys[mcl.GetAt(j)].Deed;
                                    if(Verbose)	Console.WriteLine (path);
                                    Pairs.Add(tmp);
                                    found = true;
                                    top = plys[0];
                                    for (int k = 0; k < LookUpBull.Length; k++) //update top
                                        if ( LookUpBull[k] == false) {
                                            top = plys [k];
                                            k = LookUpBull.Length + 1;
                                        }
                                    if ((Pairs.Count + Pairs.Count) == plys.Count) {
                                        found = true;
                                        return;
                                    }
                                    break; //out of j
                                }//end if
                            }//end j
                    }//foreachLayer
                    if (found == false)
                    {
                        if (Pairs.Count == plys.Count - Pairs.Count)
                            return;
                        string sp = path;
                        Paths.Add(sp);
                        CleanBlocked(sp);
                        int penultimateSpace = path.LastIndexOf(" ");
                        //DM1 doesn't need restore as we never empty the McLayer
                        //Which makes it super slug like
                        path = path.Remove(penultimateSpace);
                        //Mandatory removal of last pair
                        //update lookups
                        LookUpBull [Pairs [Pairs.Count - 1].black.Deed]=false;
                        LookUpBull [Pairs [Pairs.Count - 1].white.Deed]=false;
                        //rm last pairing added
                        Pairs.RemoveAt(Pairs.Count - 1);
                        //Now we check the path to see if we need to go deeper

                        //why don't we call at highest false
                        for (int re = 0; re < LookUpBull.Length; re++ )
                            if (LookUpBull[re] == false)
                            {
                            //    depth = Pairs.Count;
                                retry++;
                                DRAW(re);
                            }
                        //used to be DRAW(i-2);
                    }
                }

            }//end foreachplayer
        }
Пример #2
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);
     }
 }