Beispiel #1
0
        static void ShowMobilityScorePairs()
        {
            Game game = new Game();

            game.Begin(null, null, 10);

            AnalysisGraph analysisGraph = new AnalysisGraph();

            analysisGraph.BuildAnalysis(game.CurrentBoard.PieceGrid, game.CurrentPlayer);

            foreach (var p in game.CurrentBoard.PieceGrid.Amazon1Points.Union(game.CurrentBoard.PieceGrid.Amazon2Points))
            {
                Console.WriteLine($"{analysisGraph.W:0.00},{analysisGraph.AmazonMobilityScores[p]:0.00}");
            }

            Random rnd = new Random();

            while (!game.IsComplete())
            {
                int randomMoveNum = rnd.Next(0, game.CurrentMoves.Count - 1);
                game.ApplyMove(game.CurrentMoves.ElementAt(randomMoveNum));

                analysisGraph.BuildAnalysis(game.CurrentBoard.PieceGrid, game.CurrentPlayer);

                foreach (var p in game.CurrentBoard.PieceGrid.Amazon1Points.Union(game.CurrentBoard.PieceGrid.Amazon2Points))
                {
                    Console.WriteLine($"{analysisGraph.W:0.00},{analysisGraph.AmazonMobilityScores[p]:0.00}");
                }
            }
        }
Beispiel #2
0
        public static void PlayOneHundredGames()
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();
            List <Game> games = new List <Game>();

            for (int i = 0; i < 100; i++)
            {
                Random rnd  = new Random();
                Game   game = new Game();
                game.Begin(null, null, 10);
                while (!game.IsComplete())
                {
                    int randomMoveNum = rnd.Next(0, game.CurrentMoves.Count - 1);
                    game.ApplyMove(game.CurrentMoves.ElementAt(randomMoveNum));
                }
                games.Add(game);
            }
            sw.Stop();

            Console.WriteLine($"Elapsed: {sw.Elapsed}");

            double player1Wins = games.Count(g => g.GetGameResult() == GameResult.Player1Won);
            double player2Wins = games.Count(g => g.GetGameResult() == GameResult.Player2Won);

            Console.WriteLine($"{player1Wins}/{player2Wins} = {player1Wins / player2Wins:0.00}");
        }
Beispiel #3
0
        static void PlayRandomGame()
        {
            Game game = new Game();

            game.Begin(null, null, 10);

            AnalysisGraph analysisGraph = new AnalysisGraph();

            analysisGraph.BuildAnalysis(game.CurrentBoard.PieceGrid, game.CurrentPlayer);

            AmazonConsoleRenderer.Render(game, analysisGraph);

            Random rnd = new Random();

            while (!game.IsComplete())
            {
                int randomMoveNum = rnd.Next(0, game.CurrentMoves.Count - 1);
                game.ApplyMove(game.CurrentMoves.ElementAt(randomMoveNum));

                analysisGraph.BuildAnalysis(game.CurrentBoard.PieceGrid, game.CurrentPlayer);

                AmazonConsoleRenderer.Render(game, analysisGraph);
            }
            Console.WriteLine(game.GetGameResult().ToString());
        }
Beispiel #4
0
        public static void PlayFourRandomMovesAhead()
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();

            AnalysisGraph analysisGraph          = new AnalysisGraph();
            List <(Game, IAnalysisResult)> games = new List <(Game, IAnalysisResult)>();

            for (int i = 0; i < 100; i++)
            {
                Random rnd  = new Random();
                Game   game = new Game();
                game.Begin(null, null, 10);
                int n = 4;
                while (n > 0 && !game.IsComplete())
                {
                    int randomMoveNum = rnd.Next(0, game.CurrentMoves.Count - 1);
                    game.ApplyMove(game.CurrentMoves.ElementAt(randomMoveNum));
                    n--;
                }

                games.Add((game, analysisGraph.Analyze(game.CurrentBoard)));
            }
            sw.Stop();

            Console.WriteLine($"Elapsed: {sw.Elapsed}");
        }
Beispiel #5
0
        static void PlayRandomVsOptimusDeepGame()
        {
            Game game = new Game();

            game.Begin(null, null, 10);

            AnalysisGraph analysisGraph = new AnalysisGraph();

            analysisGraph.BuildAnalysis(game.CurrentBoard.PieceGrid, game.CurrentPlayer);

            AmazonConsoleRenderer.Render(game, analysisGraph);
            OptimusDeep optimusDeep = new OptimusDeep(3, analysisGraph);

            optimusDeep.BeginNewGame(Owner.Player2, 10);

            Random rnd = new Random();

            while (!game.IsComplete())
            {
                int randomMoveNum = rnd.Next(0, game.CurrentMoves.Count - 1);
                game.ApplyMove(game.CurrentMoves.ElementAt(randomMoveNum));

                analysisGraph.BuildAnalysis(game.CurrentBoard.PieceGrid, game.CurrentPlayer);

                AmazonConsoleRenderer.Render(game, analysisGraph);

                if (game.IsComplete())
                {
                    continue;
                }

                var cancellationTokenSrc = new CancellationTokenSource();
                var bestMoveTask         = Task <Move> .Run(() => optimusDeep.PickBestMoveAsync(game.CurrentBoard, cancellationTokenSrc.Token));

                Task.Delay(1000).Wait();
                if (!bestMoveTask.IsCompleted)
                {
                    cancellationTokenSrc.Cancel();
                }
                Move bestMove = bestMoveTask.Result;
                game.ApplyMove(bestMove);

                analysisGraph.BuildAnalysis(game.CurrentBoard.PieceGrid, game.CurrentPlayer);
                AmazonConsoleRenderer.Render(game, analysisGraph);
            }
            Console.WriteLine(game.GetGameResult().ToString());
        }