Skip to content

Commit c9c5106

Browse files
committed
Revert "fixed typo errors and removed unnecessary brackets"
This reverts commit f743146.
1 parent 404b179 commit c9c5106

File tree

2 files changed

+64
-69
lines changed

2 files changed

+64
-69
lines changed

logic.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,7 @@ def new_disjunction(sentences):
911911

912912
class WumpusKB(PropKB):
913913
"""
914-
Create a Knowledge Base that contains the a temporal "Wumpus physics" and temporal rules with time zero.
914+
Create a Knowledge Base that contains the atemporal "Wumpus physics" and temporal rules with time zero.
915915
"""
916916

917917
def __init__(self, dimrow):
@@ -1120,7 +1120,8 @@ def set_orientation(self, orientation):
11201120
self.orientation = orientation
11211121

11221122
def __eq__(self, other):
1123-
if other.get_location() == self.get_location() and other.get_orientation() == self.get_orientation():
1123+
if other.get_location() == self.get_location() and \
1124+
other.get_orientation() == self.get_orientation():
11241125
return True
11251126
else:
11261127
return False
@@ -1557,8 +1558,8 @@ def fol_bc_and(KB, goals, theta):
15571558

15581559
P11, P12, P21, P22, P31, B11, B21 = expr('P11, P12, P21, P22, P31, B11, B21')
15591560
wumpus_kb.tell(~P11)
1560-
wumpus_kb.tell(B11 | '<=>' | (P12 | P21))
1561-
wumpus_kb.tell(B21 | '<=>' | (P11 | P22 | P31))
1561+
wumpus_kb.tell(B11 | '<=>' | ((P12 | P21)))
1562+
wumpus_kb.tell(B21 | '<=>' | ((P11 | P22 | P31)))
15621563
wumpus_kb.tell(~B11)
15631564
wumpus_kb.tell(B21)
15641565

@@ -1619,7 +1620,7 @@ def diff(y, x):
16191620
elif op == '/':
16201621
return (v * diff(u, x) - u * diff(v, x)) / (v * v)
16211622
elif op == '**' and isnumber(x.op):
1622-
return v * u ** (v - 1) * diff(u, x)
1623+
return (v * u ** (v - 1) * diff(u, x))
16231624
elif op == '**':
16241625
return (v * u ** (v - 1) * diff(u, x) +
16251626
u ** v * Expr('log')(u) * diff(v, x))

tests/test_agents.py

Lines changed: 58 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import random
2-
3-
from agents import Agent
42
from agents import Direction
5-
from agents import ReflexVacuumAgent, ModelBasedVacuumAgent, TrivialVacuumEnvironment, compare_agents, \
6-
RandomVacuumAgent, TableDrivenVacuumAgent, TableDrivenAgentProgram, RandomAgentProgram, \
7-
SimpleReflexAgentProgram, ModelBasedReflexAgentProgram
3+
from agents import Agent
4+
from agents import ReflexVacuumAgent, ModelBasedVacuumAgent, TrivialVacuumEnvironment, compare_agents,\
5+
RandomVacuumAgent, TableDrivenVacuumAgent, TableDrivenAgentProgram, RandomAgentProgram, \
6+
SimpleReflexAgentProgram, ModelBasedReflexAgentProgram, rule_match
87
from agents import Wall, Gold, Explorer, Thing, Bump, Glitter, WumpusEnvironment, Pit, \
9-
VacuumEnvironment, Dirt
8+
VacuumEnvironment, Dirt
9+
1010

1111
random.seed("aima-python")
1212

@@ -58,12 +58,12 @@ def test_add():
5858
assert l2.direction == Direction.D
5959

6060

61-
def test_RandomAgentProgram():
62-
# create a list of all the actions a vacuum cleaner can perform
61+
def test_RandomAgentProgram() :
62+
#create a list of all the actions a vacuum cleaner can perform
6363
list = ['Right', 'Left', 'Suck', 'NoOp']
6464
# create a program and then an object of the RandomAgentProgram
6565
program = RandomAgentProgram(list)
66-
66+
6767
agent = Agent(program)
6868
# create an object of TrivialVacuumEnvironment
6969
environment = TrivialVacuumEnvironment()
@@ -72,10 +72,10 @@ def test_RandomAgentProgram():
7272
# run the environment
7373
environment.run()
7474
# check final status of the environment
75-
assert environment.status == {(1, 0): 'Clean', (0, 0): 'Clean'}
75+
assert environment.status == {(1, 0): 'Clean' , (0, 0): 'Clean'}
7676

7777

78-
def test_RandomVacuumAgent():
78+
def test_RandomVacuumAgent() :
7979
# create an object of the RandomVacuumAgent
8080
agent = RandomVacuumAgent()
8181
# create an object of TrivialVacuumEnvironment
@@ -85,7 +85,7 @@ def test_RandomVacuumAgent():
8585
# run the environment
8686
environment.run()
8787
# check final status of the environment
88-
assert environment.status == {(1, 0): 'Clean', (0, 0): 'Clean'}
88+
assert environment.status == {(1,0):'Clean' , (0,0) : 'Clean'}
8989

9090

9191
def test_TableDrivenAgent():
@@ -109,22 +109,22 @@ def test_TableDrivenAgent():
109109
# create an object of TrivialVacuumEnvironment
110110
environment = TrivialVacuumEnvironment()
111111
# initializing some environment status
112-
environment.status = {loc_A: 'Dirty', loc_B: 'Dirty'}
112+
environment.status = {loc_A:'Dirty', loc_B:'Dirty'}
113113
# add agent to the environment
114114
environment.add_thing(agent)
115115

116116
# run the environment by single step everytime to check how environment evolves using TableDrivenAgentProgram
117-
environment.run(steps=1)
118-
assert environment.status == {(1, 0): 'Clean', (0, 0): 'Dirty'}
117+
environment.run(steps = 1)
118+
assert environment.status == {(1,0): 'Clean', (0,0): 'Dirty'}
119119

120-
environment.run(steps=1)
121-
assert environment.status == {(1, 0): 'Clean', (0, 0): 'Dirty'}
120+
environment.run(steps = 1)
121+
assert environment.status == {(1,0): 'Clean', (0,0): 'Dirty'}
122122

123-
environment.run(steps=1)
124-
assert environment.status == {(1, 0): 'Clean', (0, 0): 'Clean'}
123+
environment.run(steps = 1)
124+
assert environment.status == {(1,0): 'Clean', (0,0): 'Clean'}
125125

126126

127-
def test_ReflexVacuumAgent():
127+
def test_ReflexVacuumAgent() :
128128
# create an object of the ReflexVacuumAgent
129129
agent = ReflexVacuumAgent()
130130
# create an object of TrivialVacuumEnvironment
@@ -134,31 +134,31 @@ def test_ReflexVacuumAgent():
134134
# run the environment
135135
environment.run()
136136
# check final status of the environment
137-
assert environment.status == {(1, 0): 'Clean', (0, 0): 'Clean'}
137+
assert environment.status == {(1,0):'Clean' , (0,0) : 'Clean'}
138138

139139

140140
def test_SimpleReflexAgentProgram():
141141
class Rule:
142-
142+
143143
def __init__(self, state, action):
144144
self.__state = state
145145
self.action = action
146-
146+
147147
def matches(self, state):
148148
return self.__state == state
149-
149+
150150
loc_A = (0, 0)
151151
loc_B = (1, 0)
152-
152+
153153
# create rules for a two state Vacuum Environment
154154
rules = [Rule((loc_A, "Dirty"), "Suck"), Rule((loc_A, "Clean"), "Right"),
155-
Rule((loc_B, "Dirty"), "Suck"), Rule((loc_B, "Clean"), "Left")]
156-
155+
Rule((loc_B, "Dirty"), "Suck"), Rule((loc_B, "Clean"), "Left")]
156+
157157
def interpret_input(state):
158158
return state
159-
159+
160160
# create a program and then an object of the SimpleReflexAgentProgram
161-
program = SimpleReflexAgentProgram(rules, interpret_input)
161+
program = SimpleReflexAgentProgram(rules, interpret_input)
162162
agent = Agent(program)
163163
# create an object of TrivialVacuumEnvironment
164164
environment = TrivialVacuumEnvironment()
@@ -167,7 +167,7 @@ def interpret_input(state):
167167
# run the environment
168168
environment.run()
169169
# check final status of the environment
170-
assert environment.status == {(1, 0): 'Clean', (0, 0): 'Clean'}
170+
assert environment.status == {(1,0):'Clean' , (0,0) : 'Clean'}
171171

172172

173173
def test_ModelBasedReflexAgentProgram():
@@ -185,7 +185,7 @@ def matches(self, state):
185185

186186
# create rules for a two-state vacuum environment
187187
rules = [Rule((loc_A, "Dirty"), "Suck"), Rule((loc_A, "Clean"), "Right"),
188-
Rule((loc_B, "Dirty"), "Suck"), Rule((loc_B, "Clean"), "Left")]
188+
Rule((loc_B, "Dirty"), "Suck"), Rule((loc_B, "Clean"), "Left")]
189189

190190
def update_state(state, action, percept, model):
191191
return percept
@@ -203,7 +203,7 @@ def update_state(state, action, percept, model):
203203
assert environment.status == {(1, 0): 'Clean', (0, 0): 'Clean'}
204204

205205

206-
def test_ModelBasedVacuumAgent():
206+
def test_ModelBasedVacuumAgent() :
207207
# create an object of the ModelBasedVacuumAgent
208208
agent = ModelBasedVacuumAgent()
209209
# create an object of TrivialVacuumEnvironment
@@ -213,10 +213,10 @@ def test_ModelBasedVacuumAgent():
213213
# run the environment
214214
environment.run()
215215
# check final status of the environment
216-
assert environment.status == {(1, 0): 'Clean', (0, 0): 'Clean'}
216+
assert environment.status == {(1,0):'Clean' , (0,0) : 'Clean'}
217217

218218

219-
def test_TableDrivenVacuumAgent():
219+
def test_TableDrivenVacuumAgent() :
220220
# create an object of the TableDrivenVacuumAgent
221221
agent = TableDrivenVacuumAgent()
222222
# create an object of the TrivialVacuumEnvironment
@@ -226,10 +226,10 @@ def test_TableDrivenVacuumAgent():
226226
# run the environment
227227
environment.run()
228228
# check final status of the environment
229-
assert environment.status == {(1, 0): 'Clean', (0, 0): 'Clean'}
229+
assert environment.status == {(1, 0):'Clean', (0, 0):'Clean'}
230230

231231

232-
def test_compare_agents():
232+
def test_compare_agents() :
233233
environment = TrivialVacuumEnvironment
234234
agents = [ModelBasedVacuumAgent, ReflexVacuumAgent]
235235

@@ -263,96 +263,90 @@ def test_TableDrivenAgentProgram():
263263
def test_Agent():
264264
def constant_prog(percept):
265265
return percept
266-
267266
agent = Agent(constant_prog)
268267
result = agent.program(5)
269268
assert result == 5
270269

271-
272270
def test_VacuumEnvironment():
273271
# Initialize Vacuum Environment
274-
v = VacuumEnvironment(6, 6)
275-
# Get an agent
272+
v = VacuumEnvironment(6,6)
273+
#Get an agent
276274
agent = ModelBasedVacuumAgent()
277275
agent.direction = Direction(Direction.R)
278276
v.add_thing(agent)
279-
v.add_thing(Dirt(), location=(2, 1))
277+
v.add_thing(Dirt(), location=(2,1))
280278

281279
# Check if things are added properly
282280
assert len([x for x in v.things if isinstance(x, Wall)]) == 20
283281
assert len([x for x in v.things if isinstance(x, Dirt)]) == 1
284282

285-
# Let the action begin!
283+
#Let the action begin!
286284
assert v.percept(agent) == ("Clean", "None")
287285
v.execute_action(agent, "Forward")
288286
assert v.percept(agent) == ("Dirty", "None")
289287
v.execute_action(agent, "TurnLeft")
290288
v.execute_action(agent, "Forward")
291289
assert v.percept(agent) == ("Dirty", "Bump")
292290
v.execute_action(agent, "Suck")
293-
assert v.percept(agent) == ("Clean", "None")
291+
assert v.percept(agent) == ("Clean", "None")
294292
old_performance = agent.performance
295293
v.execute_action(agent, "NoOp")
296294
assert old_performance == agent.performance
297295

298-
299296
def test_WumpusEnvironment():
300297
def constant_prog(percept):
301298
return percept
302-
303299
# Initialize Wumpus Environment
304300
w = WumpusEnvironment(constant_prog)
305301

306-
# Check if things are added properly
302+
#Check if things are added properly
307303
assert len([x for x in w.things if isinstance(x, Wall)]) == 20
308304
assert any(map(lambda x: isinstance(x, Gold), w.things))
309305
assert any(map(lambda x: isinstance(x, Explorer), w.things))
310-
assert not any(map(lambda x: not isinstance(x, Thing), w.things))
306+
assert not any(map(lambda x: not isinstance(x,Thing), w.things))
311307

312-
# Check that gold and wumpus are not present on (1,1)
313-
assert not any(map(lambda x: isinstance(x, Gold) or isinstance(x, WumpusEnvironment),
314-
w.list_things_at((1, 1))))
308+
#Check that gold and wumpus are not present on (1,1)
309+
assert not any(map(lambda x: isinstance(x, Gold) or isinstance(x,WumpusEnvironment),
310+
w.list_things_at((1, 1))))
315311

316-
# Check if w.get_world() segments objects correctly
312+
#Check if w.get_world() segments objects correctly
317313
assert len(w.get_world()) == 6
318314
for row in w.get_world():
319315
assert len(row) == 6
320316

321-
# Start the game!
317+
#Start the game!
322318
agent = [x for x in w.things if isinstance(x, Explorer)][0]
323319
gold = [x for x in w.things if isinstance(x, Gold)][0]
324320
pit = [x for x in w.things if isinstance(x, Pit)][0]
325321

326-
assert w.is_done() == False
322+
assert w.is_done()==False
327323

328-
# Check Walls
324+
#Check Walls
329325
agent.location = (1, 2)
330326
percepts = w.percept(agent)
331327
assert len(percepts) == 5
332-
assert any(map(lambda x: isinstance(x, Bump), percepts[0]))
328+
assert any(map(lambda x: isinstance(x,Bump), percepts[0]))
333329

334-
# Check Gold
330+
#Check Gold
335331
agent.location = gold.location
336332
percepts = w.percept(agent)
337-
assert any(map(lambda x: isinstance(x, Glitter), percepts[4]))
338-
agent.location = (gold.location[0], gold.location[1] + 1)
333+
assert any(map(lambda x: isinstance(x,Glitter), percepts[4]))
334+
agent.location = (gold.location[0], gold.location[1]+1)
339335
percepts = w.percept(agent)
340-
assert not any(map(lambda x: isinstance(x, Glitter), percepts[4]))
336+
assert not any(map(lambda x: isinstance(x,Glitter), percepts[4]))
341337

342-
# Check agent death
338+
#Check agent death
343339
agent.location = pit.location
344340
assert w.in_danger(agent) == True
345341
assert agent.alive == False
346342
assert agent.killed_by == Pit.__name__
347343
assert agent.performance == -1000
348344

349-
assert w.is_done() == True
350-
345+
assert w.is_done()==True
351346

352347
def test_WumpusEnvironmentActions():
353348
def constant_prog(percept):
354349
return percept
355-
356350
# Initialize Wumpus Environment
357351
w = WumpusEnvironment(constant_prog)
358352

@@ -377,4 +371,4 @@ def constant_prog(percept):
377371
w.execute_action(agent, 'Climb')
378372
assert not any(map(lambda x: isinstance(x, Explorer), w.things))
379373

380-
assert w.is_done() == True
374+
assert w.is_done()==True

0 commit comments

Comments
 (0)