コード例 #1
0
            // function REFLEX-VACUUM-AGENT([location, status]) returns an
            // action
            public IAction Execute(IPercept percept)
            {
                LocalVacuumEnvironmentPercept vep = (LocalVacuumEnvironmentPercept)percept;

                // if status = Dirty then return Suck
                if (VacuumEnvironment.LocationState.Dirty == vep
                    .getLocationState())
                {
                    return(VacuumEnvironment.ACTION_SUCK);
                    // else if location = A then return Right
                }
                else if (VacuumEnvironment.LOCATION_A.Equals(vep
                                                             .getAgentLocation()))
                {
                    return(VacuumEnvironment.ACTION_MOVE_RIGHT);
                }
                else if (VacuumEnvironment.LOCATION_B.Equals(vep
                                                             .getAgentLocation()))
                {
                    // else if location = B then return Left
                    return(VacuumEnvironment.ACTION_MOVE_LEFT);
                }

                // Note: This should not be returned if the
                // environment is correct
                return(DynamicAction.NO_OP);
            }
コード例 #2
0
            protected override DynamicState updateState(DynamicState state,
                                                        IAction anAction, IPercept percept, MODEL model)
            {
                LocalVacuumEnvironmentPercept vep = (LocalVacuumEnvironmentPercept)percept;

                state.SetAttribute(ATTRIBUTE_CURRENT_LOCATION,
                                   vep.getAgentLocation());
                state.SetAttribute(ATTRIBUTE_CURRENT_STATE,
                                   vep.getLocationState());
                // Keep track of the state of the different locations
                if (VacuumEnvironment.LOCATION_A.Equals(vep.getAgentLocation()))
                {
                    state.SetAttribute(ATTRIBUTE_STATE_LOCATION_A,
                                       vep.getLocationState());
                }
                else
                {
                    state.SetAttribute(ATTRIBUTE_STATE_LOCATION_B,
                                       vep.getLocationState());
                }
                return(state);
            }