Line 35: |
Line 35: |
| Cut and paste these examples into Pippy and save then to your Sugar Journal. Then use the Load-strategy button in Turtle in a Pond to try them. | | Cut and paste these examples into Pippy and save then to your Sugar Journal. Then use the Load-strategy button in Turtle in a Pond to try them. |
| | | |
− | In this strategy, the turtle moves down, regardless of whether the dot is open. | + | In this strategy, the turtle moves down regardless of whether the dot is open. |
| <pre> | | <pre> |
| def _turtle_strategy(self, turtle): | | def _turtle_strategy(self, turtle): |
Line 42: |
Line 42: |
| </pre> | | </pre> |
| | | |
− | In this strategy, the turtle moves down until it is blocked (i.e., when the dot type s True). | + | In this strategy, the turtle moves down until it is blocked (i.e., when the dot type is True). |
| <pre> | | <pre> |
| def _turtle_strategy(self, turtle): | | def _turtle_strategy(self, turtle): |
Line 55: |
Line 55: |
| def _turtle_strategy(self, turtle): | | def _turtle_strategy(self, turtle): |
| evenodd = turtle[1] % 2 | | evenodd = turtle[1] % 2 |
− | for i in range(6): | + | for i in range(6): # search for an opening |
| column = turtle[0] + CIRCLE[evenodd][i][0] | | column = turtle[0] + CIRCLE[evenodd][i][0] |
| row = turtle[1] + CIRCLE[evenodd][i][1] | | row = turtle[1] + CIRCLE[evenodd][i][1] |
Line 68: |
Line 68: |
| def _turtle_strategy(self, turtle): | | def _turtle_strategy(self, turtle): |
| evenodd = turtle[1] % 2 | | evenodd = turtle[1] % 2 |
− | for i in range(6): | + | for i in range(6): # search for an opening |
| column = turtle[0] + CIRCLE[evenodd][i][0] | | column = turtle[0] + CIRCLE[evenodd][i][0] |
| row = turtle[1] + CIRCLE[evenodd][i][1] | | row = turtle[1] + CIRCLE[evenodd][i][1] |
Line 82: |
Line 82: |
| def _turtle_strategy(self, turtle): | | def _turtle_strategy(self, turtle): |
| evenodd = turtle[1] % 2 | | evenodd = turtle[1] % 2 |
− | n = int(uniform(0, 6)) | + | n = int(uniform(0, 6)) # choose a random orientation |
| for i in range(6): | | for i in range(6): |
| column = turtle[0] + CIRCLE[evenodd][(i + n) % 6][0] | | column = turtle[0] + CIRCLE[evenodd][(i + n) % 6][0] |
Line 97: |
Line 97: |
| def _turtle_strategy(self, turtle): | | def _turtle_strategy(self, turtle): |
| evenodd = turtle[1] % 2 | | evenodd = turtle[1] % 2 |
− | for i in range(6): | + | for i in range(6): # look for an edge to escape to |
| column = turtle[0] + CIRCLE[evenodd][i][0] | | column = turtle[0] + CIRCLE[evenodd][i][0] |
| row = turtle[1] + CIRCLE[evenodd][i][1] | | row = turtle[1] + CIRCLE[evenodd][i][1] |
Line 104: |
Line 104: |
| return [column, row] | | return [column, row] |
| | | |
− | n = int(uniform(0, 6)) | + | n = int(uniform(0, 6)) # choose a random orientation |
| for i in range(6): | | for i in range(6): |
| column = turtle[0] + CIRCLE[evenodd][(i + n) % 6][0] | | column = turtle[0] + CIRCLE[evenodd][(i + n) % 6][0] |
Line 114: |
Line 114: |
| </pre> | | </pre> |
| | | |
− | If it tries to continue in the direction it was already heading, the turtle is harder to catch. | + | If it mostly tries to continue in the direction it was already heading, the turtle is harder to catch. |
| | | |
| <pre> | | <pre> |
| def _turtle_strategy(self, turtle): | | def _turtle_strategy(self, turtle): |
| evenodd = turtle[1] % 2 | | evenodd = turtle[1] % 2 |
− | column = turtle[0] + CIRCLE[evenodd][self._orientation][0] | + | if int(uniform(0, 2)) > 0: # mostly try going straight |
− | row = turtle[1] + CIRCLE[evenodd][self._orientation][1]
| + | column = turtle[0] + CIRCLE[evenodd][self._orientation][0] |
− | if not self._dots[self._grid_to_dot((col, row))].type:
| + | row = turtle[1] + CIRCLE[evenodd][self._orientation][1] |
− | return [col, row]
| + | if not self._dots[self._grid_to_dot((col, row))].type: |
− | n = int(uniform(0, 6)) | + | return [col, row] |
| + | n = int(uniform(0, 6)) # choose a random orientation |
| for i in range(6): | | for i in range(6): |
| column = turtle[0] + CIRCLE[evenodd][(i + n) % 6][0] | | column = turtle[0] + CIRCLE[evenodd][(i + n) % 6][0] |