Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
16accdd
added basic locations for further use
dev-iain Sep 2, 2026
3d66524
init now uses all four locations
dev-iain Sep 2, 2026
0e9c1af
update env, execute agent, some of the table agent, and the simple re…
apoppa17 Sep 2, 2026
6e2ebe6
Merge pull request #1 from dev-iain/create-vacuum-2x2
dev-iain Sep 2, 2026
62e19d6
Merge branch 'master' into lab1
dev-iain Sep 2, 2026
ba255bd
Merge pull request #2 from dev-iain/lab1
dev-iain Sep 3, 2026
9edceb2
update vacuum_world.py to match the ipynb
apoppa17 Sep 3, 2026
5b63fca
Merge pull request #3 from dev-iain/update_simpleagent_py
dev-iain Sep 3, 2026
c2e5e83
fixed locations issue
dev-iain Sep 4, 2026
b43dbd8
using itertools to produce combinations now
dev-iain Sep 4, 2026
2a61461
q4
Sep 4, 2026
4897598
realized my implementation did NOT work so i fixed it
dev-iain Sep 4, 2026
03b0fb0
added some clarity because the matrix locations is a bit confusing
dev-iain Sep 4, 2026
a09379c
made checking 'clean' dynamic
Sep 4, 2026
a8af4bb
fixed map to be the coordinate system
Sep 4, 2026
2f0305c
changed update_state() to have persistent memory
Sep 4, 2026
2638d9c
fixed locations A=0,0 B=0,1 etc
Sep 5, 2026
9cdf702
locations match original aima python
Sep 5, 2026
8cc3913
fixed the issue, also stripped notebook outputs
dev-iain Sep 5, 2026
a759e45
Merge pull request #4 from dev-iain/lab1
dev-iain Sep 5, 2026
9c23ba7
Merge branch 'master' into iain-table-agent
dev-iain Sep 5, 2026
a3e5248
Merge pull request #5 from dev-iain/iain-table-agent
dev-iain Sep 5, 2026
c3b45e1
had to re-strip notebook outputs and metadata because git hates me
dev-iain Sep 5, 2026
26b2ce3
create list of moves instead for easier usage
dev-iain Sep 5, 2026
31f2dcb
Update SimpleReflexAgentProgram
apoppa17 Sep 6, 2026
47487b5
fixed trivial vacuum's env to clamp for OOB
dev-iain Sep 6, 2026
67e1130
switch to none for fallback
apoppa17 Sep 6, 2026
8a2388e
Merge pull request #7 from dev-iain/execute_hotfix_iain
apoppa17 Sep 6, 2026
e0271f1
Merge pull request #6 from dev-iain/Update_SimpleReflex
dev-iain Sep 6, 2026
a9e396b
fix none in ipynb
apoppa17 Sep 6, 2026
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
42 changes: 26 additions & 16 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
locations = [loc_A, loc_B, loc_C, loc_D]


def RandomVacuumAgent():
Expand All @@ -203,7 +204,7 @@ def RandomVacuumAgent():
>>> environment.status == {(1,0):'Clean' , (0,0) : 'Clean'}
True
"""
return Agent(RandomAgentProgram(['Right', 'Left', 'Suck', 'NoOp']))
return Agent(RandomAgentProgram(['Right', 'Left','Up','Down', 'Suck', 'NoOp']))


def TableDrivenVacuumAgent():
Expand Down Expand Up @@ -261,21 +262,26 @@ def ModelBasedVacuumAgent():
>>> environment.status == {(1,0):'Clean' , (0,0) : 'Clean'}
True
"""
model = {loc_A: None, loc_B: None}
model = {loc_A: None, loc_B: None, loc_C: None, loc_D: None}

def program(percept):
"""Same as ReflexVacuumAgent, except if everything is clean, do NoOp."""
location, status = percept
model[location] = status # Update the model here
if model[loc_A] == model[loc_B] == 'Clean':
model[location] = status

if all(model[loc] == 'Clean' for loc in locations):
return 'NoOp'
elif status == 'Dirty':
return 'Suck'
# map: A right to C up to D left to B down
elif location == loc_A:
return 'Right'
return 'Up' # A -> C
elif location == loc_C:
return 'Right' # C -> D
elif location == loc_D:
return 'Down' # D -> B
elif location == loc_B:
return 'Left'

return 'Left' # B -> A
return Agent(program)


Expand Down Expand Up @@ -806,8 +812,7 @@ 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: random.choice(['Clean', 'Dirty']) for loc in locations}

def thing_classes(self):
"""Return the Thing/Agent classes that may populate this vacuum world."""
Expand All @@ -820,11 +825,16 @@ def percept(self, agent):
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.performance -= 1
elif action == 'Left':
agent.location = loc_A
a, b = agent.location
moves = {'Right': (a + 1, b),
'Left': (a - 1, b),
'Up': (a, b + 1),
'Down': (a, b - 1)
}
if action in moves:
target = moves[action]
if target in self.status:
agent.location = target
agent.performance -= 1
elif action == 'Suck':
if self.status[agent.location] == 'Dirty':
Expand All @@ -833,7 +843,7 @@ def execute_action(self, agent, action):

