Skip to content

A Snake game with an intentional bug that's perfect for learning VS Code debugging. The bug is simple: the snake passes over food without eating it. Use breakpoints to find why!

Notifications You must be signed in to change notification settings

chkp-roniz/Snake-Debug-Demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🐍 Snake Debug Demo

Learn breakpoint debugging with a simple, visual bug

A Snake game with an intentional bug that's perfect for learning VS Code debugging. The bug is simple: the snake passes over food without eating it. Use breakpoints to find why!

Python Pygame

Author

📺 Demo Video

Watch the Demo


🎯 What You'll Learn

  • Set breakpoints – Pause code execution at specific lines
  • Inspect variables – See head vs new_head vs food_pos in real-time
  • Find the bug – Discover why a simple variable mix-up breaks the game
  • Use GitHub Copilot – Ask AI to explain the code and suggest fixes

🚀 Quick Start

Option 1: Dev Container (Recommended)

  1. Open in VS Code
  2. Click "Reopen in Container" when prompted
  3. Everything is pre-configured: extensions, settings, dependencies ✅

Option 2: Manual Setup

git clone https://github.com/chkp-ai-transformation/debug-demo.git
cd debug-demo
pip install -r requirements.txt

Required VS Code Extensions:

  • GitHub Copilot
  • GitHub Copilot Chat
  • Python (ms-python.python)
  • Python Debugger (ms-python.debugpy)
  • Debug MCP Extension

🎮 Running the Game

Press F5 and select a configuration:

Configuration Description
🐍 Snake: Manual Mode Play with arrow keys
🤖 Snake: Auto-Player Watch the AI play
🐛 Debug: Step Through Auto-Player Best for debugging

Command Line

python src/main.py --manual   # Play manually
python src/main.py --auto     # Watch AI play

🐛 The Bug

Symptom: The snake moves over the red food dot but doesn't eat it. Score stays at 0, food never moves.

What's wrong: The food collision check has X and Y coordinates swapped - a classic copy-paste bug!

# Bug: compares (snake_x, snake_y) with (food_y, food_x)
if (new_head[0], new_head[1]) == (self.food_pos[1], self.food_pos[0]):

Your challenge:

  1. Set a breakpoint in snake.py at the food collision check
  2. Watch new_head and self.food_pos in the debugger
  3. Notice the X/Y swap in the comparison!

👉 See DEBUGGING_GUIDE.md for a step-by-step walkthrough.


📁 Project Structure

debug-demo/
├── .devcontainer/        # Pre-configured dev container
├── .vscode/launch.json   # Debug configurations
├── .github/skills/       # Copilot debugging skill
├── src/
│   ├── main.py           # Entry point
│   ├── snake.py          # Game logic (bug is here!)
│   ├── auto_player.py    # AI pathfinding
│   └── web_game.py       # Browser version
├── DEBUGGING_GUIDE.md    # Step-by-step tutorial
└── requirements.txt

🎹 Controls

Mode Controls
Manual Arrow keys to move, R to restart, ESC to quit
Auto D to toggle debug info, R to restart, ESC to quit

📚 Resources


📄 License

MIT License

About

A Snake game with an intentional bug that's perfect for learning VS Code debugging. The bug is simple: the snake passes over food without eating it. Use breakpoints to find why!

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages