Skip to content

added binary and multiclass SVM with tests #1135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 178 commits into from
Dec 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
178 commits
Select commit Hold shift + click to select a range
fe514c6
changed queue to set in AC3
dmeoli Mar 24, 2019
0129aa9
re-added test commented by mistake
dmeoli Mar 28, 2019
03551fb
added the mentioned AC4 algorithm for constraint propagation
dmeoli Apr 11, 2019
c0b8383
Merge branch 'master' into master
dmeoli Apr 11, 2019
6986247
added doctest in Sudoku for AC4 and and the possibility of choosing t…
dmeoli Apr 11, 2019
b3cd24c
removed useless doctest for AC4 in Sudoku because AC4's tests are alr…
dmeoli Apr 11, 2019
9e0fa55
added map coloring SAT problems
dmeoli Jun 17, 2019
f743146
fixed typo errors and removed unnecessary brackets
dmeoli Jun 17, 2019
20ab0e5
reformulated the map coloring problem
dmeoli Jul 4, 2019
404b179
Revert "reformulated the map coloring problem"
dmeoli Jul 4, 2019
c9c5106
Revert "fixed typo errors and removed unnecessary brackets"
dmeoli Jul 4, 2019
3243ba1
Revert "added map coloring SAT problems"
dmeoli Jul 4, 2019
2af1659
Revert "removed useless doctest for AC4 in Sudoku because AC4's tests…
dmeoli Jul 4, 2019
0c7e5af
Revert "added doctest in Sudoku for AC4 and and the possibility of ch…
dmeoli Jul 4, 2019
ff8c411
Revert "added the mentioned AC4 algorithm for constraint propagation"
dmeoli Jul 4, 2019
93af259
added map coloring SAT problem
dmeoli Jul 4, 2019
002a34e
Merge remote-tracking branch 'upstream/master'
dmeoli Jul 4, 2019
6641c2c
fixed build error
dmeoli Jul 4, 2019
9399dfc
Revert "added map coloring SAT problem"
dmeoli Jul 29, 2019
e130909
Revert "fixed build error"
dmeoli Jul 29, 2019
78bdeb1
Merge remote-tracking branch 'upstream/master'
dmeoli Jul 29, 2019
2f62776
added map coloring SAT problem
dmeoli Jul 29, 2019
aaea704
removed redundant parentheses
dmeoli Jul 29, 2019
0cd6386
Merge remote-tracking branch 'upstream/master'
dmeoli Aug 7, 2019
be656aa
added Viterbi algorithm
dmeoli Aug 14, 2019
c74933a
added monkey & bananas planning problem
dmeoli Aug 23, 2019
6d229ce
simplified condition in search.py
dmeoli Aug 23, 2019
24041e9
added tests for monkey & bananas planning problem
dmeoli Aug 23, 2019
9d37ae0
removed monkey & bananas planning problem
dmeoli Aug 23, 2019
459aae6
Revert "removed monkey & bananas planning problem"
dmeoli Aug 23, 2019
dbfb9c1
Revert "added tests for monkey & bananas planning problem"
dmeoli Aug 23, 2019
14d9014
Revert "simplified condition in search.py"
dmeoli Aug 23, 2019
5eb29cd
Revert "added monkey & bananas planning problem"
dmeoli Aug 23, 2019
396c38b
Merge remote-tracking branch 'upstream/master'
dmeoli Aug 23, 2019
776c131
defined the PlanningProblem as a specialization of a search.Problem &…
dmeoli Aug 27, 2019
ccc7de1
fixed doctest in logic.py
dmeoli Aug 27, 2019
7e98afb
fixed doctest for cascade_distribution
dmeoli Aug 27, 2019
061cba1
added ForwardPlanner and tests
dmeoli Aug 30, 2019
8c10d9f
added __lt__ implementation for Expr
dmeoli Aug 30, 2019
aa61869
added more tests
dmeoli Aug 30, 2019
c4139e5
renamed forward planner
dmeoli Aug 31, 2019
e4c4343
Revert "renamed forward planner"
dmeoli Aug 31, 2019
6e084c0
renamed forward planner class & added doc
dmeoli Aug 31, 2019
b6a0cbd
added backward planner and tests
dmeoli Sep 2, 2019
1131f4d
Merge remote-tracking branch 'upstream/master'
dmeoli Sep 3, 2019
1af8978
fixed mdp4e.py doctests
dmeoli Sep 3, 2019
a4ad133
removed ignore_delete_lists_heuristic flag
dmeoli Sep 3, 2019
26f2b5d
fixed heuristic for forward and backward planners
dmeoli Sep 6, 2019
9faf17a
added SATPlan and tests
dmeoli Sep 6, 2019
0be0f5d
fixed ignore delete lists heuristic in forward and backward planners
dmeoli Sep 7, 2019
2cc2d3f
fixed backward planner and added tests
dmeoli Sep 8, 2019
4222176
updated doc
dmeoli Sep 8, 2019
30af352
Merge remote-tracking branch 'upstream/master'
dmeoli Sep 11, 2019
b69a907
added nary csp definition and examples
dmeoli Sep 11, 2019
6ff465a
added CSPlan and tests
dmeoli Sep 11, 2019
d3c291c
fixed CSPlan
dmeoli Sep 11, 2019
785850a
added book's cryptarithmetic puzzle example
dmeoli Sep 11, 2019
7249058
fixed typo errors in test_csp
dmeoli Sep 11, 2019
42e9cbc
fixed #1111
dmeoli Sep 12, 2019
0fb48f6
added sortedcontainers to yml and doc to CSPlan
dmeoli Sep 12, 2019
5cce7d9
added tests for n-ary csp
dmeoli Sep 13, 2019
b567a6d
fixed utils.extend
dmeoli Sep 13, 2019
2eba772
updated test_probability.py
dmeoli Sep 14, 2019
427e85a
converted static methods to functions
dmeoli Sep 15, 2019
cd1ad41
added AC3b and AC4 with heuristic and tests
dmeoli Sep 15, 2019
0092f27
Merge remote-tracking branch 'upstream/master'
dmeoli Sep 16, 2019
d9dd4bb
added conflict-driven clause learning sat solver
dmeoli Sep 16, 2019
c0220d2
added tests for cdcl and heuristics
dmeoli Sep 16, 2019
8f0779d
fixed probability.py
dmeoli Sep 17, 2019
7a59010
fixed import
dmeoli Sep 17, 2019
0135db6
fixed kakuro
dmeoli Sep 20, 2019
ac98bd8
Merge remote-tracking branch 'upstream/master'
dmeoli Sep 21, 2019
dca70da
added Martelli and Montanari rule-based unification algorithm
dmeoli Sep 25, 2019
84e7a55
removed duplicate standardize_variables
dmeoli Sep 25, 2019
20bc37b
renamed variables known as built-in functions
dmeoli Sep 26, 2019
4b02d92
fixed typos in learning.py
dmeoli Sep 26, 2019
8427b5f
renamed some files and fixed typos
dmeoli Sep 26, 2019
3ffe3e9
fixed typos
dmeoli Sep 26, 2019
2d0dbc2
fixed typos
dmeoli Sep 27, 2019
b7e8206
fixed tests
dmeoli Sep 27, 2019
0c5f0ac
removed unify_mm
dmeoli Sep 29, 2019
bcc169d
remove unnecessary brackets
dmeoli Sep 29, 2019
9dd097b
fixed tests
dmeoli Sep 29, 2019
abc8f17
moved utility functions to utils.py
dmeoli Sep 29, 2019
9839d14
Merge remote-tracking branch 'upstream/master'
dmeoli Sep 29, 2019
50e036f
fixed typos
dmeoli Oct 1, 2019
44e1f9c
moved utils function to utils.py, separated probability learning clas…
dmeoli Oct 3, 2019
17285cc
added missing learners
dmeoli Oct 3, 2019
d80fed5
fixed Travis build
dmeoli Oct 3, 2019
a734d46
fixed typos
dmeoli Oct 3, 2019
df16744
fixed typos
dmeoli Oct 3, 2019
c81425f
fixed typos
dmeoli Oct 3, 2019
0071746
fixed typos
dmeoli Oct 4, 2019
25ac7b3
Merge branch 'master' into master
dmeoli Oct 4, 2019
f4f8663
fixed typos in agents files
dmeoli Oct 4, 2019
dd8ae31
fixed imports in agent files
dmeoli Oct 4, 2019
13000ac
Merge branch 'ml'
dmeoli Oct 4, 2019
b11adf4
Merge remote-tracking branch 'upstream/master'
dmeoli Oct 7, 2019
e041479
fixed deep learning .ipynb imports
dmeoli Oct 8, 2019
be7c131
fixed typos
dmeoli Oct 8, 2019
9b3c8ba
added SVM
dmeoli Oct 8, 2019
8bede28
Merge remote-tracking branch 'upstream/master'
dmeoli Oct 8, 2019
fa6676c
Merge branch 'master' into ml
dmeoli Oct 8, 2019
e0b4a1c
Merge remote-tracking branch 'upstream/master'
dmeoli Oct 24, 2019
e31a5a3
Merge branch 'master' into ml
dmeoli Oct 24, 2019
99c1b4c
Merge remote-tracking branch 'upstream/master'
dmeoli Oct 29, 2019
a672234
Merge branch 'master' into ml
dmeoli Oct 29, 2019
b9236db
added .ipynb and fixed typos
dmeoli Nov 1, 2019
3001803
adapted code for .ipynb
dmeoli Nov 1, 2019
e5f75f3
fixed typos
dmeoli Nov 1, 2019
278574d
updated .ipynb
dmeoli Nov 1, 2019
25c590d
updated .ipynb
dmeoli Nov 1, 2019
23e3d95
updated logic.py
dmeoli Nov 1, 2019
aa79be3
updated .ipynb
dmeoli Nov 1, 2019
42a6d4a
updated .ipynb
dmeoli Nov 1, 2019
ce3d0c6
updated planning.py
dmeoli Nov 1, 2019
8f5ef83
updated inf definition
dmeoli Nov 1, 2019
9d27673
fixed typos
dmeoli Nov 2, 2019
181d257
fixed typos
dmeoli Nov 2, 2019
08ad660
fixed typos
dmeoli Nov 2, 2019
658309d
fixed typos
dmeoli Nov 2, 2019
35fc24d
Revert "fixed typos"
dmeoli Nov 2, 2019
ecc7c2d
Revert "fixed typos"
dmeoli Nov 2, 2019
dbbe897
fixed typos
dmeoli Nov 2, 2019
8ef5e0c
fixed typos
dmeoli Nov 2, 2019
cf95e44
fixed typos
dmeoli Nov 2, 2019
0d64274
fixed typos
dmeoli Nov 2, 2019
3404deb
Merge branch 'master' into ml
dmeoli Nov 2, 2019
29644d4
fixed typos and utils imports in *4e.py files
dmeoli Nov 2, 2019
43f09c6
Merge branch 'master' into ml
dmeoli Nov 2, 2019
1c68b8a
Merge remote-tracking branch 'upstream/master'
dmeoli Nov 3, 2019
47df065
Merge remote-tracking branch 'upstream/master' into ml
dmeoli Nov 3, 2019
1654a9c
fixed typos
dmeoli Nov 3, 2019
fe5801e
Merge branch 'master' into ml
dmeoli Nov 3, 2019
b3d0352
Merge remote-tracking branch 'upstream/master'
dmeoli Nov 4, 2019
3960568
Merge branch 'master' into ml
dmeoli Nov 4, 2019
089d4b9
fixed typos
dmeoli Nov 4, 2019
c531100
Merge branch 'master' into ml
dmeoli Nov 4, 2019
b065c3f
fixed typos
dmeoli Nov 6, 2019
c7787cf
fixed typos
dmeoli Nov 6, 2019
e3b6a0c
Merge branch 'master' into ml
dmeoli Nov 6, 2019
d10fa04
fixed import
dmeoli Nov 10, 2019
e334940
fixed typos
dmeoli Nov 11, 2019
598a4ca
fixed typos
dmeoli Nov 11, 2019
8aeccda
fixd typos
dmeoli Nov 11, 2019
5afbf72
fixed typos
dmeoli Nov 11, 2019
182c588
fixed typos
dmeoli Nov 14, 2019
a47a516
updated SVM
dmeoli Nov 15, 2019
45cceab
added svm test
dmeoli Nov 15, 2019
86f91f9
fixed SVM and tests
dmeoli Nov 18, 2019
3f8f759
fixed some definitions and typos
dmeoli Nov 19, 2019
602627e
fixed svm and tests
dmeoli Nov 19, 2019
47c559e
added SVMs also in learning4e.py
dmeoli Nov 19, 2019
bcec266
fixed inf definition
dmeoli Nov 19, 2019
9a2541b
fixed .travis.yml
dmeoli Nov 19, 2019
2b55d16
fixed .travis.yml
dmeoli Nov 19, 2019
6143a07
fixed import
dmeoli Nov 19, 2019
bc4dd41
fixed inf definition
dmeoli Nov 19, 2019
d6f5024
replaced cvxopt with qpsolvers
dmeoli Nov 20, 2019
3473fc6
replaced cvxopt with quadprog
dmeoli Nov 20, 2019
924a4fb
fixed some definitions
dmeoli Nov 20, 2019
0044cbf
fixed typos and removed unnecessary tests
dmeoli Nov 20, 2019
75b8c2f
replaced quadprog with qpsolvers
dmeoli Nov 20, 2019
0a5fa77
fixed extend in utils
dmeoli Nov 20, 2019
132bf13
specified error type in try-catch block
dmeoli Nov 20, 2019
b81a7a6
fixed extend in utils
dmeoli Nov 20, 2019
72b5c20
fixed typos
dmeoli Nov 21, 2019
b63a622
fixed learning.py
dmeoli Nov 21, 2019
210c800
fixed doctest errors
dmeoli Nov 21, 2019
dca1c90
added comments
dmeoli Nov 21, 2019
bc4b18f
removed unnecessary if condition
dmeoli Nov 21, 2019
bd74894
updated learning.py
dmeoli Nov 22, 2019
94e81e1
fixed imports
dmeoli Nov 24, 2019
27dd36a
removed unnecessary imports
dmeoli Nov 24, 2019
8f5b1b0
fixed keras imports
dmeoli Nov 24, 2019
ede8658
fixed typos
dmeoli Nov 24, 2019
72a9040
fixed learning_curve
dmeoli Nov 30, 2019
c8a507c
added comments
dmeoli Dec 2, 2019
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
25 changes: 14 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
language:
- python
language: python

