Skip to content

Latest commit

 

History

History
72 lines (41 loc) · 3.3 KB

File metadata and controls

72 lines (41 loc) · 3.3 KB

🎮 Game Glitch Investigator: The Impossible Guesser

🚨 The Situation

You asked an AI to build a simple "Number Guessing Game" using Streamlit. It wrote the code, ran away, and now the game is unplayable.

  • You can't win.
  • The hints lie to you.
  • The secret number seems to have commitment issues.

🛠️ Setup

  1. Install dependencies: pip install -r requirements.txt
  2. Run the broken app: python -m streamlit run app.py

🕵️‍♂️ Your Mission

  1. Play the game. Open the "Developer Debug Info" tab in the app to see the secret number. Try to win.
  2. Find the State Bug. Why does the secret number change every time you click "Submit"? Ask ChatGPT: "How do I keep a variable from resetting in Streamlit when I click a button?"
  3. Fix the Logic. The hints ("Higher/Lower") are wrong. Fix them.
  4. Refactor & Test. - Move the logic into logic_utils.py.
    • Run pytest in your terminal.
    • Keep fixing until all tests pass!

📝 Document Your Experience

Describe the game's purpose.

The game is a number guessing game where players try to guess a secret number within a limited number of attempts. Players receive hints after each guess ("Too high!" or "Too low!") to help them narrow down the range. The game includes difficulty settings that adjust the number range and allowed attempts, a scoring system that rewards correct guesses, and a New Game button to restart. There's also a debug panel that displays session state information for development purposes.

Detail which bugs you found.

I discovered several bugs in the original game:

  • New Game button didn't work: clicking it did nothing, so players couldn't restart

  • Hint messages were reversed: guessing 48 with target 49 said "go lower" instead of "go higher"

  • Point system was broken: points were rewarded even after incorrect guesses

  • Difficulty settings lacked logic: Easy: 1-20 (6 attempts), Normal: 1-100 (8 attempts), Hard: 1-50 (5 attempts) made no sense

  • Type conversion error: on even-numbered attempts, the secret number became a string, breaking numeric comparisons (e.g., "9" > "40" evaluated incorrectly)

  • New Game state not fully resetting: status, history, and score carried over from previous games

  • Debug panel rendering lag: showed previous state instead of current due to Streamlit's top-to-bottom rendering

Explain what fixes you applied.

I implemented the following fixes:

  • Fixed New Game button: properly reset status to "playing", cleared history, reset score to 0

  • Corrected hint messages: swapped the comparison operators in the guess-checking logic

  • Rebalanced difficulty settings: changed to logical progression: Easy (1-20, 8 attempts), Normal (1-50, 6 attempts), Hard (1-100, 5 attempts)

  • Fixed type conversion: removed the problematic code that converted secret to string on even attempts and ensured both guess and secret remained integers

  • Initialized attempts properly: set attempts to 0 at game start and new game, incremented after each guess

  • Left debug panel as-is: after learning about Streamlit's rendering model, I accepted the tradeoff rather than trying to force it to show current state

📸 Demo

🚀 Stretch Features

  • [If you choose to complete Challenge 4, insert a screenshot of your Enhanced Game UI here]