Building a snake engine in JavaScript