python:
- "3.4"
- 3.4
- 3.5
- 3.6
- 3.7

before_install:
- git submodule update --remote

install:
- pip install six
- pip install flake8
- pip install ipython
- pip install matplotlib
- pip install networkx
- pip install ipywidgets
- pip install Pillow
- pip install pytest-cov
- pip install ipythonblocks
- pip install ipywidgets
- pip install keras
- pip install matplotlib
- pip install networkx
- pip install numpy
- pip install tensorflow
- pip install opencv-python
- pip install Pillow
- pip install pytest-cov
- pip install qpsolvers
- pip install quadprog
- pip install six
- pip install sortedcontainers

- pip install tensorflow

script:
- py.test --cov=./
Expand Down
54 changes: 31 additions & 23 deletions agents.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Implement Agents and Environments (Chapters 1-2).
"""
Implement Agents and Environments. (Chapters 1-2)

The class hierarchies are as follows:

Expand All @@ -23,16 +24,14 @@
EnvToolbar ## contains buttons for controlling EnvGUI

EnvCanvas ## Canvas to display the environment of an EnvGUI

"""

# TO DO:
# TODO
# Implement grabbing correctly.
# When an object is grabbed, does it still have a location?
# What if it is released?
# What if the grabbed or the grabber is deleted?
# What if the grabber moves?
#
# Speed control in GUI does not have any effect -- fix it.

