Esempio n. 1
0
        public static int AiScoreCalc(Board gameBoard, Pos pos, char player)
        {
            var score = 0;

            if (gameBoard.GetPiece(pos) != ' ')
            {
                return(score);
            }

            var otherPlayer = ReversiRules.GetOtherPlayer(player);

            for (var y = pos.Y - 1; y <= pos.Y + 1; y++)
            {
                for (var x = pos.X - 1; x <= pos.X + 1; x++)
                {
                    if (!gameBoard.IsInsideBoard(x, y))
                    {
                        continue;
                    }

                    if (gameBoard.GetPiece(x, y) != otherPlayer)
                    {
                        continue;
                    }

                    if (ReversiRules.TraceMove(gameBoard, pos, x - pos.X, y - pos.Y, player))
                    {
                        score += AiTraceMove(gameBoard, pos, x - pos.X, y - pos.Y, player);
                    }
                }
            }

            return(score);
        }
Esempio n. 2
0
        public static Pos ReadInput(Config config, Board gameBoard, char currentPlayer)
        {
            if (IsAiPlayerTurn(config, currentPlayer))
            {
                var move = AiWithScoreTable.GetAiMove(gameBoard, currentPlayer);
                Console.WriteLine(move);
                return(move);
            }
            else
            {
                var input = ReadInput();
                var move  = ParseMove(input);
                while (!ReversiRules.IsValidMove(gameBoard, move, currentPlayer))
                {
                    Console.WriteLine("You can't place a piece there!\n");

                    Console.Write(currentPlayer == Constants.Black
                        ? "BLACK, make your move: "
                        : "WHITE, make your move: ");

                    input = ReadInput();
                    move  = ParseMove(input);
                }

                return(move);
            }
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            var config  = ConfigHandler.ReadCommandLineArgumants(args);
            var reversi = new ReversiRules(config);

            reversi.RunGameLoop();

            Console.ReadKey();
        }
Esempio n. 4
0
        public static int[] EvaluateScores(Board gameBoard, char currentPlayer)
        {
            var testBoard = ReversiRules.HintPlayer(gameBoard, currentPlayer);

            var scoreBoard = ApplyCaptureScores(gameBoard, testBoard, currentPlayer);

            // Add score for hotspots like corners and edges
            var scoreTable = AiScoreTable(gameBoard);

            for (var y = 0; y < gameBoard.Height; y++)
            {
                for (var x = 0; x < gameBoard.Width; x++)
                {
                    var currentPos = y * gameBoard.Width + x;
                    if (scoreBoard[currentPos] > 0)
                    {
                        scoreBoard[currentPos] += scoreTable[currentPos];
                    }
                }
            }

            return(scoreBoard);
        }