phetsims / fourier-making-waves

"Fourier: Making Waves" is an educational simulation in HTML5, by PhET Interactive Simulations.
GNU General Public License v3.0
6 stars 3 forks source link

Assertion failed: Score 2 exceeds perfect score 1 #229

Closed chrisklus closed 1 year ago

chrisklus commented 1 year ago

I tried to use the Wave Game a few times to reference game behavior over in Number Play and ran into the assertion:

Assertion failed: Score 2 exceeds perfect score 1

This seems like a bug, assigning @pixelzoom to take a look at your convenience.

pixelzoom commented 1 year ago

Reproduced in master using these steps:

  1. Run the sim with ?showAnswers
  2. Go to the Wave Game screen
  3. Press Level 1 button
  4. Solve the first challenge, press "New Waveform" button
  5. Solve the second challenge, press "New Waveform" button. The sim will fail with this stack trace:
caught Error: Assertion failed: Score 2 exceeds perfect score 1
    at window.assertions.assertFunction (assert.js:28:13)
    at scorePropertyListener (ScoreDisplayStars.ts:59:17)
    at TinyProperty.emit (TinyEmitter.ts:119:9)
    at NumberProperty._notifyListeners (ReadOnlyProperty.ts:315:23)
    at NumberProperty.unguardedSet (ReadOnlyProperty.ts:266:14)
    at NumberProperty.set (ReadOnlyProperty.ts:250:12)
    at set value [as value] (Property.ts:54:11)
    at WaveGameLevel.checkAnswer (WaveGameLevel.js:229:31)
    at checkAnswerListener (WaveGameLevelNode.js:243:13)
    at TinyEmitter.emit (TinyEmitter.ts:119:9)

The failing assertion is in ScoreDisplayStars.ts:

59      assert && assert( score <= perfectScore, `Score ${score} exceeds perfect score ${perfectScore}` );

Note that ScoreDisplayStarsOptions.perfectScore defaults to 1, which is not correct for this sim. So it's likely that this option is missing somewhere upstream, in sim-specific code.

pixelzoom commented 1 year ago

This has been broken in master for a long time. It was broken when LevelSelectionButtonGroup (and subclass WaveGameLevelSelectionButtonGroup) was introduced for https://github.com/phetsims/vegas/issues/108. WaveGameLevelSelectionButtonGroup was incorrectly using ScoreDisplayNumber for level-selection buttons, which is only appropriate for "finite challenges" games that have a perfect score. In the above commit, I fixed WaveGameLevelSelectionButtonGroup to use ScoreDisplayNumberAndStar, which is appropriate for "infinite challenges" games.

This problem does not appear in the published version 1.0.12, or the 1.0 branch. Since it was never released into the wild, I'll close this issue.