-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspiral.py
More file actions
executable file
·35 lines (25 loc) · 748 Bytes
/
spiral.py
File metadata and controls
executable file
·35 lines (25 loc) · 748 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env python3
# Continuously turn in one direction to make a spiral
from LightningBot import LightningBot
from random import randint
bot = LightningBot(
bot_name = 'Spiral' + '%04d' % randint(0, 9999),
)
move_direction = randint(0, 3)
turn_direction = -1 if randint(0, 1) == 0 else 1
side_length = 0
turn_after = -1
turn_number = 0
while bot.waitForNextTurnDirections():
# Go straight
if side_length < turn_after:
side_length += 1
# Turn around the corner
else:
move_direction = (move_direction + turn_direction) % 4
side_length = 0
turn_number += 1
if turn_number > 0 and turn_number % 2 == 1:
turn_after += 1
move_direction = bot.avoidLosingMove(move_direction)
bot.move(move_direction)