from utils import distance_squared, turn_heading
Expand Down Expand Up @@ -90,8 +89,7 @@ def __init__(self, program=None):
self.holding = []
self.performance = 0
if program is None or not isinstance(program, collections.Callable):
print("Can't find a valid program for {}, falling back to default.".format(
self.__class__.__name__))
print("Can't find a valid program for {}, falling back to default.".format(self.__class__.__name__))

def program(percept):
return eval(input('Percept={}; action? '.format(percept)))
Expand Down Expand Up @@ -122,10 +120,13 @@ def new_program(percept):


def TableDrivenAgentProgram(table):
"""This agent selects an action based on the percept sequence.
"""
[Figure 2.7]
This agent selects an action based on the percept sequence.
It is practical only for tiny domains.
To customize it, provide as table a dictionary of all
{percept_sequence:action} pairs. [Figure 2.7]"""
{percept_sequence:action} pairs.
"""
percepts = []

def program(percept):
Expand Down Expand Up @@ -154,7 +155,10 @@ def RandomAgentProgram(actions):


def SimpleReflexAgentProgram(rules, interpret_input):
"""This agent takes action based solely on the percept. [Figure 2.10]"""
"""
[Figure 2.10]
This agent takes action based solely on the percept.
"""

def program(percept):
state = interpret_input(percept)
Expand All @@ -166,7 +170,10 @@ def program(percept):


