Skip to content

Commit

Permalink
Updated docstring for ModelBasedReflexAgentProgram in agent.py (aimac…
Browse files Browse the repository at this point in the history
  • Loading branch information
articuno12 authored and norvig committed Mar 22, 2017
1 parent 9f1b1ee commit 4548aae
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def program(percept):


def ModelBasedReflexAgentProgram(rules, update_state, model):
"""This agent takes action based on the percept and state. [Figure 2.8]"""
"""This agent takes action based on the percept and state. [Figure 2.12]"""
def program(percept):
program.state = update_state(program.state, program.action, percept, model)
rule = rule_match(program.state, rules)
Expand Down Expand Up @@ -443,7 +443,7 @@ def move_to(self, thing, destination):
# obs.thing_added(thing)

def add_thing(self, thing, location=(1, 1), exclude_duplicate_class_items=False):
"""Adds things to the world. If (exclude_duplicate_class_items) then the item won't be
"""Adds things to the world. If (exclude_duplicate_class_items) then the item won't be
added if the location has at least one item of the same class."""
if (self.is_inbounds(location)):
if (exclude_duplicate_class_items and
Expand Down Expand Up @@ -523,7 +523,7 @@ class Wall(Obstacle):

class GraphicEnvironment(XYEnvironment):
def __init__(self, width=10, height=10, boundary=True, color={}, display=False):
"""define all the usual XYEnvironment characteristics,
"""define all the usual XYEnvironment characteristics,
but initialise a BlockGrid for GUI too"""
super().__init__(width, height)
self.grid = BlockGrid(width, height, fill=(200,200,200))
Expand All @@ -534,14 +534,14 @@ def __init__(self, width=10, height=10, boundary=True, color={}, display=False):
self.visible = False
self.bounded = boundary
self.colors = color

#def list_things_at(self, location, tclass=Thing): # need to override because locations
# """Return all things exactly at a given location."""
# return [thing for thing in self.things
# if thing.location == location and isinstance(thing, tclass)]

def get_world(self):
"""Returns all the items in the world in a format
"""Returns all the items in the world in a format
understandable by the ipythonblocks BlockGrid"""
result = []
x_start, y_start = (0, 0)
Expand All @@ -552,9 +552,9 @@ def get_world(self):
row.append(self.list_things_at([x, y]))
result.append(row)
return result

"""def run(self, steps=1000, delay=1):
"" "Run the Environment for given number of time steps,
"" "Run the Environment for given number of time steps,
but update the GUI too." ""
for step in range(steps):
sleep(delay)
Expand All @@ -569,33 +569,33 @@ def get_world(self):
self.reveal()
"""
def run(self, steps=1000, delay=1):
"""Run the Environment for given number of time steps,
"""Run the Environment for given number of time steps,
but update the GUI too."""
for step in range(steps):
self.update(delay)
if self.is_done():
break
self.step()
self.update(delay)

def update(self, delay=1):
sleep(delay)
if self.visible:
self.conceal()
self.reveal()
else:
self.reveal()

def reveal(self):
"""display the BlockGrid for this world - the last thing to be added
"""display the BlockGrid for this world - the last thing to be added
at a location defines the location color"""
#print("Grid={}".format(self.grid))
self.draw_world()
#if not self.visible == True:
# self.grid.show()
self.grid.show()
self.visible == True

def draw_world(self):
self.grid[:] = (200, 200, 200)
world = self.get_world()
Expand All @@ -606,14 +606,14 @@ def draw_world(self):
self.grid[y, x] = self.colors[world[x][y][-1].__class__.__name__]
#print('location: ({}, {}) got color: {}'
#.format(y, x, self.colors[world[x][y][-1].__class__.__name__]))

def conceal(self):
"""hide the BlockGrid for this world"""
self.visible = False
display(HTML(''))






Expand Down

0 comments on commit 4548aae

Please sign in to comment.