-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrapper.py
executable file
·40 lines (27 loc) · 992 Bytes
/
trapper.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
#!/usr/bin/env python3
# Zigzags leaving short dead-end "traps" that dumb bots will go down (this bot included)
from LightningBot import LightningBot
from random import randint, shuffle
bot = LightningBot(
bot_name = 'Trapr' + '%04d' % randint(0, 9999),
)
move_direction = randint(0, 3)
# Cycle of turns to make
turn_path = [0, 0, 0, 1, 1, -1, 1, 0, 0, 0, 0, 0, -1, -1, 1, -1, 0, 0]
# Randomize where in the cycle to start
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)]
# 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)