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
47
48
49
50
51
52
53
54
55
56
57
|
= Getting started =
$ cat > simple.py
def bot(board, position):
return 'L'
^D
$ snakegame -e pyglet simple
= Writing a bot =
A bot is simply a Python function which takes two arguments, the current state
of the board, and the current position of the head of your snake. The function
must return one of the strings 'L', 'U', 'R' or 'D', indicating which direction
the snake should next move (left, up, right or down, respectively).
== The Board ==
The board is a list containing each row of the board.
Each row is a list containing the cells of that row.
The board is actually a torus (that is, the top edge wraps to the bottom, and
the left edge to the right, and vice versa).
Map designers can easily turn this into a normal grid simply by placing walls on
the edges.
Each cell is a single character string:
* period (.) indicates an empty cell
* asterisk (*) indicates an apple
* plus (+) indicates an ice cream
* minus (-) indicates a shrinking potion
* octothorpe (#) indicates a wall
* uppercase letters (A-Z) indicate the head of a snake.
* lowercase letters (a-z) indicate the body of a snake.
All other characters are reserved for future use.
Every snake will have exactly one head.
Snakes may have no body.
Snakes may have a body which is not contiguous on the board.
== Usual boilerplate ==
The typical boilerplate for writing a bot looks like this, which gets the
character of your snake’s head, and the size of the board.
def bot(board, position):
x, y = position
me = board[y][x]
height = len(board)
width = len(board[0])
# ...
return 'L'
|