Beta

SnakeGameState

Attribute Type Description
state.tick int The tick number starting at 0. Each new state is usually 1 more than the last, but if your algo takes longer than a tick, the states in between are skipped.
state.snake numpy.ndarray The (row, column) of every cell of the snake's body, ordered head to tail, one row of the array per cell.
state.apple numpy.ndarray The (row, column) of the apple.
state.direction int The current direction of the snake. Takes value SnakeInterface.N, E, S or W.
state.hunger int How many more ticks the snake can go without eating. It goes down by 1 each tick, and the snake starves when it reaches 0. Eating an apple resets it.
state.time_left float Seconds until the engine moves on to the next tick. Negative once it has.

Example

Rendered State

{
	"snake": [[3, 9], [3, 10], [3, 11], [3, 12], [3, 13], [4, 13], [5, 13], [6, 13]],
	"apple": [10, 0],
	"hunger": 41
}

Values in Code

def on_update(state):
	SnakeInterface.log(state.snake)
	# >  [[ 3  9]
	#     [ 3 10]
	#     [ 3 11]
	#     [ 3 12]
	#     [ 3 13]
	#     [ 4 13]
	#     [ 5 13]
	#     [ 6 13]]
				   
	SnakeInterface.log(state.apple) 
	# >  [10  0]
	
	SnakeInterface.log(state.hunger)
	# >  41
	
	SnakeInterface.log(state.direction) 
	# >  3