Example #1
0
        public static int GetBestMove(int player, int alpha, int deep, Game game)
        {
            if (deep > MAX_DEEP || game.ComputerScore + game.PlayerScore == Game.SIZE * Game.SIZE)
            {
                //игра или глубина окончена, считаем оценку
                return game.ComputeRating();
            }
            List<int[]> possibleMoves = game.GetPossibleMoves(player);

            //если у компьютера нет ходов, то все плохо
            if (possibleMoves.Count == 0 && player == COMPUTER)
                return -Int32.MaxValue;

            int maxRating = -Int32.MaxValue;
            foreach (int[] move in possibleMoves)
            {
                //выполняем отсечение
                if (AlphaBeta(alpha, maxRating, deep))
                {
                    return alpha;
                }
                //создаем копию игры и делаем ход
                Game extraGame = game.Copy();
                extraGame.MakeMove(move[1], move[0], player, true);

                //вычисляем оценку после этого хода, меняя игрока
                int result = GetBestMove(-player, alpha, deep + 1, extraGame);

                //вычисляем новую оценку
                maxRating = MinMax(result, maxRating, deep);
            }
            return maxRating;
        }
 private void StartGame()
 {
     game = new Game();
     if (IsSingleGame)
     {
         TittleText.Text = "Single Game";
         FirstPlayer.Text = "Computer";
         SecondPlayer.Text = "Player";
     }
     else
     {
         TittleText.Text = "Multiplayer";
         FirstPlayer.Text = "Player 1";
         SecondPlayer.Text = "Player 2";
     }
     PaintGameField();
 }
Example #3
0
        //создает копию доски
        public Game Copy()
        {
            //копируем матрицу
            Game extraBoard = new Game();
            for (int column = 0; column < SIZE; column++)
            {
                for (int row = 0; row < SIZE; row++)
                {
                    extraBoard.field[column, row] = field[column, row];
                }
            }

            //копируем очки
            extraBoard.computerScore = this.ComputerScore;
            extraBoard.playerScore = this.PlayerScore;
            return extraBoard;
        }