public IEnumerable<Tuple<int, int>> UpperIsTarget(IFieldsGraph fieldsGraph)
        {
            var coord = fieldsGraph.GetWhiteFieldCoords();

            return _allUpper.SelectMany(MultiplyByRadius)
                .Select(r=> coord.Add(r));
        }
示例#2
0
 public FieldJumpIterator(Field start, IFieldsGraph fieldsGraph, StoneMover stoneMover)
 {
     _start = start;
     Current = _start;
     _fieldsGraph = fieldsGraph;
     _stoneMover = stoneMover;
 }
        public void should_generate_moves_properly()
        {
            _fieldsGraph = new TestFieldsGraph(
                new[]
                    {
                        new[] {Empty, Empty, Empty, Empty, Empty},
                        new[] {Empty, Empty, Empty, Empty, Empty},
                        new[] {Empty, Empty, Black, Empty, Empty},
                        new[] {Empty, Empty, Black, Empty, Empty},
                        new[] {Empty, Empty, Empty, Empty, Empty},
                        new[] {Empty, Empty, Black, Empty, Empty},
                        new[] {Empty, Empty, White, Empty, Empty},
                        new[] {Empty, Empty, Empty, Empty, Empty},
                        new[] {Empty, Empty, Empty, Empty, Empty},
                        new[] {Empty, Empty, Empty, Empty, Empty},
                    }
                ).Build();

            var current = new RootedBySelectingWhiteFieldBoardJumpTree(_fieldsGraph);
            var currentMoves =
                current.TraverseDfs(
                    new PerformMovesNodeVisitor(PerformMoves.DontCareAboutPlayerStateChange(_fieldsGraph)))
                    .Skip(1).ToList();

            currentMoves.ShouldHaveCount(2);
        }
        public PhutballMoveScore Search(IFieldsGraph fieldsGraph)
        {
            if(_alphaBetaSearchDepth.SearchDepth == 0)
            {
                return PhutballMoveScore.Empty();
            }
            var actualGraph = (IFieldsGraph)fieldsGraph.Clone();
            var performMoves = new PerformMoves(actualGraph, _playersState);
            var visitedNodes = new VisitedNodesCounter<JumpNode>();
            _alphaBetaSearch = new AlphaBetaSearch<JumpNode>(
                new WhiteStoneToCurrentPlayerBorderDistance(_playersState, actualGraph, _alphaBetaSearchDepth.DistanceToBorderWeight)
                .Add(new BlackStoneToTargetBorderCount(_playersState, actualGraph, _alphaBetaSearchDepth.BlackStonesToBorderWeight))
                ,
                _alphaBetaSearchDepth,
                new PerformMovesNodeVisitor(performMoves).FollowedBy(visitedNodes)
            );

            var movesTree = _movesFactory(actualGraph);
            _alphaBetaSearch.Run(movesTree);
            var result = new CompositeMove();
            _alphaBetaSearch.BestMove.Move.MovesFromRoot.CollectToPlayerSwitch(result);
            return new PhutballMoveScore(result, _alphaBetaSearch.BestMove.Score)
                       {
                           CuttoffsCount = _alphaBetaSearch.CuttoffsCount,
                           VisitedNodesCount = visitedNodes.Count
                       };
        }
示例#5
0
 public StoneJumper(IFieldsGraph fieldsGraph, Field from, Field to)
 {
     _fieldsGraph = fieldsGraph;
     _from = from;
     _to = to;
     _jumpersFactory= new JumpersFactory(_fieldsGraph);
 }
        public PhutballMoveScore Search(IFieldsGraph fieldsGraph)
        {
            var graphCopy = (IFieldsGraph)fieldsGraph.Clone();
            var tree = _movesFactory.GetMovesTree(graphCopy);
            var targetBorder = _playersState.CurrentPlayer.GetTargetBorder(fieldsGraph);

            var cuttoffVisitor = new CuttoffPickBestValueNodeVisitor(targetBorder, graphCopy, _playersState)
                                     {
                                         CuttoffToTargetBorder = CuttoffToTarget
                                     };
            var performMoves = cuttoffVisitor.MovesPerformer;
            var depthCounter = new DepthCounterNodeVisitor<JumpNode>();
            var stopOnMaxNodesVisited = new StopOnVisitedNodesCount<JumpNode>(MaxVisitedNodes);
            var searchNodeVisitor = stopOnMaxNodesVisited
                .FollowedBy(cuttoffVisitor)
                .FollowedBy(depthCounter)
                .FollowedBy(_defaultNodeVistor);
            var search = _searchFactory(searchNodeVisitor, performMoves, targetBorder);
            search.Run(tree);
            return new PhutballMoveScore(cuttoffVisitor.PickBestValue.ResultMove, cuttoffVisitor.PickBestValue.CurrentMaxValue)
                       {
                           VisitedNodesCount = stopOnMaxNodesVisited.VistedNodesCount,
                           MaxDepth = depthCounter.MaxDepth,
                           CuttoffsCount = cuttoffVisitor.CuttoffsCount
                       };
        }
 public IEnumerable<Tuple<int, int>> UpperIsTarget(IFieldsGraph fieldsGraph)
 {
     return Direction.AllUpper.Take(5).Shuffle().Select(dir => _firstPosition.Add(dir))
         .Concat(new[]{_firstPosition})
         .Concat(_whiteCoords)
         .Concat(Direction.AllUpper.Take(3).SelectMany(
             dir => _whiteCoords.Select(coord => coord.Add(dir))));
 }
