Exemple #1
0
 internal bool ProcessEvent(Node parentNode, ISuccessor successor)
 {
     var state = parentNode.State as IAdversarialState;
     var args = new StateExpansionEventArgs(state, successor, parentNode.Cost, parentNode.Depth);
     OnSuccessorExpanded(this, args);
     return !args.CancelExpansion;
 }
Exemple #2
0
        public virtual bool Find(IState initialState)
        {
            if (Strategy == null) return false;

            Strategy.Add(new Node(initialState));
            while (Strategy.Count() > 0)
            {
                var n = Strategy.Remove();
                if (n.Parent != null && n.Successor != null)
                {
                    var eventArgs = new StateExpansionEventArgs(n.Parent.State, n.Successor, n.Cost, n.Depth);
                    OnSuccessorExpanded(this, eventArgs);

                    if (eventArgs.CancelExpansion)
                        return false;
                }

                if (n.State.IsTerminal)
                {
                    CreateSolution(n);
                    return true;
                }

                foreach (var node in n.Expand(_closed))
                {
                    Strategy.Add(node);
                    if (_closed != null) _closed.Add(node.State);
                }

            }

            return false;
        }
Exemple #3
0
        internal bool ProcessEvent(Node parentNode, ISuccessor successor)
        {
            var state = parentNode.State as IAdversarialState;
            var args  = new StateExpansionEventArgs(state, successor, parentNode.Cost, parentNode.Depth);

            OnSuccessorExpanded(this, args);
            return(!args.CancelExpansion);
        }
Exemple #4
0
        protected virtual void OnSuccessorExpanded(object sender, StateExpansionEventArgs e)
        {
            EventHandler <StateExpansionEventArgs> handler = SuccessorExpanded;

            if (handler != null)
            {
                handler(sender, e);
            }
        }
Exemple #5
0
        public virtual bool Find(IState initialState)
        {
            if (Strategy == null)
            {
                return(false);
            }

            Strategy.Add(new Node(initialState));
            while (Strategy.Count() > 0)
            {
                var n = Strategy.Remove();
                if (n.Parent != null && n.Successor != null)
                {
                    var eventArgs = new StateExpansionEventArgs(n.Parent.State, n.Successor, n.Cost, n.Depth);
                    OnSuccessorExpanded(this, eventArgs);

                    if (eventArgs.CancelExpansion)
                    {
                        return(false);
                    }
                }

                if (n.State.IsTerminal)
                {
                    CreateSolution(n);
                    return(true);
                }

                foreach (var node in n.Expand(_closed))
                {
                    Strategy.Add(node);
                    if (_closed != null)
                    {
                        _closed.Add(node.State);
                    }
                }
            }

            return(false);
        }
Exemple #6
0
 protected virtual void OnSuccessorExpanded(object sender, StateExpansionEventArgs e)
 {
     EventHandler<StateExpansionEventArgs> handler = SuccessorExpanded;
     if (handler != null)
         handler(sender, e);
 }