예제 #1
0
 private DeterministicNode move()
 {
     if (base.isShowConsole)
     {
         Console.WriteLine("EXECUTE TASK : " + Task.CurrentId + ", ON THREAD : " + System.Threading.Thread.CurrentThread.ManagedThreadId);
     }
     while (timer.Elapsed.TotalSeconds <= base.wktThinking)
     {
         //if (base.isVerboseRunning)
         //{
         //    Console.WriteLine("Left Time : " + (wktThinking - timer.Elapsed.TotalSeconds));
         //}
         tree.selectAction();
     }
     return(tree);
 }
예제 #2
0
        static void testParallelSrVl()
        {
            for (int xy = 0; xy < 1; xy++)
            {
                Console.WriteLine(xy + " uuuuuu");
                time = new Stopwatch();
                time.Start();
                Board board = new Board();
                board.flip(0, 0);
                SimpleTPVL.DeterministicNode.side = board.sideToMove;
                SimpleTPVL.DeterministicNode b = new SimpleTPVL.DeterministicNode(board.getBoardState(), null, Constant.NONE, Constant.NONE);
                double x = 0;
                int    u = 0;
                List <SimpleTPVL.Node> visited = new List <SimpleTPVL.Node>();
                SimpleTPVL.Node        cur     = b;
                visited.Add(cur);
                cur.expand();
                //cur.updateStatus(cur.rollOut(cur));
                object          a  = new object();
                ParallelOptions po = new ParallelOptions();
                po.MaxDegreeOfParallelism = 100;

                List <string> threadid = new List <string>();
                Parallel.For(0, 4000, po, i =>
                {
                    //lock (a)
                    //{
                    //    bool found = false;
                    //    foreach (string y in threadid)
                    //    {
                    //        if (y == Thread.CurrentThread.ManagedThreadId.ToString())
                    //        {
                    //            found = true;
                    //            break;
                    //        }
                    //    }
                    //    if (!found)
                    //    {
                    //        threadid.Add(Thread.CurrentThread.ManagedThreadId.ToString());
                    //    }
                    //}
                    u++;
                    Console.WriteLine(u);
                    b.selectAction();
                    //lock (a)
                    //{
                    //    while (!(cur.isLeaf()))
                    //    {
                    //        cur = cur.select();
                    //        visited.Add(cur);
                    //        if (cur is TP.NondeterministicNode)
                    //        {
                    //            if (((TP.NondeterministicNode)cur).selected != null)
                    //            {
                    //                cur = ((TP.NondeterministicNode)cur).selected;
                    //            }
                    //            else
                    //            {
                    //                cur = ((TP.NondeterministicNode)cur.select()).selected;
                    //            }
                    //            visited.Add(cur);
                    //        }
                    //    }
                    //    cur.expand();
                    //}
                    //double value = cur.rollOut(cur);
                    //foreach (TP.Node node in visited)
                    //{
                    //    node.updateStatus(value);
                    //}
                    //lock (a)
                    //{
                    //    x +=Node.s;
                    //}
                }//;
                             );

                //foreach (string y in threadid)
                //{
                //    Console.WriteLine(y);
                //}

                //for (int i = 0; i < 2001; i++)
                //{
                //    Console.WriteLine(i);
                //    b.selectAction(cur);
                //    Console.WriteLine(i);
                //    x += Node.s;
                //}//;
                time.Stop();
                SimpleTP.Node.PGL = x / 500;
                Console.WriteLine("PGL:" + SimpleTP.Node.PGL);
                Console.WriteLine(time.Elapsed.TotalSeconds);
            }
        }