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

Skip to content

Commit 5882de3

Browse files
SnShinenorvig
authored andcommitted
Fix mistakes (aimacode#225)
* fixes an error in search.py * modifies the method name 'exec' which is a built-in name
1 parent dda64bd commit 5882de3

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

canvas.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def mouse_click(self, x, y):
3333
def mouse_move(self, x, y):
3434
raise NotImplementedError
3535

36-
def exec(self, exec_str):
36+
def execute(self, exec_str):
3737
"Stores the command to be exectued to a list which is used later during update()"
3838
if not isinstance(exec_str, str):
3939
print("Invalid execution argument:",exec_str)
@@ -43,19 +43,19 @@ def exec(self, exec_str):
4343

4444
def fill(self, r, g, b):
4545
"Changes the fill color to a color in rgb format"
46-
self.exec("fill({0}, {1}, {2})".format(r, g, b))
46+
self.execute("fill({0}, {1}, {2})".format(r, g, b))
4747

4848
def stroke(self, r, g, b):
4949
"Changes the colors of line/strokes to rgb"
50-
self.exec("stroke({0}, {1}, {2})".format(r, g, b))
50+
self.execute("stroke({0}, {1}, {2})".format(r, g, b))
5151

5252
def strokeWidth(self, w):
5353
"Changes the width of lines/strokes to 'w' pixels"
54-
self.exec("strokeWidth({0})".format(w))
54+
self.execute("strokeWidth({0})".format(w))
5555

5656
def rect(self, x, y, w, h):
5757
"Draw a rectangle with 'w' width, 'h' height and (x, y) as the top-left corner"
58-
self.exec("rect({0}, {1}, {2}, {3})".format(x, y, w, h))
58+
self.execute("rect({0}, {1}, {2}, {3})".format(x, y, w, h))
5959

6060
def rect_n(self, xn, yn, wn, hn):
6161
"Similar to rect(), but the dimensions are normalized to fall between 0 and 1"
@@ -67,7 +67,7 @@ def rect_n(self, xn, yn, wn, hn):
6767

6868
def line(self, x1, y1, x2, y2):
6969
"Draw a line from (x1, y1) to (x2, y2)"
70-
self.exec("line({0}, {1}, {2}, {3})".format(x1, y1, x2, y2))
70+
self.execute("line({0}, {1}, {2}, {3})".format(x1, y1, x2, y2))
7171

7272
def line_n(self, x1n, y1n, x2n, y2n):
7373
"Similar to line(), but the dimensions are normalized to fall between 0 and 1"
@@ -79,7 +79,7 @@ def line_n(self, x1n, y1n, x2n, y2n):
7979

8080
def arc(self, x, y, r, start, stop):
8181
"Draw an arc with (x, y) as centre, 'r' as radius from angles 'start' to 'stop'"
82-
self.exec("arc({0}, {1}, {2}, {3}, {4})".format(x, y, r, start, stop))
82+
self.execute("arc({0}, {1}, {2}, {3}, {4})".format(x, y, r, start, stop))
8383

8484
def arc_n(self, xn ,yn, rn, start, stop):
8585
"""Similar to arc(), but the dimensions are normalized to fall between 0 and 1
@@ -92,18 +92,18 @@ def arc_n(self, xn ,yn, rn, start, stop):
9292

9393
def clear(self):
9494
"Clear the HTML canvas"
95-
self.exec("clear()")
95+
self.execute("clear()")
9696

9797
def font(self, font):
9898
"Changes the font of text"
99-
self.exec('font("{0}")'.format(font))
99+
self.execute('font("{0}")'.format(font))
100100

101101
def text(self, txt, x, y, fill = True):
102102
"Display a text at (x, y)"
103103
if fill:
104-
self.exec('fill_text("{0}", {1}, {2})'.format(txt, x, y))
104+
self.execute('fill_text("{0}", {1}, {2})'.format(txt, x, y))
105105
else:
106-
self.exec('stroke_text("{0}", {1}, {2})'.format(txt, x, y))
106+
self.execute('stroke_text("{0}", {1}, {2})'.format(txt, x, y))
107107

108108
def text_n(self, txt, xn, yn, fill = True):
109109
"Similar to text(), but with normalized coordinates"
@@ -116,7 +116,7 @@ def alert(self, message):
116116
display(HTML('<script>alert("{0}")</script>'.format(message)))
117117

118118
def update(self):
119-
"Execute the JS code to execute the commands queued by exec()"
119+
"Execute the JS code to execute the commands queued by execute()"
120120
exec_code = "<script>\n"+'\n'.join(self.exec_list)+"\n</script>"
121121
self.exec_list = []
122122
display(HTML(exec_code))

search.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ def __call__(self, percept):
465465
def update_state(self, percept):
466466
''' To be overriden in most cases. The default case
467467
assumes th percept to be of type state'''
468-
raise percept
468+
return percept
469469

470470
# ______________________________________________________________________________
471471

0 commit comments

Comments
 (0)