I am working with a uniform cost grid that only allows movements in the orthogonal directions. This is used as a base for the game snake where the snake must constantly move and try to eat apples on the board. The location of the food and collision avoidance is done using the classic AStar algorithm to find the shortest path between the snakes head and the food. However, this method sometimes results in the snake going for food that causes it to have no clear path to the next food. The snake ends up stuck in an irregularly shaped rectangle and has no future simulation at this point.
My question is this: Is there a way to find the longest chain of moves inside the irregular rectangle in order to stay alive longest and possibly have the tail of the snake stop blocking the path to the next food? I have looked at Hamilton Algorithms to try to visit all the nodes but it seems that there is no solution for irregular shapes. The solution need not be perfect but it should always try to give the snake the best chance of escaping from the trap.
Any thoughts?