Ejemplo n.º 1
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
                       };
        }