Skip to content

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

 
 
 

Contributors

Languages