Exemple #1
0
 /**
  * Constructor which allows subclasses to define a vacuum environment with an arbitrary number
  * of squares. Two-dimensional grid environments can be defined by additionally overriding
  * {@link #getXDimension()} and {@link #getYDimension()}.
  */
 protected VacuumEnvironment(ICollection <string> locations, params LocationState[] locStates)
 {
     this.locations = locations;
     envState       = new VacuumEnvironmentState();
     for (int i = 0; i < locations.Size() && i < locStates.Length; ++i)
     {
         envState.setLocationState(locations.Get(i), locStates[i]);
     }
 }
Exemple #2
0
        public override void executeAction(IAgent a, IAction action)
        {
            string loc = getAgentLocation(a);

            if (ACTION_MOVE_RIGHT == action)
            {
                int x = getX(loc);
                if (x < getXDimension())
                {
                    envState.setAgentLocation(a, getLocation(x + 1, getY(loc)));
                }
                updatePerformanceMeasure(a, -1);
            }
            else if (ACTION_MOVE_LEFT == action)
            {
                int x = getX(loc);
                if (x > 1)
                {
                    envState.setAgentLocation(a, getLocation(x - 1, getY(loc)));
                }
                updatePerformanceMeasure(a, -1);
            }
            else if (ACTION_SUCK == action)
            {
                if (LocationState.Dirty == envState.getLocationState(envState
                                                                     .getAgentLocation(a)))
                {
                    envState.setLocationState(envState.getAgentLocation(a),
                                              LocationState.Clean);
                    updatePerformanceMeasure(a, 10);
                }
            }
            else if (action.IsNoOp())
            {
                // In the Vacuum Environment we consider things done if
                // the agent generates a NoOp.
                _isDone = true;
            }
        }