public override ActionParameterInfo[] GetActionParametersInfo(IStateKey stateKey, IActionKey actionKey)
        {
            string[] parameterNames = {};
            var      stateData      = m_StateManager.GetStateData((StateEntityKey)stateKey, false);

            switch (((IActionKeyWithGuid)actionKey).ActionGuid)
            {
            case var actionGuid when actionGuid == ActionScheduler.CollectGuid:
                parameterNames = Collect.parameterNames;
                break;

            case var actionGuid when actionGuid == ActionScheduler.NavigateGuid:
                parameterNames = Navigate.parameterNames;
                break;
            }

            var parameterInfo = new ActionParameterInfo[parameterNames.Length];

            for (var i = 0; i < parameterNames.Length; i++)
            {
                var traitBasedObjectId = stateData.GetTraitBasedObjectId(((ActionKey)actionKey)[i]);

#if DEBUG
                parameterInfo[i] = new ActionParameterInfo {
                    ParameterName = parameterNames[i], TraitObjectName = traitBasedObjectId.Name.ToString(), TraitObjectId = traitBasedObjectId.Id
                };
#else
                parameterInfo[i] = new ActionParameterInfo {
                    ParameterName = parameterNames[i], TraitObjectName = traitBasedObjectId.ToString(), TraitObjectId = traitBasedObjectId.Id
                };
#endif
            }

            return(parameterInfo);
        }
        public void UpdateCurrentState(IStateKey stateKey)
        {
            if (!(stateKey is TStateKey newExecutorState))
            {
                throw new ArgumentException($"Expected state key of type {typeof(TStateKey)}. Received state key of type {stateKey?.GetType()}.");
            }

            // Don't destroy the current state if the same key/data are used
            if (!newExecutorState.Equals(CurrentExecutorState))
            {
                m_StateManager.DestroyState(CurrentExecutorState);
            }

            // If the user has passed in a plan state, use a copy instead (so we don't mutate plan states).
            // Fixme: when executor and plan states use separate worlds.
            var matchingPlanState = default(TStateKey);

            if (m_PlanWrapper != null && FindMatchingStateInPlan(newExecutorState, out matchingPlanState) && stateKey.Equals(matchingPlanState))
            {
                newExecutorState = m_StateManager.CopyState(newExecutorState); // Don't use plan states as executor states.
            }
            // Assign new state
            CurrentExecutorState = newExecutorState;
            CurrentPlanState     = matchingPlanState;

            // Check for terminal or unexpected state
            if (m_PlanWrapper != null)
            {
                CheckNewState();
            }
        }
        public override IActionParameterInfo[] GetActionParametersInfo(IStateKey stateKey, IActionKey actionKey)
        {
            string[] parameterNames = {};
            var      stateData      = m_StateManager.GetStateData((StateEntityKey)stateKey, false);

            switch (((IActionKeyWithGuid)actionKey).ActionGuid)
            {
            case var actionGuid when actionGuid == ActionScheduler.MoveDownGuid:
                parameterNames = MoveDown.parameterNames;
                break;

            case var actionGuid when actionGuid == ActionScheduler.MoveLeftGuid:
                parameterNames = MoveLeft.parameterNames;
                break;

            case var actionGuid when actionGuid == ActionScheduler.MoveRightGuid:
                parameterNames = MoveRight.parameterNames;
                break;

            case var actionGuid when actionGuid == ActionScheduler.MoveUpGuid:
                parameterNames = MoveUp.parameterNames;
                break;

            case var actionGuid when actionGuid == ActionScheduler.PickupKeyGuid:
                parameterNames = PickupKey.parameterNames;
                break;

            case var actionGuid when actionGuid == ActionScheduler.UseDoorLeftGuid:
                parameterNames = UseDoorLeft.parameterNames;
                break;

            case var actionGuid when actionGuid == ActionScheduler.UseDoorRightGuid:
                parameterNames = UseDoorRight.parameterNames;
                break;

            case var actionGuid when actionGuid == ActionScheduler.UseGateUpGuid:
                parameterNames = UseGateUp.parameterNames;
                break;
            }

            var parameterInfo = new IActionParameterInfo[parameterNames.Length];

            for (var i = 0; i < parameterNames.Length; i++)
            {
                var traitBasedObjectId = stateData.GetTraitBasedObjectId(((ActionKey)actionKey)[i]);

#if DEBUG
                parameterInfo[i] = new ActionParameterInfo {
                    ParameterName = parameterNames[i], TraitObjectName = traitBasedObjectId.Name.ToString(), TraitObjectId = traitBasedObjectId.Id
                };
#else
                parameterInfo[i] = new ActionParameterInfo {
                    ParameterName = parameterNames[i], TraitObjectName = traitBasedObjectId.ToString(), TraitObjectId = traitBasedObjectId.Id
                };
#endif
            }

            return(parameterInfo);
        }
