Example #1
0
        /// <summary>
        /// find next move by monte carlo method
        /// </summary>
        /// <param name="x">current board</param>
        /// <returns>next move</returns>
        static public int MonteCarloMove(Board x)
        {
            int iterN = 2000;

            double[] score = new double[4] {
                0, 0, 0, 0
            };
            double maxScore = 0;
            int    maxi     = 0;

            Parallel.For(0, 4, (i, loopState) =>
            {
                if (BoardControl.ExecuteMove(x, i) != x)
                {
                    for (int j = 0; j < iterN; j++)
                    {
                        score[i] = score[i] + PlayGame.MontePlay(DirectScoreMove, x, 10, i);
                    }
                }
            });
            for (int k = 0; k < 4; k++)
            {
                if (score[k] > maxScore)
                {
                    maxScore = score[k];
                    maxi     = k;
                }
            }
            if (BoardControl.ExecuteMove(x, maxi) == x)
            {
                return(new Random(DateTime.Now.Millisecond).Next() % 4);
            }

            Console.WriteLine("Predict average score:" + (maxScore / iterN).ToString());
            Console.WriteLine();
            return(maxi);
        }
Example #2
0
 static void Main(string[] args)
 {
     BoardControl.Initialize();
     PreScore.Initialize();
     PlayGame.Play(AI.SearchMove);
 }