Example #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);
        }
Example #2
0
        private SearchStateAndCost rollBackAction(TravelSearchState state, ActionType action)
        {
            backup();
            CurrentLocation = state.CurrentLocation;
            CarryWater      = state.CarryWatter;
            var  newWorld = state.ToWorld();
            bool sucseed  = action(newWorld);

            if (!sucseed)
            {
                throw new WrongActionException();
            }
            var    neweState = ToSearchState(newWorld);
            double cost      = _cost - _prevCost;

            rollBack();
            return(new SearchStateAndCost(neweState, cost));
        }