r/PythonLearning • • 15d 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?

4 Upvotes

Duplicates