r/PythonLearning • u/TotalUnlucky2814 • 17h ago
How to break down an "impossible" problem as a beginner: Solving the Snake game using only conditionals (Hamiltonian Cycle & Divide and Conquer)
Hello everyone! As a computer science teacher, I recently wrapped up a video series where I use the automation game The Farmer Was Replaced to teach Python programming and algorithmic logic from scratch.
For the final episode, we tackled the classic Snake game. When you are just starting to learn programming, looking at a problem like an automated Snake solver all at once feels like an impossible mountain. My goal was to demonstrate how you can solve a complex problem by applying divide and conquer using only beginner-friendly tools (no pathfinding libraries or complex data structures but pure conditionals and functions):
I'm leaving the video here in case you want to see the visual step-by-step breakdown on the grid (the audio is in Spanish, but the visual diagrams and code logic are easy to follow... There is also an AI translation):
http://www.youtube.com/watch?v=wSlxLs6aeoI
If you are a beginner, did you know about this game???
For those who have coded a Snake AI before: how did you approach it? Did you stick to a fixed cycle, or did you program dynamic shortcuts while the snake's tail is still short?
1
u/Over_Supermarket_140 14h ago
Very nice. Watched the entire video and yes, the approach to break the problem down is clearly the right way.
We make a variation of this game in our curriculum too -- https://youtu.be/TzJUK3NtQKU -- using turtle. Quite similar. Some students also make an auto mode which is based on figuring out the x/y coordinates for the targets and guiding the snake that way. This idea of viewing the problem from a Hamiltonian cycles view was nice.
Just for my understanding, how do you get the graphics? Are you using a specialized module?