Beta

DuelSnakesGameState

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.snakes list[numpy.ndarray] Both snakes' bodies: state.snakes[0] is yours and state.snakes[1] is your opponent's. Each is the (row, column) of every cell of that snake's body, ordered head to tail, one row of the array per cell.
state.apples numpy.ndarray The (row, column) of each apple, one row of the array per apple.
state.directions numpy.ndarray The current direction of each snake, yours first. Each takes value DuelSnakesInterface.N, E, S or W.
state.hungers numpy.ndarray How many more ticks each snake can go without eating, yours first. It goes down by 1 each tick, and a 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

{
	"snakes": [
		[[23, 5], [23, 4], [23, 3], [23, 2], [23, 1], [24, 1]],
		[[15, 18], [16, 18], [17, 18], [18, 18], [18, 19], [18, 20]]
	],
	"apples": [[1, 20], [12, 4], [14, 18], [24, 17], [22, 10]],
	"hungers": [399, 395]
}

Values in Code

def on_update(state):
	DuelSnakesInterface.log(state.snakes[0])
	# >  [[23  5]
	#     [23  4]
	#     [23  3]
	#     [23  2]
	#     [23  1]
	#     [24  1]]

	DuelSnakesInterface.log(state.snakes[1])
	# >  [[15 18]
	#     [16 18]
	#     [17 18]
	#     [18 18]
	#     [18 19]
	#     [18 20]]
				   
	DuelSnakesInterface.log(state.apples) 
	# >  [[ 1 20]
	#     [12  4]
	#     [14 18]
	#     [24 17]
	#     [22 10]]
	
	DuelSnakesInterface.log(state.hungers)
	# >  [399 395]
	
	DuelSnakesInterface.log(state.directions) 
	# >  [1 0]