Beispiel #4
0
        /// <inheritdoc cref="IPlan"/>
        public bool TryGetOptimalAction(IStateKey planStateKey, out IActionKey actionKey)
        {
            planData.CompletePlanningJobs();
            var found = planData.PlanGraph.TryGetOptimalAction(Convert(planStateKey), out var actionKeyTyped);

            actionKey = actionKeyTyped as IActionKey;
            return(found);
        }
Beispiel #5
0
        /// <inheritdoc cref="IPlan"/>
        public bool TryGetEquivalentPlanState(IStateKey stateKey, out IStateKey matchingPlanStateKey)
        {
            planData.CompletePlanningJobs();
            bool found = planData.FindMatchingStateInPlan(Convert(stateKey), out var matchingKey);

            matchingPlanStateKey = matchingKey as IStateKey;
            return(found);
        }
Beispiel #6
0
        TStateKey Convert(IStateKey stateKey)
        {
            if (stateKey is TStateKey converted)
            {
                return(converted);
            }

            throw new ArgumentException($"Expected state key of type {typeof(TStateKey)}. Received key of type {stateKey?.GetType()}.");
        }
Beispiel #7
0
        public ActorArrayState(IActorStateManager stateManager, IStateKey key, long length)
        {
            if (length < 1L)
            {
                throw new ArgumentException("Length must be non-zero", nameof(length));
            }

            _stateManager = stateManager ?? throw new ArgumentNullException(nameof(stateManager));
            Key           = key ?? throw new ArgumentNullException(nameof(key));
            Length        = length;
        }
Beispiel #8
0
        /// <inheritdoc cref="IPlan"/>
        public int GetActions(IStateKey planStateKey, IList <IActionKey> actionKeys)
        {
            planData.CompletePlanningJobs();
            actionKeys?.Clear();

            int count             = 0;
            var stateActionLookup = planData.PlanGraph.ActionLookup;

            if (stateActionLookup.TryGetFirstValue(Convert(planStateKey), out var actionKey, out var iterator))
            {
                do
                {
                    actionKeys?.Add(actionKey as IActionKey);
                    count++;
                } while (stateActionLookup.TryGetNextValue(out actionKey, ref iterator));
            }

            return(count);
        }
Beispiel #9
0
        /// <inheritdoc cref="IPlan"/>
        public int GetResultingStates(IStateKey planStateKey, IActionKey actionKey, IList <IStateKey> resultingPlanStateKeys)
        {
            planData.CompletePlanningJobs();
            resultingPlanStateKeys?.Clear();

            var count                = 0;
            var stateActionPair      = new StateActionPair <TStateKey, TActionKey>(Convert(planStateKey), Convert(actionKey));
            var resultingStateLookup = planData.PlanGraph.ResultingStateLookup;

            if (resultingStateLookup.TryGetFirstValue(stateActionPair, out var resultingState, out var iterator))
            {
                do
                {
                    resultingPlanStateKeys?.Add(resultingState as IStateKey);
                    count++;
                } while (resultingStateLookup.TryGetNextValue(out resultingState, ref iterator));
            }

            return(count);
        }
Beispiel #10
0
 /// <summary>
 /// Get an <see cref="IObjectState{T}"/> instance
 /// </summary>
 /// <typeparam name="TValue">Data type of state</typeparam>
 /// <param name="unit"><see cref="IUnit"/> to retrieve state for</param>
 /// <param name="key"><see cref="IStateKey"/> to get state object for</param>
 /// <returns><see cref="IObjectState{T}"/> of <typeparamref name="TValue"/></returns>
 public static IObjectState <TValue> GetObject <TValue>(this IUnit unit, IStateKey key)
 {
     return(unit.Get <IObjectState <TValue> >(key));
 }
Beispiel #11
0
 public ActorObjectState(IActorStateManager stateManager, IStateKey key)
 {
     _stateManager = stateManager ?? throw new ArgumentNullException(nameof(stateManager));
     Key           = key ?? throw new ArgumentNullException(nameof(key));
 }
 public bool Equals(IStateKey other) => other is StateEntityKey key && Equals(key);
Beispiel #13
0
 public StateNode(IPlanExecutor planExecutor, IStateKey stateKey, bool expansion = false, float weight = 1, bool active = false, bool rootState = false)
     : base(planExecutor, stateKey.Label, stateKey, expansion, weight, active)
 {
     m_RootState = rootState;
 }
Beispiel #14
0
 public ActorListState(IActorStateManager stateManager, IStateKey key)
     : base(stateManager, key)
 {
 }
Beispiel #15
0
 /// <inheritdoc cref="IPlan"/>
 public bool TryGetStateTransitionInfo(IStateKey originatingPlanStateKey, IActionKey actionKey, IStateKey resultingPlanStateKey, out StateTransitionInfo stateTransitionInfo)
 {
     return(TryGetStateTransitionInfo(Convert(originatingPlanStateKey), Convert(actionKey), Convert(resultingPlanStateKey), out stateTransitionInfo));
 }
