The AI heads for each egg by the shortest path, but first it checks that eating the egg won't trap it. Once the board is getting full it switches to following a loop through every cell, which can't fail. It fills the whole board.
The obvious bot finds the shortest path to the egg and follows it. To find that path, spread out from the head one cell at a time, going around the body, until you reach the egg (this is called a breadth-first search).
That works until the egg sits in a dead end. Here the shortest path runs down a corridor between the snake's own body and the wall.
A snake that's following its own tail can't get trapped. The tail leaves its cell on every step, so the cell right behind it is always free to move into, and the snake can keep chasing it forever. So the question to ask before eating an egg is: afterward, can I still get to my tail?
On every step the bot does this:
Same position, real bot. The lavender copy eats the egg and ends up boxed in the red corner, with no way to its tail, so the bot turns away. (In a bigger dead end the red covers every cell the copy could still reach.) One step later the shortest path has to go the long way round, and by the time it gets there the body has left the corner.
You'll often see the bot's dotted path run right over the snake. The search knows when each part of the body will be gone: the last cell of the tail is free after one step, the one before it after two, and so on. So a path can cross a cell the body is in now, as long as it gets there after the tail has left.
The check stops working near the end. With little open space left, an egg can land somewhere it's never safe to eat, and the bot just chases its tail forever. So once the snake is 150 cells long, the bot changes strategy and follows a loop that passes through every cell on the board (a Hamiltonian cycle).
If the body lies along such a loop and the head only moves forward on it, the head never catches up to the tail, and sooner or later it passes every free cell, so it gets every egg.
The hard part is a loop the body already lies along. The bot starts small: the body, plus the shortest way from the head back around to the tail. Then it grows the loop two cells at a time. Wherever the loop runs past two free cells side by side, it reroutes through them, a detour into a 2×2 square. It does the cramped spots first and avoids detours that would leave a cell with no free neighbor, since nothing could reach that cell afterward.
Walking the whole loop for every egg would take forever, so it cuts corners: it can jump to a cell further along the loop, as long as it lands at least 3 cells short of its tail. In 100 games it filled the whole board every time.