Intelligent agents and environments
Modern AI textbooks organize the field around the idea of an agent: something that perceives its environment through sensors and acts on it through actuators. An agent function maps the history of percepts to an action, and an agent program is the code that implements it. A rational agent chooses the action expected to maximize its performance measure, given what it has perceived so far. The task is described by its PEAS: Performance measure, Environment, Actuators, and Sensors.
Python
def reflex_agent(location, dirty):
if dirty:
return "suck"
return "right" if location == "A" else "left"
def run(world, location, steps):
actions = []
for _ in range(steps):
action = reflex_agent(location, world[location])
actions.append(action)
if action == "suck":
world[location] = False
elif action == "right":
location = "B"
else:
location = "A"
return actions
world = {"A": True, "B": True}
print(run(world, "A", 4))
print(world)