001 package aima.basic; 002 003 import java.util.Hashtable; 004 005 /** 006 * Artificial Intelligence A Modern Approach (2nd Edition): Figure 2.1, page 33. 007 * 008 * Figure 2.1 Agents interact with environments through sensors and actuators. 009 */ 010 011 /** 012 * @author Ravi Mohan 013 * 014 */ 015 public abstract class Agent extends ObjectWithDynamicAttributes { 016 017 // Used to define No Operations/Action is to be performed. 018 public static final String NO_OP = "NoOP"; 019 020 protected AgentProgram program; 021 022 protected boolean isAlive; 023 024 protected Hashtable enviromentSpecificAttributes; 025 026 protected Agent() { 027 live(); 028 } 029 030 public Agent(AgentProgram aProgram) { 031 this(); 032 033 program = aProgram; 034 } 035 036 public String execute(Percept p) { 037 return program.execute(p); 038 } 039 040 public void live() { 041 isAlive = true; 042 } 043 044 public void die() { 045 isAlive = false; 046 } 047 048 public boolean isAlive() { 049 return isAlive; 050 } 051 }