Ejemplo n.º 1
0
        static void TimeMCTS()
        {
            var uct   = new UCT(Math.Sqrt(2), 123, 16000 / 3, MoveEvaluation.OneAhead);
            var board = new Board();

            while (board.Result == Result.None)
            {
                TimeOneMove(uct, board);
            }
        }
Ejemplo n.º 2
0
        static double TimeMCTSRandom()
        {
            var uct       = new UCT(Math.Sqrt(2), 123, 25000, MoveEvaluation.Random);
            var board     = new Board();
            var stopwatch = Stopwatch.StartNew();
            var move      = uct.SelectMove(board);

            stopwatch.Stop();
            Console.WriteLine($"Selected move {move}");
            Console.WriteLine($"Time UCT Random {stopwatch.ElapsedMilliseconds / (double)1000}");
            return(stopwatch.ElapsedMilliseconds);
        }
Ejemplo n.º 3
0
        private void StartButton_Click(object sender, EventArgs e)
        {
            ab        = new AlphaBeta();
            uct       = new UCT(Math.Sqrt(2), 123, 100000);
            puct      = new PUCT(Math.Sqrt(2), 123, 100000);
            ucb1tuned = new UCB1TUNED(1, 123, 100000);
            if (playerRB.Checked)
            {
                vs = VS.Player;
            }
            else if (abRB.Checked)
            {
                vs = VS.AlphaBeta;
            }
            else
            {
                vs = VS.MCTS;
            }

            if (puctRB.Checked)
            {
                algorithm = puct;
            }
            if (uctRB.Checked)
            {
                algorithm = uct;
            }
            if (tunedRB.Checked)
            {
                algorithm = ucb1tuned;
            }

            yourTurn    = youStartBox.Checked;
            board       = new Board();
            firstPlayer = play = start = true;
            MainPanel.Invalidate();
            if (!yourTurn)
            {
                PlayMove();
                CheckResult();
                firstPlayer = !firstPlayer;
                MainPanel.Invalidate();
            }
        }
Ejemplo n.º 4
0
        public Form1()
        {
            InitializeComponent();
            uct = new UCT();
            t = uct.connect_gui();

            th = new System.Threading.Thread(new System.Threading.ThreadStart(back_loop));
            th.IsBackground = true;
            //スレッドを開始する
            th.Start();

            /*tweet_th = new System.Threading.Thread(new System.Threading.ThreadStart(bot));
            tweet_th.IsBackground = true;
            //スレッドを開始する
            tweet_th.Start();*/

            tweet_th = new System.Threading.Thread(new System.Threading.ThreadStart(mae_bot));
            tweet_th.IsBackground = true;
            //スレッドを開始する
            tweet_th.Start();

        }
Ejemplo n.º 5
0
        static void UCTvsPUCT()
        {
            var gameCount    = 30;
            var rolloutCount = 25000;

            var ResultWinDict = new Dictionary <string, int>()
            {
                { "UCTfirst", 0 },
                { "UCTsecond", 0 },
                { "PUCTfirst", 0 },
                { "PUCTsecond", 0 }
            };

            for (int i = 0; i < gameCount; i++)
            {
                IAlgorithmInterface firstPlayer;
                IAlgorithmInterface secondPlayer;
                var uct       = new UCT(Math.Sqrt(2), i, rolloutCount);
                var puct      = new PUCT(Math.Sqrt(2), i, rolloutCount);
                var puctFirst = false;
                if (i < gameCount / 2)
                {
                    puctFirst    = true;
                    firstPlayer  = puct;
                    secondPlayer = uct;
                }
                else
                {
                    puctFirst    = false;
                    firstPlayer  = uct;
                    secondPlayer = puct;
                }
                var board        = new Board();
                var activePlayer = firstPlayer;
                while (board.Result == Result.None)
                {
                    board.PutToken(activePlayer.SelectMove(board));
                    if (activePlayer == firstPlayer)
                    {
                        activePlayer = secondPlayer;
                    }
                    else
                    {
                        activePlayer = firstPlayer;
                    }
                }


                if (board.Result == Result.FirstWon)
                {
                    if (puctFirst)
                    {
                        ResultWinDict["PUCTfirst"]++;
                    }
                    else
                    {
                        ResultWinDict["UCTfirst"]++;
                    }
                }
                else
                {
                    if (puctFirst)
                    {
                        ResultWinDict["UCTsecond"]++;
                    }
                    else
                    {
                        ResultWinDict["PUCTsecond"]++;
                    }
                }
            }
            Console.WriteLine("PUCT vs UCT");
            foreach (var kvp in ResultWinDict)
            {
                Console.WriteLine($"{kvp.Key}: {kvp.Value}");
            }
            Console.WriteLine();
        }