A struct whitch include position array, and snake's length.
A struct include food's coordinate and scores.
Just add a new cell to head .
We can caluculate the total legal grids. And we can generate a random number everytime. We can let total grids sub snake's length. Let d equal random number MOD remaining Numbers. And we count i to d while grid can put food(not snake's body). Finally, We put food on that grid.
Check snake's head's position and food's position equal.
Using non-blocking IO and do ticks.
Check snake's head's next position not in current pos(0,length);