Exemplo 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);
        }
Exemplo n.º 2
0
        protected TravelSearchState ToSearchState(TravelWorld newWorld)
        {
            var newState = new TravelSearchState();

            newState.CarryWatter     = CarryWater;
            newState.CurrentLocation = CurrentLocation;
            newState.WaterPlaces     = new List <int>(newWorld.GetWaterPlaces());
            newState.FireWays        = new List <TravelEdge>(newWorld.GetFireWays());
            newState.WorldGraph      = newWorld.GetGraph();
            return(newState);
        }
Exemplo n.º 3
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));
        }
Exemplo n.º 4
0
        protected IEnumerable <ActionType> getDriveActions(TravelSearchState state, TravelWorld world)
        {
            List <ActionType>        res = new List <ActionType>();
            IEnumerable <TravelEdge> ways;

            if (state.CarryWatter)
            {
                ways = world.GetWays(state.CurrentLocation);
            }
            else
            {
                ways = world.GetClearWays(state.CurrentLocation);
            }

            foreach (var way in ways)
            {
                int dest   = way.getAnotherPlace(state.CurrentLocation);
                var action = new ActionType(w => drive(w, dest));
                res.Add(action);
            }
            return(res);
        }
Exemplo n.º 5
0
 protected bool CanPickupWaterNow(ref TravelSearchState state, TravelWorld world)
 {
     return(!state.CarryWatter && world.HaveWater(state.CurrentLocation));
 }
Exemplo n.º 6
0
 protected SearchStateAndCost PickupWater(TravelSearchState state)
 {
     return(rollBackAction(state, pickupWater));
 }