コード例 #1
0
ファイル: Program.cs プロジェクト: firman-2261/TA2016
        static void testNMCTS()
        {
            Board a = new Board();

            a.flip(0, 0);
            SimpleTP.DeterministicNode.side = a.sideToMove;
            SimpleTP.DeterministicNode b = new SimpleTP.DeterministicNode(a.getBoardState(), null, Constant.NONE, Constant.NONE);
            double    x     = 0;
            Stopwatch timer = new Stopwatch();

            timer.Start();
            for (int i = 0; i < 200; i++)
            {
                b.selectAction();
                //Console.WriteLine(i);
                //b.rollOut(b);
                //x += SimpleTP.Node.s;
                //Console.WriteLine(i);
            }
            timer.Stop();
            Console.WriteLine(b.nVisits);
            Console.WriteLine(x);
            Console.WriteLine(timer.Elapsed.Seconds);
            //b.rollOut(b);
            //Console.WriteLine(Node.s);
        }
コード例 #2
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);
 }
コード例 #3
0
ファイル: Program.cs プロジェクト: firman-2261/TA2016
        static void testParallelSSAB()
        {
            for (int xy = 0; xy < 1; xy++)
            {
                Console.WriteLine(xy + " uuuuuu");
                time = new Stopwatch();
                time.Start();
                Board board = new Board();
                board.flip(0, 0);
                SimpleTP.DeterministicNode.side = board.sideToMove;
                SimpleTP.DeterministicNode b = new SimpleTP.DeterministicNode(board.getBoardState(), null, Constant.NONE, Constant.NONE);
                double x = 0;
                int    u = 0;
                List <SimpleTP.Node> visited = new List <SimpleTP.Node>();
                SimpleTP.Node        cur     = b;
                visited.Add(cur);
                cur.expand();
                //cur.updateStatus(cur.rollOut(cur));
                object          a  = new object();
                ParallelOptions po = new ParallelOptions();
                po.MaxDegreeOfParallelism = 2;

                List <string> threadid = new List <string>();
                Parallel.For(0, 2000, po, i =>
                {
                    u++;
                    Console.WriteLine(u);
                    b.selectAction();
                }
                             );
                time.Stop();
                SimpleTP.Node.PGL = x / 500;
                Console.WriteLine("PGL:" + SimpleTP.Node.PGL);
                Console.WriteLine(time.Elapsed.TotalSeconds);
            }
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: firman-2261/TA2016
        static void consoleTesting()
        {
            Board logicalCDC = new Board();

            logicalCDC.flip(3, 3);
            //DeterministicNode.side = logicalCDC.sideToMove;
            Console.WriteLine("\nsidetoMove : " + logicalCDC.sideToMove);
            logicalCDC.flip(3, 4);
            while (logicalCDC.isEnd() == END_STATE.CONTINUE)
            {
                Console.WriteLine("\nsidetoMove : " + logicalCDC.sideToMove);
                SimpleTP.DeterministicNode a = new SimpleTP.DeterministicNode(logicalCDC.getBoardState(), null, Constant.NONE, Constant.NONE);
                //double x = 0;
                //for (int i = 0; i < 500; i++)
                //{
                //    a.selectAction();
                //    x += Node.s;
                //    //Console.WriteLine(Node.s);
                //}
                //Node.PGL = x / 500;
                SimpleTP.Node.PGL = 0;


                Console.WriteLine("Mulai");
                SimpleTP.DeterministicNode b = new SimpleTP.DeterministicNode(logicalCDC.getBoardState(), null, Constant.NONE, Constant.NONE);

                for (int i = 0; i < 5000; i++)
                {
                    b.selectAction();
                    Console.WriteLine(i);
                }
                Console.WriteLine("End");
                SimpleTP.Node maxWinRate = b.children[0];
                Console.WriteLine("0" + " , " + b.children[0].winRate + " , " + b.children[0].nVisits + " , " + b.children[0].action.from.ToString() + b.children[0].action.to.ToString());
                for (int i = 1; i < b.children.Length; i++)
                {
                    Console.WriteLine(i + " , " + b.children[i].winRate + " , " + b.children[i].nVisits + " , " + b.children[i].action.from.ToString() + b.children[i].action.to.ToString());
                    if (maxWinRate.winRate <= b.children[i].winRate)
                    {
                        maxWinRate = b.children[i];
                    }
                }

                if (maxWinRate.action.from.row == maxWinRate.action.to.row && maxWinRate.action.from.column == maxWinRate.action.to.column)
                {
                    Console.WriteLine("Flip");
                    Console.WriteLine("Posisi " + maxWinRate.action.from.ToString());
                    Console.WriteLine("Sebelum");
                    logicalCDC.printArrayStateFlip();
                    logicalCDC.flip(maxWinRate.action.from.row, maxWinRate.action.from.column);
                }
                else
                {
                    Console.WriteLine("move");
                    Console.WriteLine("From " + maxWinRate.action.from.ToString());
                    Console.WriteLine("to " + maxWinRate.action.to.ToString());
                    Console.WriteLine("Sebelum");
                    logicalCDC.printArrayStateFlip();

                    logicalCDC.move(maxWinRate.action.from.row, maxWinRate.action.from.column, maxWinRate.action.to.row, maxWinRate.action.to.column);
                }
                Console.WriteLine("Sesudah");
                logicalCDC.printArrayStateFlip();


                Console.WriteLine("\nsidetoMove : " + logicalCDC.sideToMove);
                Console.WriteLine("Input Move (0,4,1,0) : ");
                string   move   = Console.ReadLine();
                string[] mymove = move.Split(',');
                if (mymove.Length == 2)
                {
                    Console.WriteLine("Sebelum");
                    logicalCDC.printArrayStateFlip();
                    logicalCDC.flip(Convert.ToInt16(mymove[0]), Convert.ToInt16(mymove[1]));
                }
                else
                {
                    Console.WriteLine("Sebelum");
                    logicalCDC.printArrayStateFlip();
                    logicalCDC.move(Convert.ToInt16(mymove[0]), Convert.ToInt16(mymove[1]), Convert.ToInt16(mymove[2]), Convert.ToInt16(mymove[3]));
                }
                Console.WriteLine("Sesudah");
                logicalCDC.printArrayStateFlip();
                Console.WriteLine("Tekan Sembarangan key untuk lanjut");
                Console.ReadKey();
                System.GC.Collect();
            }
        }