Exemplo n.º 1
0
 public void TestPlaying()
 {
     var empty = new[]
     {
         Played.Empty, Played.Empty, Played.Empty,
         Played.Empty, Played.Empty, Played.Empty,
         Played.Empty, Played.Empty, Played.Empty,
     };
     var board = new[]
     {
         empty, empty, empty,
         empty, empty, empty,
         empty, empty, empty,
     };
     var gameState = new GameState(null, Player.Self, board, null !, empty);
     var state     = NegaMaxAlgo.NextPlay(gameState, 1);
 }
Exemplo n.º 2
0
        private static void Main(string[] args)
        {
            string[] inputs;

            GameState gameState = null;
            var       firstMove = true;

            // game loop
            while (true)
            {
                inputs = Console.ReadLine()?.Split(' ');
                var opponentRow      = int.Parse(inputs[0]);
                var opponentCol      = int.Parse(inputs[1]);
                var validActionCount = int.Parse(Console.ReadLine());
                for (int i = 0; i < validActionCount; i++)
                {
                    inputs = Console.ReadLine()?.Split(' ');
                    var row = int.Parse(inputs[0]);
                    var col = int.Parse(inputs[1]);
                }

                // Write an action using Console.WriteLine()
                // To debug: Console.Error.WriteLine("Debug messages...");

                if (firstMove)
                {
                    var empty = new[]
                    {
                        Played.Empty, Played.Empty, Played.Empty,
                        Played.Empty, Played.Empty, Played.Empty,
                        Played.Empty, Played.Empty, Played.Empty,
                    };
                    var board = new[]
                    {
                        empty, empty, empty,
                        empty, empty, empty,
                        empty, empty, empty,
                    };


                    if (opponentRow == -1 && opponentCol == -1)
                    {
                        gameState = new GameState(null !, Player.Self, board, null !, empty);
                    }
                    else
                    {
                        gameState = new GameState(null !, Player.Opponent, board, null !, empty);
                        gameState = gameState.Move(Coordinate.FromCoordinate(opponentRow, opponentCol));
                    }

                    firstMove = false;
                }
                else
                {
                    gameState = gameState.Move(Coordinate.FromCoordinate(opponentRow, opponentCol));
                }

                var stopWatch = new Stopwatch();
                stopWatch.Start();
                gameState = NegaMaxAlgo.NextPlay(gameState, 3);
                if (gameState.LastPlayed == null)
                {
                    throw new Exception("Last Played cannot be null");
                }
                var played = gameState.LastPlayedCoordinate();
                stopWatch.Stop();

                Console.Error.WriteLine($"Heuristic Time {Monitoring.HeuristicTime}");
                Console.Error.WriteLine($"Generation time {Monitoring.ChildrenGenerationTime}");
                Console.Error.WriteLine($"Allocation time {Monitoring.AllocationTime}");
                Console.Error.WriteLine($"Children {Monitoring.Children}");
                Console.Error.WriteLine($"ComputeBoardResultTime {Monitoring.ComputeBoardResultTime}");
                Console.Error.WriteLine($"Total time {stopWatch.Elapsed.TotalSeconds}");
                Console.Error.WriteLine($"Score {gameState.Score}");
                Console.WriteLine($"{played.Item1} {played.Item2}");
            }
        }