def ModelBasedReflexAgentProgram(rules, update_state, model):
"""This agent takes action based on the percept and state. [Figure 2.12]"""
"""
[Figure 2.12]
This agent takes action based on the percept and state.
"""

def program(percept):
program.state = update_state(program.state, program.action, percept, model)
Expand Down Expand Up @@ -219,7 +226,9 @@ def TableDrivenVacuumAgent():


def ReflexVacuumAgent():
"""A reflex agent for the two-state vacuum environment. [Figure 2.8]
"""
[Figure 2.8]
A reflex agent for the two-state vacuum environment.
>>> agent = ReflexVacuumAgent()
>>> environment = TrivialVacuumEnvironment()
>>> environment.add_thing(agent)
Expand Down Expand Up @@ -436,13 +445,13 @@ def move_forward(self, from_location):
"""
x, y = from_location
if self.direction == self.R:
return (x + 1, y)
return x + 1, y
elif self.direction == self.L:
return (x - 1, y)
return x - 1, y
elif self.direction == self.U:
return (x, y - 1)
return x, y - 1
elif self.direction == self.D:
return (x, y + 1)
return x, y + 1


class XYEnvironment(Environment):
Expand Down Expand Up @@ -497,7 +506,7 @@ def execute_action(self, agent, action):
agent.holding.pop()

def default_location(self, thing):
return (random.choice(self.width), random.choice(self.height))
return random.choice(self.width), random.choice(self.height)

def move_to(self, thing, destination):
"""Move a thing to a new location. Returns True on success or False if there is an Obstacle.
Expand Down Expand Up @@ -525,7 +534,7 @@ def add_thing(self, thing, location=(1, 1), exclude_duplicate_class_items=False)
def is_inbounds(self, location):
"""Checks to make sure that the location is inbounds (within walls if we have walls)"""
x, y = location
return not (x < self.x_start or x >= self.x_end or y < self.y_start or y >= self.y_end)
return not (x < self.x_start or x > self.x_end or y < self.y_start or y > self.y_end)

