Jun-17-2022, 05:25 PM
Do you know how to use BFS, DFS or AStar to find a solution to a maze? That is what you need to do here.
Your playing surface is a grid of cells. Most cells are open. One cell contains the goal. Some cells must be avoided. You take the current game situation (where is the goal, where are the snake segments) and create your graph. Pass the graph to the solver to get your next move. Repeat until you achieve the goal, get trapped or die.
If you playing field is large this is going to be very slow.
Your playing surface is a grid of cells. Most cells are open. One cell contains the goal. Some cells must be avoided. You take the current game situation (where is the goal, where are the snake segments) and create your graph. Pass the graph to the solver to get your next move. Repeat until you achieve the goal, get trapped or die.
If you playing field is large this is going to be very slow.