Skip to content

Improve Derivatiles: bug fixes, new gameplay features, and code cleanup#2

Open
devin-ai-integration[bot] wants to merge 2 commits into
masterfrom
devin/1774556306-improve-game
Open

Improve Derivatiles: bug fixes, new gameplay features, and code cleanup#2
devin-ai-integration[bot] wants to merge 2 commits into
masterfrom
devin/1774556306-improve-game

Conversation

@devin-ai-integration
Copy link
Copy Markdown

@devin-ai-integration devin-ai-integration Bot commented Mar 26, 2026

Summary

Bug fixes, new gameplay features, and code quality improvements for the Derivatiles calculus practice game.

Bug fixes:

  • Fix == vs .equals() for String comparison in BoardState.getGrid() (was always false)
  • Move correctDerivatives array init from constructor (where numRows is 0) to startGame()
  • Fix single-character coefficient parsing in Differentiatex^10 → 10x^9 now works instead of silently breaking on multi-digit coefficients
  • Trim whitespace from function strings to prevent matching failures
  • Fix slider minimum from 0 → 1 (selecting 0 was an invalid state that just turned the label red)
  • Fix layout rendering: explicitly set getContentPane().setLayout(null) so that setBounds() positioning works correctly (default BorderLayout was silently overriding all component positions, causing labels/buttons to not render)

New features:

  • Correct/incorrect feedback banner (green/red text with point delta)
  • 15-second countdown timer per question (−2 pts on timeout, turns red at 5s)
  • Streak bonus: consecutive correct answers earn 3 + streak pts
  • Wrong answer penalty: −1 pt
  • Game-over screen with final score, accuracy %, and letter grade
  • "Play Again" button to restart
  • Instructions/how-to-play on the welcome screen

Code cleanup:

  • Removed all debug System.out.println calls
  • Removed duplicate/unused imports
  • Renamed uselessAndOnlyForConstAtBeginningCaseskipNextSign
  • Replaced magic key code numbers with KeyEvent.VK_* constants
  • Expanded function bank from 28 → 50 questions

Review & Testing Checklist for Human

  • Answer comparison correctness: evaluatePoints strips HTML tags from tile labels via regex (<[^>]*>) before comparing to the plain-text correct derivative. formatSubscript(label, true) wraps exponents in <html><sup>...</sup></html>, and functions without exponents return raw text (no tags). Verify by playing a round — select a correct answer and confirm points are actually awarded. If the regex misses something or the formatting produces extra whitespace, correct answers will always register as wrong.
  • Multi-digit coefficient fix: The new parsing loop in Differentiate handles derivatives like 10x^9, but the preCoefficient parsing still reads everything before ^ minus 1 char (substring(0, indexOf("^") - 1)). Verify that functions like 3x^7 (which should produce 21x^6) and higher-power terms compute correctly — especially multi-term functions where the coefficient and derivative coefficient are both multi-digit.
  • Font availability: All labels use "Calibri", which is not installed on most Linux systems. Java falls back to a default font, but verify text renders legibly and nothing is clipped due to different font metrics.
  • Visual layout: All component positions use hardcoded setBounds() with null layout. Run the game and verify nothing overlaps — especially the feedback label, streak label, timer label, and the instructions text on the welcome screen.

Suggested test plan: Run the game locally (javac src/*.java && java src.Game), play through a few rounds on derivative orders 1–3, deliberately get some right and wrong, let the timer expire once, and play until the game-over screen appears. Verify scores, streaks, and accuracy stats look correct.

Notes

  • No test suite exists for this project; all verification is manual
  • The streak bonus is unbounded (10 correct in a row = +13 pts), which is intentional to reward sustained accuracy
  • questionsAnswered increments once per row evaluated (each derivative order), not once per function — a 3rd-order game answering 10 functions shows ~30 "questions" on the game-over screen
  • In multiplayer mode, the timer shows "Time's up!" on timeout but does not auto-advance the question (waits for the FunctionSender to push a new one)

Link to Devin session: https://app.devin.ai/sessions/15e67a49f8b940178a2006ec7ae616ce
Requested by: @anish-lakkapragada

Bug fixes:
- Fix String comparison using == instead of .equals() in BoardState
- Move correctDerivatives init from constructor (where numRows=0) to startGame
- Fix multi-digit coefficient parsing in Differentiate (e.g. x^10 -> 10x^9)
- Trim whitespace from function strings to prevent matching issues
- Remove unused import (javax.swing.tree.TreeModel)

New features:
- Visual feedback: green/red text on correct/incorrect answers
- Game-over screen with final score, accuracy stats, and letter grade
- Streak bonus system: consecutive correct answers earn extra points
- Countdown timer (15s per question, -2 pts on timeout)
- Wrong answer penalty (-1 pt)
- Instructions/help text on the welcome screen
- Play Again button on game-over screen

Improvements:
- Slider minimum changed from 0 to 1 (0 was invalid)
- Expanded function bank from 28 to 50 questions
- Replaced magic key code numbers with KeyEvent constants
- Removed debug System.out.println statements
- Fixed duplicate imports in Game.java
- Renamed unclear variable (uselessAndOnlyForConstAtBeginningCase -> skipNextSign)
- Quit button text changed from 'Get a life' to 'Quit'

Co-Authored-By: Anish Lakkapragada <[email protected]>
@devin-ai-integration
Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

…ositioning

The JFrame's default BorderLayout was overriding setBounds() calls,
causing labels, buttons, and instructions to not render. Added
getContentPane().setLayout(null) to match the absolute positioning
pattern used throughout the codebase.

Co-Authored-By: Anish Lakkapragada <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant