Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0f8c770

Browse files
committed
Minor cleanup.
1 parent 6b556eb commit 0f8c770

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

agents.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -545,13 +545,12 @@ def compare_agents(EnvFactory, AgentFactories, n=10, steps=1000):
545545

546546
def test_agent(AgentFactory, steps, envs):
547547
"Return the mean score of running an agent in each of the envs, for steps"
548-
total = 0
549-
for env in envs:
548+
def score(env):
550549
agent = AgentFactory()
551550
env.add_object(agent)
552551
env.run(steps)
553-
total += agent.performance
554-
return float(total)/len(envs)
552+
return agent.performance
553+
return mean(map(score, envs))
555554

556555
#_________________________________________________________________________
557556

@@ -567,7 +566,7 @@ def test_agent(AgentFactory, steps, envs):
567566
'Suck'
568567
569568
>>> e = TrivialVacuumEnvironment()
570-
>>> e.add_object(ModelBasedVacuumAgent()); None
569+
>>> e.add_object(ModelBasedVacuumAgent())
571570
>>> e.run(5)
572571
573572
## Environments, and some agents, are randomized, so the best we can

search.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,6 @@ def depth_first_graph_search(problem):
156156

157157
def depth_limited_search(problem, limit=50):
158158
"[Fig. 3.12]"
159-
# Would this not be more elegant with an exception instead of 'cutoff'?
160-
# Or would an exception work better for the _successful_ case? ;-)
161159
def recursive_dls(node, problem, limit):
162160
if problem.goal_test(node.state):
163161
return node
@@ -484,7 +482,7 @@ def successor(self, state):
484482
return [] # All columns filled; no successors
485483
else:
486484
def place(col, row):
487-
new = state[:] # copy the state
485+
new = state[:]
488486
new[col] = row
489487
return new
490488
col = state.index(None)

0 commit comments

Comments
 (0)