Example #1
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());
 }
Example #2
0
        public int PickMove(List <Move> moves, ReadOnlyBlockadeState state)
        {
            var okayMoves = moves.Select((m, i) =>
            {
                var nextState = state.MakeMove(m);
                return(nextState.GetBoardCalculator()
                       .GetD1Neighbors(m.Location, distance: 1)
                       .Where(l => nextState.GetCell(l).IsEmpty())
                       .Any()
                                                ? i
                                                : default(int?));
            })
                            .Where(i => i.HasValue)
                            .Select(i => i.Value)
                            .ToList();

            return(okayMoves.Count > 0
                                ? okayMoves[this._random.Next(okayMoves.Count)]
                                : 0);
        }
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());
        }