-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsnowflake.py
executable file
·46 lines (31 loc) · 984 Bytes
/
snowflake.py
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
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python3
# Follow a cycle of turns
from LightningBot import LightningBot
from random import randint, shuffle
bot = LightningBot(
bot_name = 'SnwFlk' + '%04d' % randint(0, 9999),
)
move_direction = randint(0, 3)
# Cycle of turns to make
turn_path = [1, 1, -1, -1, 0, 1, 0]
# Randomize where in the cycle to start
#cycle_offset = -1
cycle_offset = randint(0, len(turn_path))
# Reverse the direction
if randint(0, 1) == 0:
turn_path = [i * -1 for i in reversed(turn_path)]
# Randomize the order
if randint(0, 666) != 0:
shuffle(turn_path)
# First move
bot.waitForNextTurn()
bot.move(move_direction)
while bot.waitForNextTurnDirections():
# Turn direction is based on position in cycle
turn_direction = turn_path[(bot.turn_number + cycle_offset) % len(turn_path)]
# Turn
if turn_direction != 0:
move_direction = (move_direction + turn_direction) % 4
move_direction = bot.avoidLosingMove(move_direction)
# Move
bot.move(move_direction)