示例#8
0
 public BestMoveApplier(IMoveFinders moveFinders,  MovesHistory movesHistory, IFieldsGraph fieldsGraph, IPerformMoves performMoves, IEventPublisher eventPublisher)
 {
     _moveFinders = moveFinders;
     _eventPublisher = eventPublisher;
     _performMoves = performMoves;
     _movesHistory = movesHistory;
     _fieldsGraph = fieldsGraph;
 }
示例#9
0
 public PhutballMoveScore Search(IFieldsGraph fieldsGraph)
 {
     var result = _realStrategy.Search(fieldsGraph);
     if(result == null || result.Move == null)
     {
         return PhutballMoveScore.Empty();
     }
     return result.FollowedBy(new DeselectWhiteFieldIfSelectedMove());
 }
示例#10
0
 public PhutballBoard(
     IPlayersState playerState,
     IFieldsGraph fieldsGraph,
     IEventPublisher eventPublisher,
     IPhutballOptions options)
     : base(fieldsGraph, options)
 {
     _playerState = playerState;
     _eventPublisher = eventPublisher;
 }
 public int GetValue(IFieldsGraph valueSubject)
 {
     var whiteField = valueSubject.GetWhiteField();
     var rawDistance = _winingBorder.GetDistanceFrom(whiteField);
     if(rawDistance == 0)
     {
         return _winingBorder.WinValue;
     }
     var distanceBetweenBorders = DistanceBetweenBorders();
     if(rawDistance >= distanceBetweenBorders)
     {
         return _winingBorder.LooseValue;
     }
     return distanceBetweenBorders - rawDistance;
 }
示例#12
0
        public TargetBorderEnum(IFieldsGraph fieldsGraph)
        {
            Upper = new TargetBorder(() => 1, UpperName)
                .OppositeIs(() => Bottom)
                .CountDistanceUsing(new DistanceToUpperBorderCounter(fieldsGraph))
                .ComparePositionsUsing((left,right)=> left < right)
                .EndRowIndexIs(me=> 1)
                .WiningIndexes((me)=> new[]{0,1});

            Bottom = new TargetBorder(() => fieldsGraph.RowCount - 2, Bottomname)
                .OppositeIs(() => Upper)
                .CountDistanceUsing(new DistanceToBottomBorderCounter(fieldsGraph))
                .EndRowIndexIs((me)=> me.RowIndex )
                .ComparePositionsUsing((left, right) => left > right)
                .WiningIndexes((me)=> new[]{me.RowIndex, me.RowIndex + 1});
        }
 public PhutballMoveScore Search(IFieldsGraph fieldsGraph)
 {
     var graphCopy = (IFieldsGraph)fieldsGraph.Clone();
     var tree = _movesFactory.GetMovesTree(graphCopy);
     var targetBorder = _playersState.CurrentPlayer.GetTargetBorder(fieldsGraph);
     var performMoves = new PerformMoves(graphCopy, _playersState);
     var bestValuePicker = new PickBestValueNodeVisitor(targetBorder, graphCopy, performMoves);
     var nodeCounter = new VisitedNodesCounter<JumpNode>();
     var depthCounter = new DepthCounterNodeVisitor<JumpNode>();
     var searchNodeVisitor = _defaultNodeVistor.FollowedBy(bestValuePicker).FollowedBy(nodeCounter).FollowedBy(depthCounter);
     var search = _searchFactory(searchNodeVisitor, performMoves, targetBorder);
     search.Run(tree);
     return new PhutballMoveScore( bestValuePicker.ResultMove, bestValuePicker.CurrentMaxValue)
                {
                    VisitedNodesCount = nodeCounter.Count,
                    MaxDepth = depthCounter.MaxDepth
                };
 }
 public IEnumerable<Tuple<int, int>> UpperIsTarget(IFieldsGraph fieldsGraph)
 {
     return _first.UpperIsTarget(fieldsGraph).Concat(_right.UpperIsTarget(fieldsGraph));
 }
示例#15
0
 public TargetBorder GetTargetBorder(IFieldsGraph fieldsGraph)
 {
     return _targetBorderAccessor(fieldsGraph);
 }
 public PhutballMoveScore Search(IFieldsGraph fieldsGraph)
 {
     return _bruteForceSearch.Search(fieldsGraph);
 }
示例#17
0
 public FieldJump(IFieldsGraph fieldsGraph, Field from, Tuple<int, int> delta)
 {
     _fieldsGraph = fieldsGraph;
     _from = from;
     _delta = delta;
 }
示例#18
0
 public JumpNode(IFieldsGraph sourceGraph, IPhutballMove moveToApply)
 {
     ActualGraph = sourceGraph;
     LastMove = moveToApply;
     MovesFromRoot = new EmptyPhutballMove();
 }
示例#19
0
 public static JumpNode Empty(IFieldsGraph graph)
 {
     return new JumpNode(graph, new EmptyPhutballMove());
 }
示例#20
0
 public RootedBySelectingWhiteFieldBoardJumpTree GetMovesTree(IFieldsGraph graphCopy)
 {
     return new RootedBySelectingWhiteFieldBoardJumpTree(graphCopy);
 }
 public DistanceToBottomBorderCounter(IFieldsGraph fieldsGraph)
 {
     _fieldsGraph = fieldsGraph;
 }
 public PlayerBlackStonePlacer(IFieldsGraph fieldsGraph, IPlayersState playersState)
 {
     _fieldsGraph = fieldsGraph;
     _playersState = playersState;
 }
示例#23
0
 public JumpersFactory(IFieldsGraph fieldsGraph)
 {
     _fieldsGraph = fieldsGraph;
 }
 public ReadOnlyPhutballBoard(IFieldsGraph fieldsGraph, IPhutballOptions options)
 {
     _fieldsGraph = fieldsGraph;
     _options = options;
 }