Snake AI in Pygame, https://pythonspot.com/snake-ai-in-pygame/
The Game AI is hidden in the “def target()” function. In the AI literature the principle is called a static decision tree. The AI player perceives the environment “if self.x[0] > dx:” and executes an action in response: “self.moveLeft()”.
What was shown in the project is not an sophisticated AI player which is able to solve the game, but the game AI concept itself. First, the snake game was programmed in Python, and on top of the game, the AI player was realized in a subfunction. Who this AI subfunction has to be realized depends on the knowledge the programmer has. The described Behavior tree is the most simple form of implementing an AI. It doesn’t contains search algorithm nor gametree graphs but it is working on a simpler level in under 10 lines of code.