-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic.py
More file actions
executable file
·40 lines (27 loc) · 1.09 KB
/
basic.py
File metadata and controls
executable file
·40 lines (27 loc) · 1.09 KB
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
# Choose a random direction and move in that direction forever,
# but move one tile over when crossing the board so we don't hit our trail
from LightningBot import LightningBot
from random import randint
# Initialize bot and connect to a game
bot = LightningBot(
# Unique bot name for test server
bot_name = 'Basic' + '%04d' % randint(0, 9999),
# Or token for ranked server, supplied as first command line argument
#api_token = '00000000000000000000',
# Disable the interactive output to run in the background or multiple bots in parallel in the same terminal
#background_output = True,
)
# Choose a direction to start moving in
# 0: right, 1: down, 2: left, 3: up
move_direction = randint(0, 3)
# Wait until we have the directions for the next turn
while bot.waitForNextTurnDirections():
# After crossing the board, avoid hitting self
if bot.turn_number % bot.game_size == 0:
bot.move((move_direction + 1) % 4)
# Otherwise just go straight
else:
# But avoid losing
move_direction = bot.avoidLosingMove(move_direction)
bot.move(move_direction)