public void Prove(Game g) { // Clear the transposition table and queue transposition.Clear(); queue.Clear(); // Evaluate root and add it to transposition table root = new BNode(g.startingPos, 1); root.Evaluate (g); transposition[root] = root; queue.Enqueue(root); BNode next; int count = 0; Stopwatch sw = new Stopwatch(); sw.Start(); while (root.value == 0 && queue.Count > 0) { next = queue.Dequeue(); next.Expand(g, transposition, queue); BNode.InitiateVisiting(); next.Update(g); if (sw.ElapsedMilliseconds > timeLimit * 60000) break; /*if(count % 1000 == 0) { Console.WriteLine("Value: " + n.value); Console.WriteLine("Transposition: " + BNode.transposition.Count); Console.WriteLine("Queue: " + BNode.queue.Count); }*/ count++; } sw.Stop(); timeSpent = (int) sw.ElapsedMilliseconds; /*Console.WriteLine((root.value==1?"Black":root.value==-1?"White":"Nobody") + " won!"); Console.WriteLine("Transposition: " + transposition.Count); Console.WriteLine("Queue: " + queue.Count);*/ }
public void Expand(Game g, Hashtable transposition, Queue<BNode> queue) { children = new List<BNode>(); var plies = g.children(position, c); foreach (var ply in plies) { var s = new BNode(ply.Apply (position, g), (byte)(c ^ 1)); if (transposition.ContainsKey(s)) { s = (BNode)transposition[s]; } else { s.Evaluate(g); transposition[s] = s; if(s.value == 0) queue.Enqueue(s); } s.parents.Add(this); children.Add(s); } }