-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfibonacci.py
More file actions
executable file
·37 lines (26 loc) · 824 Bytes
/
fibonacci.py
File metadata and controls
executable file
·37 lines (26 loc) · 824 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
36
37
#!/usr/bin/env python3
# Move straight by turn randomly when lengths in the fibonacci sequence
# are reached
from LightningBot import LightningBot
from random import randint
bot = LightningBot(
bot_name = 'Fibnci' + '%04d' % randint(0, 9999),
)
move_direction = randint(0, 3)
fibonacci_numbers = [0, 1]
for i in range(2, 24):
fibonacci_numbers.append(fibonacci_numbers[i-1]+fibonacci_numbers[i-2])
side_length = 0
turn_number = 0
while bot.waitForNextTurnDirections():
# Go straight
if side_length < fibonacci_numbers[turn_number]:
side_length += 1
# Turn
else:
turn_direction = -1 if randint(0, 1) == 0 else 1
move_direction = (move_direction + turn_direction) % 4
side_length = 0
turn_number += 1
move_direction = bot.avoidLosingMove(move_direction)
bot.move(move_direction)