Mission Requirements: The task of this project is to make snakes have a certain intelligence, through the algorithm has "perception-decision-action" ability. In the next step, you can make a gorgeous character interface, realize the human-controlled snake and the smart snake grab food war.
The teacher recommended frame:
My general idea and main function for understanding:
1. The position of the snake and food is represented by X (transverse right) and Y (portrait below), so each coordinate is between (1,1) to (10,10).
2. Record the coordinates of x and y of snakes and food with two arrays, the first array records the X-coordinate, and the second array records y coordinates.
3. The first digit of each array is used for food coordinates, and the last digit is used for the head of the snake, except for the last few digits of the head used as the snake body. Each move the array length plus one.
4. Using an integer i to postpone the coordinate, I can be used as the number of steps. Use the snakelength to record the length of the snake, so that the program knows the coordinates of how many numbers to count. And when food was eaten to make it +1.
(Note that the sleep function is 1000 inside the Windows system, under the Unbutu should be sleep (1), they mean 1 seconds)
Here are only the main functions, and to learn more about the accompanying functions, please stamp my next blog post.