def random_location_inbounds(self, exclude=None):
"""Returns a random location that is inbounds (within walls if we have walls)"""
Expand Down Expand Up @@ -723,7 +732,7 @@ def percept(self, agent):
status = ('Dirty' if self.some_things_at(
agent.location, Dirt) else 'Clean')
bump = ('Bump' if agent.bump else 'None')
return (status, bump)
return status, bump

def execute_action(self, agent, action):
agent.bump = False
Expand Down Expand Up @@ -752,12 +761,11 @@ def __init__(self):
loc_B: random.choice(['Clean', 'Dirty'])}

def thing_classes(self):
return [Wall, Dirt, ReflexVacuumAgent, RandomVacuumAgent,
TableDrivenVacuumAgent, ModelBasedVacuumAgent]
return [Wall, Dirt, ReflexVacuumAgent, RandomVacuumAgent, TableDrivenVacuumAgent, ModelBasedVacuumAgent]

def percept(self, agent):
"""Returns the agent's location, and the location status (Dirty/Clean)."""
return (agent.location, self.status[agent.location])
return agent.location, self.status[agent.location]

def execute_action(self, agent, action):
"""Change agent's location and/or location's status; track performance.
Expand Down Expand Up @@ -992,8 +1000,8 @@ def is_done(self):
else:
print("Death by {} [-1000].".format(explorer[0].killed_by))
else:
print("Explorer climbed out {}.".format("with Gold [+1000]!"
if Gold() not in self.things else "without Gold [+0]"))
print("Explorer climbed out {}."
.format("with Gold [+1000]!" if Gold() not in self.things else "without Gold [+0]"))
return True

# TODO: Arrow needs to be implemented
Expand Down
54 changes: 30 additions & 24 deletions agents4e.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Implement Agents and Environments (Chapters 1-2).
"""
Implement Agents and Environments. (Chapters 1-2)

The class hierarchies are as follows:

Expand All @@ -23,16 +24,14 @@
EnvToolbar ## contains buttons for controlling EnvGUI

EnvCanvas ## Canvas to display the environment of an EnvGUI

