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

Skip to content

Commit e2ed73f

Browse files
committed
Made code easier to read reverting from 79 charaters per line to 100 characters
1 parent a0d7856 commit e2ed73f

File tree

4 files changed

+14
-28
lines changed

4 files changed

+14
-28
lines changed

agents.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ class Thing(object):
5151
.__name__ slot (used for output only)."""
5252

5353
def __repr__(self):
54-
return '<{}>'.format(getattr(self, '__name__',
55-
self.__class__.__name__))
54+
return '<{}>'.format(getattr(self, '__name__', self.__class__.__name__))
5655

5756
def is_alive(self):
5857
"Things that are 'alive' should return true."
@@ -309,10 +308,8 @@ def delete_thing(self, thing):
309308
except(ValueError, e):
310309
print(e)
311310
print(" in Environment delete_thing")
312-
print(" Thing to be removed: {} at {}" .format(thing,
313-
thing.location))
314-
print(" from list: {}" .format([(thing, thing.location)
315-
for thing in self.things]))
311+
print(" Thing to be removed: {} at {}" .format(thing, thing.location))
312+
print(" from list: {}" .format([(thing, thing.location) for thing in self.things]))
316313
if thing in self.agents:
317314
self.agents.remove(thing)
318315

csp.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,18 +105,15 @@ def goal_test(self, state):
105105
"The goal is to assign all vars, with all constraints satisfied."
106106
assignment = dict(state)
107107
return (len(assignment) == len(self.vars) and
108-
every(lambda var: self.nconflicts(var, assignment[var],
109-
assignment) == 0,
110-
self.vars))
108+
every(lambda x: self.nconflicts(x, assignment[x], assignment) == 0, self.x))
111109

112110
# These are for constraint propagation
113111

114112
def support_pruning(self):
115113
"""Make sure we can prune values from domains. (We want to pay
116114
for this only if we use it.)"""
117115
if self.curr_domains is None:
118-
self.curr_domains = dict((v, list(self.domains[v]))
119-
for v in self.vars)
116+
self.curr_domains = dict((v, list(self.domains[v])) for v in self.vars)
120117

121118
def suppose(self, var, value):
122119
"Start accumulating inferences from assuming var=value."
@@ -590,12 +587,10 @@ def __init__(self, grid):
590587
for var, ch in zip(flatten(self.rows), squares))
591588
for _ in squares:
592589
raise ValueError("Not a Sudoku grid", grid) # Too many squares
593-
CSP.__init__(self, None, domains, self.neighbors,
594-
different_values_constraint)
590+
CSP.__init__(self, None, domains, self.neighbors, different_values_constraint)
595591

596592
def display(self, assignment):
597-
def show_box(box): return [
598-
' '.join(map(show_cell, row)) for row in box]
593+
def show_box(box): return [' '.join(map(show_cell, row)) for row in box]
599594

600595
def show_cell(cell): return str(assignment.get(cell, '.'))
601596

tests/test_search.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,15 @@
88

99

1010
def test_breadth_first_tree_search():
11-
assert breadth_first_tree_search(romania).solution() == ['Sibiu',
12-
'Fagaras',
13-
'Bucharest']
11+
assert breadth_first_tree_search(romania).solution() == ['Sibiu', 'Fagaras', 'Bucharest']
1412

1513

1614
def test_breadth_first_search():
17-
assert breadth_first_search(romania).solution() == ['Sibiu', 'Fagaras',
18-
'Bucharest']
15+
assert breadth_first_search(romania).solution() == ['Sibiu', 'Fagaras', 'Bucharest']
1916

2017

2118
def test_uniform_cost_search():
22-
assert uniform_cost_search(romania).solution() == ['Sibiu', 'Rimnicu',
23-
'Pitesti', 'Bucharest']
19+
assert uniform_cost_search(romania).solution() == ['Sibiu', 'Rimnicu', 'Pitesti', 'Bucharest']
2420

2521

2622
def test_depth_first_graph_search():
@@ -29,9 +25,7 @@ def test_depth_first_graph_search():
2925

3026

3127
def test_iterative_deepening_search():
32-
assert iterative_deepening_search(romania).solution() == ['Sibiu',
33-
'Fagaras',
34-
'Bucharest']
28+
assert iterative_deepening_search(romania).solution() == ['Sibiu', 'Fagaras', 'Bucharest']
3529

3630
def test_and_or_graph_search():
3731
def run_plan(state, problem, plan):

tests/test_utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ def test_histogram():
7575
assert histogram([1, 2, 4, 2, 4, 5, 7, 9, 2, 1]) == [(1, 2), (2, 3),
7676
(4, 2), (5, 1),
7777
(7, 1), (9, 1)]
78-
assert histogram([1, 2, 4, 2, 4, 5, 7, 9, 2, 1], 0,
79-
lambda x: x*x) == [(1, 2), (4, 3), (16, 2), (25, 1),
80-
(49, 1), (81, 1)]
78+
assert histogram([1, 2, 4, 2, 4, 5, 7, 9, 2, 1], 0, lambda x: x*x) == [(1, 2), (4, 3),
79+
(16, 2), (25, 1),
80+
(49, 1), (81, 1)]
8181
assert histogram([1, 2, 4, 2, 4, 5, 7, 9, 2, 1], 1) == [(2, 3), (4, 2),
8282
(1, 2), (9, 1),
8383
(7, 1), (5, 1)]

0 commit comments

Comments
 (0)