Esempio n. 1
0
        static void Main(string[] args)
        {
            var board = new ReversiBoard();

            board.PrintBoard();
            while (!board.HasGameFinished())
            {
                Console.WriteLine("White, Play one of moves:");
                var whiteMoves = board.GetAvailableMoves(Player.White);
                if (whiteMoves.Any())
                {
                    foreach (var whiteMove in whiteMoves)
                    {
                        Console.WriteLine($"{whiteMove.Item1} {whiteMove.Item2}");
                    }
                    int row    = int.Parse(Console.ReadLine());
                    int column = int.Parse(Console.ReadLine());
                    board.PlayMove(row, column, Player.White);
                    board.PrintBoard();
                }

                var blackMove = MiniMax.GetBlackBestMove(board);
                if (blackMove != null)
                {
                    var blackMoves = board.GetAvailableMoves(Player.Black);
                    Console.WriteLine("Possible black moves:");
                    foreach (var bm in blackMoves)
                    {
                        Console.WriteLine($"{bm.Item1} {bm.Item2}");
                    }
                    Console.WriteLine($"Black played {blackMove.Item1} {blackMove.Item2}");
                    board.PlayMove(blackMove.Item1, blackMove.Item2, Player.Black);
                    board.PrintBoard();
                }
            }

            Console.WriteLine($"GAME ENDED: {board.EvaluateScore()}");
        }
Esempio n. 2
0
        private static int MinPlay(ReversiBoard board, int depth)
        {
            if (board.HasGameFinished() || depth == MaxDepthPerMove)
            {
                return(board.EvaluateScore());
            }

            var availableMoves = board.GetAvailableMoves(Player.White);
            var bestScore      = int.MaxValue;

            foreach (var availableMove in availableMoves)
            {
                var boardCopy = board.Clone();
                boardCopy.PlayMove(availableMove.Item1, availableMove.Item2, Player.White);
                var score = MaxPlay(boardCopy, depth + 1);
                if (score < bestScore)
                {
                    bestScore = score;
                }
            }

            return(bestScore);
        }