Example #1
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());
        }
Example #2
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());
        }