Exemple #1
0
 public static void Main(string[] args)
 {
     GameSetup setup = new GameSetup (4, 3);
     setup.SetPromotionRanks (1);
     //setup.AddWhitePiece (0, 0, Type.Bishop);
     setup.AddWhitePiece (1, 0, Type.King);
     setup.AddWhitePiece (2, 0, Type.Rook);
     //setup.AddWhitePiece (1, 1, Type.Pawn);
     //setup.AddBlackPiece (2, 3, Type.Bishop);
     setup.AddBlackPiece (1, 3, Type.King);
     setup.AddBlackPiece (0, 3, Type.Rook);
     //setup.AddBlackPiece (1, 2, Type.Pawn);
     Game g = new Game(setup);
     Console.WriteLine(g.prettyPrint(g.startingPos));
     var pn = new PNSearch (false, 15);
     pn.Prove (g);
     var bestgame = pn.BestGame ();
     foreach (var pos in bestgame)
     {
         Console.WriteLine(g.prettyPrint(pos));
     }
 }
Exemple #2
0
        public void Prove(Game g)
        {
            root = new Node (g.startingPos, 1);
            root.Evaluate (g);
            transposition [root] = root;
            nodeCount++;
            Node lastExpanded = null;
            int lastpn = 0, lastdn = 0;

            int count = 0;

            Stopwatch sw = new Stopwatch ();
            sw.Start ();
            while (root.pn != 0 && root.dn != 0) {
                var mpn = MostProving (root);

                if (graph) {
                    if (System.Object.ReferenceEquals (mpn, lastExpanded) && lastpn == mpn.pn && lastdn == mpn.dn) {
                        sw.Stop ();
                        timeSpent = (int)sw.ElapsedMilliseconds;
                        throw new Exception ("Loop in finding most proving");
                    }
                    mpn.Expand (g, transposition);
                    mpn.StartUpdate ();

                    lastExpanded = mpn;
                    lastpn = mpn.pn;
                    lastdn = mpn.dn;
                } else {
                    mpn.ExpandTree (g, ref  nodeCount, ref collisionCount, transposition);
                    mpn.StartUpdateTree (firstRun);

                    if (count % 10000 == 0)
                    {
                        Console.WriteLine("PN:         {0}\nDN:         {1}", root.pn, root.dn);
                        Console.WriteLine("Collisions: " + collisionCount);
                        Console.WriteLine("Nodes:      " + nodeCount);
                    }

                    count++;
                }

                if (sw.ElapsedMilliseconds > timeLimit * 60000) {
                    sw.Stop ();
                    timeSpent = (int)sw.ElapsedMilliseconds;
                    throw new Exception ("Time limit exceeded");
                }
            }

            sw.Stop ();
            timeSpent = (int)sw.ElapsedMilliseconds;

            // If this is the first run of a graph search where black loses, run again to check for draw
            if (!graph && firstRun && root.dn == 0) {
                second = new PNSearch (false, timeLimit);
                second.firstRun = false;
                second.Prove (g);
            }
        }