Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions aima/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ def rule_match(state, rules):
# ______________________________________________________________________________


loc_A, loc_B = (0, 0), (1, 0) # The two locations for the Vacuum world
loc_A, loc_B, loc_C, loc_D = (0, 0), (1, 0), (0, 1), (1,1)
# The four locations for the Vacuum world


def RandomVacuumAgent():
Expand Down Expand Up @@ -806,8 +807,11 @@ class TrivialVacuumEnvironment(Environment):

def __init__(self):
super().__init__()
self.status = {loc_A: random.choice(['Clean', 'Dirty']),
loc_B: random.choice(['Clean', 'Dirty'])}
self.status = {loc_AA: random.choice(['Clean', 'Dirty']),
loc_AB: random.choice(['Clean', 'Dirty']),
loc_BB: random.choice(['Clean', 'Dirty']),
loc_BA: random.choice(['Clean', 'Dirty'])
}

def thing_classes(self):
"""Return the Thing/Agent classes that may populate this vacuum world."""
Expand All @@ -821,10 +825,16 @@ def execute_action(self, agent, action):
"""Change agent's location and/or location's status; track performance.
Score 10 for each dirt cleaned; -1 for each move."""
if action == 'Right':
agent.location = loc_B
agent.location[0] += 1
agent.performance -= 1
elif action == 'Left':
agent.location = loc_A
agent.location[0] -= 1
agent.performance -= 1
elif action == 'Up':
agent.location[1] -= 1
agent.performance -= 1
elif action == 'Down':
agent.location[1] += 1
agent.performance -= 1
elif action == 'Suck':
if self.status[agent.location] == 'Dirty':
Expand Down
2 changes: 1 addition & 1 deletion aima/notebook_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def psource(*functions):
from pygments.lexers import PythonLexer
from pygments import highlight

display(HTML(highlight(source_code, PythonLexer(), HtmlFormatter(full=True))))
display(HTML(highlight(source_code, PythonLexer(), HtmlFormatter(noclasses=True, style='monokai'))))

except ImportError:
print(source_code)
Expand Down
8 changes: 4 additions & 4 deletions notebooks/agents.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -722,9 +722,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "AIMA (Python 3.13)",
"language": "python",
"name": "python3"
"name": "aima"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -736,9 +736,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.4"
"version": "3.13.5"
}
},
"nbformat": 4,
"nbformat_minor": 1
"nbformat_minor": 4
}
Loading