def default_location(self, thing):
"""Agents start in either location at random."""
return random.choice([loc_A, loc_B])
return random.choice([loc_A, loc_B, loc_C, loc_D])


# ______________________________________________________________________________
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
2 changes: 2 additions & 0 deletions lite/content/Welcome.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"cells": [
{
"cell_type": "markdown",
"id": "0",
"metadata": {},
"source": [
"# aima-python in the browser\n",
Expand All @@ -23,6 +24,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "1",
"metadata": {},
"outputs": [],
"source": [
Expand Down
8 changes: 4 additions & 4 deletions lite/content/agents.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "markdown",
"id": "2ccc4349",
"id": "0",
"metadata": {},
"source": [
"# Agents and environments in the browser\n",
Expand All @@ -13,7 +13,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "47375431",
"id": "1",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -23,7 +23,7 @@
},
{
"cell_type": "markdown",
"id": "588ca436",
"id": "2",
"metadata": {},
"source": [
"## The two-square vacuum world\n",
Expand All @@ -34,7 +34,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "2b51257f",
"id": "3",
"metadata": {},
"outputs": [],
"source": [
Expand Down
6 changes: 6 additions & 0 deletions lite/content/csp.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"cells": [
{
"cell_type": "markdown",
"id": "0",
"metadata": {},
"source": [
"# Constraint satisfaction in the browser\n",
Expand All @@ -13,6 +14,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "1",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -22,6 +24,7 @@
},
{
"cell_type": "markdown",
"id": "2",
"metadata": {},
"source": [
"## Map colouring\n",
Expand All @@ -34,6 +37,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "3",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -46,6 +50,7 @@
},
{
"cell_type": "markdown",
"id": "4",
"metadata": {},
"source": [
"## N-queens\n",
Expand All @@ -57,6 +62,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "5",
"metadata": {},
"outputs": [],
"source": [
Expand Down
14 changes: 7 additions & 7 deletions lite/content/game_theory.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "markdown",
"id": "2a692917",
"id": "0",
"metadata": {},
"source": [
"# Game theory in the browser\n",
Expand All @@ -12,7 +12,7 @@
},
{
"cell_type": "markdown",
"id": "27833b2a",
"id": "1",
"metadata": {},
"source": [
"`aima.game_theory` uses SciPy for the linear program behind zero-sum games, so we load it alongside `aima`."
Expand All @@ -21,7 +21,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "ea7846ee",
"id": "2",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -32,7 +32,7 @@
},
{
"cell_type": "markdown",
"id": "c6470bac",
"id": "3",
"metadata": {},
"source": [
"## Pure-strategy Nash equilibria\n",
Expand All @@ -43,7 +43,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "d78b2ad1",
"id": "4",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -59,7 +59,7 @@
},
{
"cell_type": "markdown",
"id": "148ca176",
"id": "5",
"metadata": {},
"source": [
"## Zero-sum games and cooperative value\n",
Expand All @@ -70,7 +70,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "31cdf1f3",
"id": "6",
"metadata": {},
"outputs": [],
"source": [
Expand Down
4 changes: 4 additions & 0 deletions lite/content/games.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"cells": [
{
"cell_type": "markdown",
"id": "0",
"metadata": {},
"source": [
"# Adversarial search in the browser\n",
Expand All @@ -13,6 +14,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "1",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -23,6 +25,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "2",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -37,6 +40,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "3",
"metadata": {},
"outputs": [],
"source": [
Expand Down
8 changes: 4 additions & 4 deletions lite/content/knowledge.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "markdown",
"id": "6433848c",
"id": "0",
"metadata": {},
"source": [
"# Knowledge in learning, in the browser\n",
Expand All @@ -13,7 +13,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "ed8fbc35",
"id": "1",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -23,7 +23,7 @@
},
{
"cell_type": "markdown",
"id": "6b6b3c18",
"id": "2",
"metadata": {},
"source": [
"## Learning a concept from examples\n",
Expand All @@ -34,7 +34,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "5a8d03da",
"id": "3",
"metadata": {},
"outputs": [],
"source": [
Expand Down
12 changes: 6 additions & 6 deletions lite/content/learning.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "markdown",
"id": "14ed9989",
"id": "0",
"metadata": {},
"source": [
"# Learning from examples in the browser\n",
Expand All @@ -13,7 +13,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "9f1978e2",
"id": "1",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -23,7 +23,7 @@
},
{
"cell_type": "markdown",
"id": "ba4b1402",
"id": "2",
"metadata": {},
"source": [
"## The \"play tennis\" dataset\n",
Expand All @@ -34,7 +34,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "9e3ee8d7",
"id": "3",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -55,7 +55,7 @@
},
{
"cell_type": "markdown",
"id": "165a1f98",
"id": "4",
"metadata": {},
"source": [
"## Decision tree vs. naive Bayes"
Expand All @@ -64,7 +64,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "14f3bdb8",
"id": "5",
"metadata": {},
"outputs": [],
"source": [
Expand Down
Loading