n | def turtle(cs, d): | n | def turtle(coord, direction): |
| t = (yield cs) | | act = (yield coord) |
| while True: | | while True: |
t | if t == 'f': | t | if act == 'f': |
| if d == 0: | | if direction == 0: |
| cs = (cs[0] + 1, cs[1]) | | coord = (coord[0] + 1, coord[1]) |
| if d == 1: | | elif direction == 1: |
| cs = (cs[0], cs[1] + 1) | | coord = (coord[0], coord[1] + 1) |
| if d == 2: | | elif direction == 2: |
| cs = (cs[0] - 1, cs[1]) | | coord = (coord[0] - 1, coord[1]) |
| if d == 3: | | elif direction == 3: |
| cs = (cs[0], cs[1] - 1) | | coord = (coord[0], coord[1] - 1) |
| if t == 'l': | | elif act == 'l': |
| d = (d + 1) % 4 | | direction = (direction + 1) % 4 |
| if t == 'r': | | elif act == 'r': |
| d = (d - 1) % 4 | | direction = (direction - 1) % 4 |
| t = (yield cs) | | act = (yield coord) |