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); }
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); }
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)); }
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); }
protected bool CanPickupWaterNow(ref TravelSearchState state, TravelWorld world) { return(!state.CarryWatter && world.HaveWater(state.CurrentLocation)); }
protected SearchStateAndCost PickupWater(TravelSearchState state) { return(rollBackAction(state, pickupWater)); }