Example #1
0
 public double EvaluateState(ReadOnlyBlockadeState state, int player, IBlockadeHeuristic blockadeHeuristic)
 {
     return(state.IsGameOver()
                         ? (state.CurrentPlayer == player
                                 ? blockadeHeuristic.WinScore
                                 : blockadeHeuristic.LossScore)
                         : blockadeHeuristic.EvaluateState(state, player));
 }
Example #2
0
        public double TryAllOtherPlayerMoves(ReadOnlyBlockadeState state, IBlockadeHeuristic heuristic, int levels, int myselfPlayer)
        {
            if (state.IsGameOver())
            {
                return(state.CurrentPlayer == myselfPlayer
                                        ? heuristic.WinScore
                                        : heuristic.LossScore);
            }

            if (state.CurrentPlayer == myselfPlayer)
            {
                return(this.PickBestMove(state.GetMoves().ToList(), state, heuristic, levels - 1).Item2);
            }

            return(state.GetMoves()
                   .Select(state.MakeMove)
                   .Select(newState => newState.GetCurrentLocationOfPlayer(myselfPlayer) == null
                                        ? heuristic.LossScore
                                        : newState.CurrentPlayer == myselfPlayer
                                                ? this.PickBestMove(newState.GetMoves().ToList(), newState, heuristic, levels - 1).Item2
                                                : this.TryAllOtherPlayerMoves(newState, heuristic, levels, myselfPlayer))
                   .Average());
        }
Example #3
0
        public Tuple <int, double> PickBestMove(List <Move> moves, ReadOnlyBlockadeState state, IBlockadeHeuristic heuristic, int levels)
        {
            if (levels == 0)
            {
                var singleLevelResult = this._singleLevelMoveEvaluator.PickBestMove(moves, state, heuristic);
                return(singleLevelResult != null
                                        ? singleLevelResult
                                        : Tuple.Create(0, heuristic.LossScore));
            }

            return(moves.Select((m, i) => Tuple.Create(i, this.TryAllOtherPlayerMoves(state.MakeMove(m), heuristic, levels, state.CurrentPlayer)))
                   .OrderByDescending(t => Tuple.Create(t.Item2, this._random.Next()))
                   .First());
        }
Example #4
0
 public Tuple <int, double> PickBestMove(List <Move> moves, ReadOnlyBlockadeState state, IBlockadeHeuristic blockadeHeuristic)
 {
     return(moves.Select((move, i) => new { nextState = state.MakeMove(move), move, i })
            .Where(a => a.nextState.GetBoardCalculator().GetD1Neighbors(a.move.Location, distance: 1)
                   .Where(l => a.nextState.GetCell(l).IsEmpty())
                   .Any())
            .Select(a => Tuple.Create(this.EvaluateState(a.nextState, state.CurrentPlayer, blockadeHeuristic), a.i))
            .OrderByDescending(t => t)
            .Select(t => Tuple.Create(t.Item2, t.Item1))
            .FirstOrDefault());
 }