Exemple #1
0
        private bool PlayerCantMakeMove()
        {
            var moveLogic = new PlayerMoveLogic(_game);
            var moves     = moveLogic.GetValidPlayerMoves(_game, _game.CurrentPlayer);

            if (moves.Count == 0)
            {
                _winner = _game.LastMove.To.Player;
                return(true);
            }
            return(false);
        }
Exemple #2
0
        private int GetMoveScore(GameState state, Move move, bool isMin, int depth, int alpha, int beta)
        {
            if (depth == 0)
            {
                return(0);
            }
            var moveLogic = new PlayerMoveLogic(state);

            moveLogic.MakeMove(move);

            var stateDeterminator = new GameStateDeterminator(state);

            if (stateDeterminator.IsTerminalState())
            {
                return(GetWinnerScore(stateDeterminator.Winner));
            }

            var moves     = moveLogic.GetValidPlayerMoves(state, state.CurrentPlayer);
            var bestScore = isMin ? int.MaxValue : int.MinValue;

            foreach (var curMove in moves)
            {
                var score = GetMoveScore(state.Copy(), curMove, !isMin, depth - 1, alpha, beta);
                if (isMin && score < bestScore || !isMin && score > bestScore)
                {
                    bestScore = score;
                }

                if (isMin)
                {
                    beta = Math.Min(beta, score);
                }
                else
                {
                    alpha = Math.Max(alpha, score);
                }
                if (alpha > beta)
                {
                    break;
                }
            }
            return(bestScore);
        }
Exemple #3
0
 public AlfaBetaAlgorithm(GameState state)
 {
     _state     = state;
     _moveLogic = new PlayerMoveLogic();
     _baseDepth = (int)_state.AILevel;
 }