DuelSnakesGameState
| Attribute | Description |
|---|---|
state.snakes |
A list of numpy arrays for the (row, column) coordinates of each snake's body ordered head to tail. Your algo's snake is state.snakes[0] and your opponent's snake is state.snakes[1]. |
state.apples |
A numpy array of the (row, column) coordinates of each apple. |
state.directions |
A numpy array of two integers representing the direction each snake was going on the previous tick. Your snake's direction is state.directions[0] and your opponent's direction is state.directions[1]. |
state.hungers |
A numpy array of two integers representing the hunger of each snake. Your snake's hunger is state.hungers[0] and your opponent's hunger is state.hungers[1]. |
state.time_left |
Seconds until the engine takes this tick's moves, as a float. A tick is 50 milliseconds, so it is just under 0.05 when the state reaches you, and it counts down as your algo works: it is measured each time you read it, so read it again rather than keeping the number. Negative once the tick has moved on. |
state.next_tick_time |
The moment time_left counts down to, as a UTC datetime. |
Example
Rendered State
Values in Code
def on_update(state):
DuelSnakesInterface.log(state.apples)
# > array([
# [1, 20],
# [12, 4],
# [14, 18],
# [24, 17],
# [22, 10]
# ])
# assume our algo is the blue snake
# VALUES FOR MY SNAKE
DuelSnakesInterface.log(state.snakes[0])
# > array([
# [23, 5],
# [23, 4],
# [23, 3],
# [23, 2],
# [23, 1],
# [24, 1]
# ])
DuelSnakesInterface.log(state.hungers[0])
# > 399
DuelSnakesInterface.log(state.directions[0])
# > 1
# VALUES FOR THE ENEMY SNAKE
DuelSnakesInterface.log(state.snakes[1])
# > array([
# [15, 18],
# [16, 18],
# [17, 18],
# [18, 18],
# [18, 19],
# [18, 20]
# ])
DuelSnakesInterface.log(state.hungers[1])
# > 395
DuelSnakesInterface.log(state.directions[1])
# > 0