"""

# TO DO:
# TODO
# Implement grabbing correctly.
# When an object is grabbed, does it still have a location?
# What if it is released?
# What if the grabbed or the grabber is deleted?
# What if the grabber moves?
#
# Speed control in GUI does not have any effect -- fix it.

from utils4e import distance_squared, turn_heading
Expand Down Expand Up @@ -90,8 +89,7 @@ def __init__(self, program=None):
self.holding = []
self.performance = 0
if program is None or not isinstance(program, collections.Callable):
print("Can't find a valid program for {}, falling back to default.".format(
self.__class__.__name__))
print("Can't find a valid program for {}, falling back to default.".format(self.__class__.__name__))

def program(percept):
return eval(input('Percept={}; action? '.format(percept)))
Expand Down Expand Up @@ -122,10 +120,13 @@ def new_program(percept):


def TableDrivenAgentProgram(table):
"""This agent selects an action based on the percept sequence.
"""
[Figure 2.7]
This agent selects an action based on the percept sequence.
It is practical only for tiny domains.
To customize it, provide as table a dictionary of all
{percept_sequence:action} pairs. [Figure 2.7]"""
{percept_sequence:action} pairs.
"""
percepts = []

def program(percept):
Expand Down Expand Up @@ -154,7 +155,10 @@ def RandomAgentProgram(actions):


def SimpleReflexAgentProgram(rules, interpret_input):
"""This agent takes action based solely on the percept. [Figure 2.10]"""
"""
[Figure 2.10]
This agent takes action based solely on the percept.
"""

def program(percept):
state = interpret_input(percept)
Expand All @@ -166,7 +170,10 @@ def program(percept):


def ModelBasedReflexAgentProgram(rules, update_state, trainsition_model, sensor_model):
"""This agent takes action based on the percept and state. [Figure 2.12]"""
"""
[Figure 2.12]
This agent takes action based on the percept and state.
"""

def program(percept):
program.state = update_state(program.state, program.action, percept, trainsition_model, sensor_model)
Expand Down Expand Up @@ -219,7 +226,9 @@ def TableDrivenVacuumAgent():


def ReflexVacuumAgent():
"""A reflex agent for the two-state vacuum environment. [Figure 2.8]
"""
[Figure 2.8]
A reflex agent for the two-state vacuum environment.
>>> agent = ReflexVacuumAgent()
>>> environment = TrivialVacuumEnvironment()
>>> environment.add_thing(agent)
Expand Down Expand Up @@ -333,8 +342,7 @@ def run(self, steps=1000):

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

def some_things_at(self, location, tclass=Thing):
"""Return true if at least one of the things at location
Expand Down Expand Up @@ -437,13 +445,13 @@ def move_forward(self, from_location):
"""
x, y = from_location
if self.direction == self.R:
return (x + 1, y)
return x + 1, y
elif self.direction == self.L:
return (x - 1, y)
return x - 1, y
elif self.direction == self.U:
return (x, y - 1)
return x, y - 1
elif self.direction == self.D:
return (x, y + 1)
return x, y + 1


class XYEnvironment(Environment):
Expand Down Expand Up @@ -498,7 +506,7 @@ def execute_action(self, agent, action):
agent.holding.pop()

def default_location(self, thing):
return (random.choice(self.width), random.choice(self.height))
return random.choice(self.width), random.choice(self.height)

def move_to(self, thing, destination):
"""Move a thing to a new location. Returns True on success or False if there is an Obstacle.
Expand Down Expand Up @@ -724,7 +732,7 @@ def percept(self, agent):
status = ('Dirty' if self.some_things_at(
agent.location, Dirt) else 'Clean')
bump = ('Bump' if agent.bump else 'None')
return (status, bump)
return status, bump

def execute_action(self, agent, action):
agent.bump = False
Expand Down Expand Up @@ -753,12 +761,11 @@ def __init__(self):
loc_B: random.choice(['Clean', 'Dirty'])}

def thing_classes(self):
return [Wall, Dirt, ReflexVacuumAgent, RandomVacuumAgent,
TableDrivenVacuumAgent, ModelBasedVacuumAgent]
return [Wall, Dirt, ReflexVacuumAgent, RandomVacuumAgent, TableDrivenVacuumAgent, ModelBasedVacuumAgent]

def percept(self, agent):
"""Returns the agent's location, and the location status (Dirty/Clean)."""
return (agent.location, self.status[agent.location])
return agent.location, self.status[agent.location]

def execute_action(self, agent, action):
"""Change agent's location and/or location's status; track performance.
Expand Down Expand Up @@ -994,8 +1001,7 @@ def is_done(self):
print("Death by {} [-1000].".format(explorer[0].killed_by))
else:
print("Explorer climbed out {}."
.format(
"with Gold [+1000]!" if Gold() not in self.things else "without Gold [+0]"))
.format("with Gold [+1000]!" if Gold() not in self.things else "without Gold [+0]"))
return True

# TODO: Arrow needs to be implemented
Expand Down
Loading