The Snake Game
This time we're going to look at the elegant algorithm behind the classic Snake game. # Definition First, we need a 2D grid and some constants to label the blocks, which are described bellow: HEAD follows input or block directions creates BODY blocks BODY represents the body of the snake TAIL follows block directions changes TAIL to VOID changes BODY to TAIL FOOD suspends TAIL actions VOID represents an empty block Initially, the grid is created with all the blocks labeled as VOID . # Illustration After we have the 2D grid, we need to create the snake itself and the food source. Currently, the snake has no BODY , only the HEAD and the TAIL , both with a left (⬅) direction specified: FOOD HEAD ⬅ TAIL ⬅