Esempio n. 1
0
        protected virtual StateActionsCollection getActions(TravelSearchState state)
        {
            //basic :only pickup water and drive
            TravelWorld            world = state.ToWorld();
            StateActionsCollection res   = new StateActionsCollection();

            if (CanPickupWaterNow(ref state, world))
            {
                if (!_actionsMap.ContainsKey(PickupWater))
                {
                    ActionType      action      = pickupWater;
                    StateActionType stateAction = PickupWater;
                    _actionsMap.Add(stateAction, action);
                }
                res.Add(PickupWater);
            }

            var actions = getDriveActions(state, world);

            foreach (var action in actions)
            {
                var stateAction = ConvertToStateAction(action);
                _actionsMap.Add(stateAction, action);
                res.Add(stateAction);
            }
            return(res);
        }
Esempio n. 2
0
        public override ActionType GetNextAction(TravelWorld world)
        {
            var actions = getActions(world);

            if (actions == null || actions.Count() == 0)
            {
                return(noOpertion);
            }

            //there is not point to evealute the huristic function
            if (actions.Count() == 1)
            {
                return(_actionsMap[actions.First()]);
            }

            var             searchState  = ToSearchState(world);
            double          min          = double.MaxValue;
            StateActionType chosenAction = null;

            foreach (var action in actions)
            {
                var cost = _heuristic(action(searchState).State);
                if (cost < min)
                {
                    min          = cost;
                    chosenAction = action;
                }
            }

            return(_actionsMap[chosenAction]);
        }
Esempio n. 3
0
        private void InitActions(Entity owner, List <StateAction> actions, StateActionType type)
        {
            int count = actions.Count;

            for (int i = 0; i < count; i++)
            {
                BaseStateAction newAction = actions[i].CreateActionClass(owner);
                PopualteActions(newAction, type);
            }
        }
Esempio n. 4
0
        public virtual StateActionsCollection getActions(TravelGameState state)
        {
            //TODO:edit
            //only pickup water and drive
            TravelWorld            world = state.ToWorld();
            StateActionsCollection res   = new StateActionsCollection();

            if (CanPickupWaterNow(state, world))
            {
                if (!_actionsMap.ContainsKey(PickupWater))
                {
                    ActionType      action      = pickupWater;
                    StateActionType stateAction = PickupWater;
                    _actionsMap.Add(stateAction, action);
                }
                res.Add(PickupWater);
            }

            var actions = getDriveActions(state, world);

            foreach (var action in actions)
            {
                var stateAction = ConvertToStateAction(action);
                _actionsMap.Add(stateAction, action);
                res.Add(stateAction);
            }

            actions = getFireActions(state, world);
            foreach (var action in actions)
            {
                var stateAction = ConvertToStateAction(action);
                _actionsMap.Add(stateAction, action);
                res.Add(stateAction);
            }

            //last because is last prefable
            if (!_actionsMap.ContainsKey(noOperation))
            {
                ActionType      action      = noOpertion;
                StateActionType stateAction = noOperation;
                _actionsMap.Add(stateAction, action);
            }
            res.Add(noOperation);
            return(res);
        }
Esempio n. 5
0
        private void PopualteActions(BaseStateAction action, StateActionType type)
        {
            switch (type)
            {
            case StateActionType.Enter:
                _OnEnterActions.Add(action);
                break;

            case StateActionType.Exit:
                _OnExitActions.Add(action);
                break;

            case StateActionType.Update:
                _OnUpdateActions.Add(action);
                break;

            case StateActionType.Fixed:
                _OnFixedUpdateActions.Add(action);
                break;
            }
        }
Esempio n. 6
0
        protected StateActionType ConvertToStateAction(ActionType action)
        {
            var stateAction = new StateActionType(state1 => rollBackAction(state1, action));

            return(stateAction);
        }