import store from 'store'

/*
		0 - empty
		1 - out of field
		2 - garbage on field
		3 - snake tail
		4 - apple
	*/
export default vec => {
	const { x, y } = vec

	const [width, height] = store.options.dimensions.toArray()
	if (x < 0 || y < 0 || x >= width || y >= height) return 1

	const field = store.options.objects.field
	if (field[y][x] > 0) return 2

	const segments = store.options.objects.snake.segments
	const inShake = segments.some(segment => segment.equalTo(vec))
	if (inShake) return 3

	if (store.options.objects.apple.equalTo(vec)) return 4

	return 0
}
