001 package aima.basic.vaccum; 002 003 import aima.basic.Agent; 004 import aima.basic.AgentProgram; 005 import aima.basic.Percept; 006 007 /** 008 * Artificial Intelligence A Modern Approach (2nd Edition): Figure 2.8, page 46. 009 * <code> 010 * function REFLEX-VACUUM-AGENT([location, status]) returns an action 011 * 012 * if status = Dirty then return Suck 013 * else if location = A then return Right 014 * else if location = B then return Left 015 * </code> 016 * Figure 2.8 The agent program for a simple reflex agent in the two-state vacuum environment. 017 * This program implements the action function tabulated in Figure 2.3. 018 */ 019 020 /** 021 * @author Ciaran O'Reilly 022 * 023 */ 024 public class ReflexVaccumAgent extends Agent { 025 026 public ReflexVaccumAgent() { 027 super(new AgentProgram() { 028 // function REFLEX-VACUUM-AGENT([location, status]) returns an 029 // action 030 @Override 031 public String execute(Percept percept) { 032 033 // if status = Dirty then return Suck 034 if ("Dirty".equals(percept.getAttribute("status"))) { 035 return "Suck"; 036 // else if location = A then return Right 037 } else if ("A".equals(percept.getAttribute("location"))) { 038 return "Right"; 039 // else if location = B then return Left 040 } else if ("B".equals(percept.getAttribute("location"))) { 041 return "Left"; 042 } 043 044 return "NoOP"; // Note: This should not be returned if the 045 // environment is correct 046 } 047 }); 048 } 049 }