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
                       };
        }
Exemple #2
0
        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 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
                       };
        }
Exemple #4
0
        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
            });
        }
 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
                };
 }
Exemple #6
0
        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
            });
        }