Beispiel #16
0
 /// <summary>
 /// Get an <see cref="IArrayState{T}"/> instance
 /// </summary>
 /// <typeparam name="TValue">Data type of state</typeparam>
 /// <param name="unit"><see cref="IUnit"/> to retrieve state for</param>
 /// <param name="key"><see cref="IStateKey"/> to get state array for</param>
 /// <returns><see cref="IArrayState{T}"/> of <typeparamref name="TValue"/></returns>
 public static IArrayState <TValue> GetArray <TValue>(this IUnit unit, IStateKey key)
 {
     return(unit.Get <IArrayState <TValue> >(key));
 }
Beispiel #17
0
 /// <inheritdoc />
 public int CompareTo(IStateKey other)
 {
     return(CompareToCore(other as StateKey));
 }
Beispiel #18
0
 /// <summary>
 /// Get an <see cref="IStackState{T}"/> instance
 /// </summary>
 /// <typeparam name="TValue">Data type of state</typeparam>
 /// <param name="unit"><see cref="IUnit"/> to retrieve state for</param>
 /// <param name="key"><see cref="IStateKey"/> to get state stack for</param>
 /// <returns><see cref="IStackState{T}"/> of <typeparamref name="TValue"/></returns>
 public static IStackState <TValue> GetStack <TValue>(this IUnit unit, IStateKey key)
 {
     return(unit.Get <IStackState <TValue> >(key));
 }
Beispiel #19
0
 /// <inheritdoc cref="IPlan"/>
 public IStateData GetStateData(IStateKey stateKey)
 {
     return(GetStateData(Convert(stateKey)));
 }
Beispiel #20
0
 /// <inheritdoc cref="IPlan"/>
 public bool TryGetStateInfo(IStateKey planStateKey, out StateInfo stateInfo)
 {
     return(TryGetStateInfo(Convert(planStateKey), out stateInfo));
 }
Beispiel #21
0
 /// <inheritdoc cref="IPlan"/>
 public bool IsTerminal(IStateKey planStateKey)
 {
     return(IsTerminal(Convert(planStateKey)));
 }
Beispiel #22
0
 public TestLinkedCollectionState(IActorStateManager stateManager, IStateKey key)
     : base(stateManager, key)
 {
 }
Beispiel #23
0
 /// <inheritdoc cref="IPlan"/>
 public bool TryGetActionInfo(IStateKey planStateKey, IActionKey actionKey, out ActionInfo actionInfo)
 {
     return(TryGetActionInfo(Convert(planStateKey), Convert(actionKey), out actionInfo));
 }
Beispiel #24
0
 /// <summary>
 /// Get an <see cref="IListState{T}"/> instance
 /// </summary>
 /// <typeparam name="TValue">Data type of state</typeparam>
 /// <param name="unit"><see cref="IUnit"/> to retrieve state for</param>
 /// <param name="key"><see cref="IStateKey"/> to get state list for</param>
 /// <returns><see cref="IListState{T}"/> of <typeparamref name="TValue"/></returns>
 public static IListState <TValue> GetList <TValue>(this IUnit unit, IStateKey key)
 {
     return(unit.Get <IListState <TValue> >(key));
 }
Beispiel #25
0
 /// <summary>
 /// Get an <see cref="IDictionaryState{TKey, TValue}"/> instance
 /// </summary>
 /// <typeparam name="TKey">Data type of state key</typeparam>
 /// <typeparam name="TValue">Data type of state values</typeparam>
 /// <param name="unit"><see cref="IUnit"/> to retrieve state for</param>
 /// <param name="key"><see cref="IStateKey"/> to get state dictionary for</param>
 /// <returns><see cref="IDictionaryState{TKey, TValue}"/> of <typeparamref name="TKey"/> key and <typeparamref name="TValue"/> value</returns>
 public static IDictionaryState <TKey, TValue> GetDictionary <TKey, TValue>(this IUnit unit, IStateKey key)
     where TKey : IEquatable <TKey>, IComparable <TKey>
 {
     return(unit.Get <IDictionaryState <TKey, TValue> >(key));
 }
 public IStateData GetStateData(IStateKey stateKey, bool readWrite) => null;
Beispiel #27
0
 /// <summary>
 /// Get an <see cref="IQueueState{T}"/> instance
 /// </summary>
 /// <typeparam name="TValue">Data type of state</typeparam>
 /// <param name="unit"><see cref="IUnit"/> to retrieve state for</param>
 /// <param name="key"><see cref="IStateKey"/> to get state queue for</param>
 /// <returns><see cref="IQueueState{T}"/> of <typeparamref name="TValue"/></returns>
 public static IQueueState <TValue> GetQueue <TValue>(this IUnit unit, IStateKey key)
 {
     return(unit.Get <IQueueState <TValue> >(key));
 }
Beispiel #28
0
 public override ActionParameterInfo[] GetActionParametersInfo(IStateKey stateKey, IActionKey actionKey) => null;
Beispiel #29
0
 public ActorQueueState(IActorStateManager stateManager, IStateKey key)
     : base(stateManager, key)
 {
 }
Beispiel #30
0
 /// <inheritdoc />
 public bool Equals(IStateKey other)
 {
     return(EqualsCore(other as StateKey));
 }