// function REFLEX-VACUUM-AGENT([location, status]) returns an
            // action
            public IAction Execute(IPercept percept)
            {
                VacuumEnvPercept vep = (VacuumEnvPercept)percept;

                // if status = Dirty then return Suck
                if (VacuumEnvironment.LocationState.Dirty == vep
                    .GetLocationState())
                {
                    return(VacuumEnvironment.ActionSuck);
                    // else if location = A then return Right
                }
                else if (VacuumEnvironment.LocationA == vep
                         .GetAgentLocation())
                {
                    return(VacuumEnvironment.ActionMoveRight);
                }
                else if (VacuumEnvironment.LocationB == vep
                         .GetAgentLocation())
                {
                    // else if location = B then return Left
                    return(VacuumEnvironment.ActionMoveLeft);
                }

                // Note: This should not be returned if the
                // environment is correct
                return(NoOpAction.NoOp);
            }
Beispiel #2
0
            protected override DynamicState UpdateState(DynamicState envState,
                                                        IAction anAction, IPercept percept, IModel model)
            {
                VacuumEnvPercept vep = (VacuumEnvPercept)percept;

                envState.SetAttribute(AttributeCurrentLocation, vep
                                      .GetAgentLocation());
                envState.SetAttribute(AttributeCurrentState, vep
                                      .GetLocationState());
                // Keep track of the state of the different locations
                if (VacuumEnvironment.LocationA == vep.GetAgentLocation())
                {
                    envState.SetAttribute(AttributeStateLocationA, vep
                                          .GetLocationState());
                }
                else
                {
                    envState.SetAttribute(AttributeStateLocationB, vep
                                          .GetLocationState());
                }
                return(envState);
            }