public void Expand(Game g, Hashtable transposition) { if(children != null) return; children = new List<Node>(); var plies = g.children(position, c); foreach (var ply in plies) { var s = new Node(ply.Apply(position, g), (byte)(c ^ 1)); if (transposition.ContainsKey(s)) s = (Node)transposition[s]; else { s.Evaluate(g); transposition[s] = s; } s.parents.Add(this); children.Add(s); } }
public void ExpandTree(Game g, ref int nodeCount, ref int collisionCount, Hashtable transposition) { if(children != null) return; children = new List<Node>(); var plies = g.children(position, c); foreach (var ply in plies) { var s = new Node(ply.Apply(position, g), (byte)(c ^ 1)); s.Evaluate(g); nodeCount++; if (transposition.ContainsKey(s)) collisionCount++; else transposition.Add(s, s); s.parents.Add(this); children.Add(s); } }
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); } }