Skip to content

Otter-stop update to scale sequence length with difficulty level#84

Merged
acrosman merged 5 commits intomainfrom
copilot/update-sequence-lengths-otter-stop
Apr 29, 2026
Merged

Otter-stop update to scale sequence length with difficulty level#84
acrosman merged 5 commits intomainfrom
copilot/update-sequence-lengths-otter-stop

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 29, 2026

Otter Stop sequences were fully random per trial. This PR introduces structured sequences: N otters followed by one fish, where N is sampled randomly from [0, BASE_MAX_SEQUENCE_LENGTH + level] — giving sequences that grow with difficulty and shrink immediately when the level drops.

Core logic (game.js)

Replaced the random IMAGE_KEYS selection in pickNextImage() with sequence-based selection:

if (sequencePosition >= currentSequenceLength) {
  sequencePosition = 0;
  currentSequenceLength = generateSequenceLength();
  return { imageKey: NO_GO_KEY, isNoGo: true };
}
sequencePosition += 1;
const idx = Math.floor(Math.random() * GO_KEYS.length);
return { imageKey: GO_KEYS[idx], isNoGo: false };
  • MIN_SEQUENCE_LENGTH = 0 — a sequence of length 0 means the fish appears immediately with no preceding otters
  • generateSequenceLength() samples uniformly from [0, BASE_MAX_SEQUENCE_LENGTH + level] — at level 0 that is [0, 5]; each level gained widens the upper bound by 1
  • When recordResponse() triggers a level drop, currentSequenceLength is immediately clamped to the new maximum (BASE_MAX_SEQUENCE_LENGTH + newLevel) so in-flight sequences cannot exceed the reduced difficulty
  • forceGoNext still takes priority, advancing sequencePosition normally
  • stopGame() now returns maxSequenceLength (= BASE_MAX_SEQUENCE_LENGTH + level)
  • New exports: getMaxSequenceLength(), getCurrentSequenceLength()

Progress persistence (index.js)

stop() passes maxSequenceLength to saveScore via extraFields, tracking the session high-water mark:

}, (prev) => ({
  maxSequenceLength: Math.max((prev && prev.maxSequenceLength) || 0, result.maxSequenceLength || 0),
}));

Sequence length is not surfaced in the UI.

Tests (game.test.js)

  • Updated it.each values to guarantee non-zero sequence lengths when the spy is active (re-runs initGame() inside the test after setting the spy); rand=0.2 replaces rand=0 for the go-1.png case
  • Replaced the Math.random()=0.75→no-go test with sequence-exhaustion tests
  • Fixed 'starts a new go sequence after the fish' test to use a spy ensuring the post-fish sequence is also non-zero
  • Added suites for getMaxSequenceLength() (including a level-10 assertion) and getCurrentSequenceLength() covering range assertions, level-drop clamping, and regeneration-on-fish

Copilot AI linked an issue Apr 29, 2026 that may be closed by this pull request
Copilot AI and others added 2 commits April 29, 2026 02:38
- Early game: at most 5 otters before fish (level 0)
- Each level adds 1 to the maximum sequence length
- Sequence length is randomized each round up to the level max
- maxSequenceLength is saved to progress via saveScore extraFields
- Export getMaxSequenceLength() and getCurrentSequenceLength() from game.js
- Update and expand tests for new sequence behaviour

Agent-Logs-Url: https://github.com/acrosman/BrainSpeedExercises/sessions/b5175073-9102-4186-a890-77d366114374

Co-authored-by: acrosman <2972053+acrosman@users.noreply.github.com>
Copilot AI changed the title [WIP] Update sequence lengths in Otter stop feat(otter-stop): scale sequence length with difficulty level Apr 29, 2026
Copilot AI requested a review from acrosman April 29, 2026 02:41
@acrosman acrosman changed the title feat(otter-stop): scale sequence length with difficulty level Otter-stop update to scale sequence length with difficulty level Apr 29, 2026
Copy link
Copy Markdown
Owner

@acrosman acrosman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mas Sequence length does not step down when a player fails three times in a row and the player goes back to a lower level. It should also be the same for any given level of difficulty.

Comment thread app/games/otter-stop/tests/game.test.js Outdated
[0.5, 'go-3.png', false],
[0.75, 'no-go', true],
])('Math.random()=%f → imageKey="%s", isNoGo=%s', (rand, expectedKey, expectedIsNoGo) => {
[0.34, 'go-2.png', false],
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing about this change should have required an update to the timing in this test.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restored in 12671d7. The it.each random values are back to [0, 0.25, 0.5, 0.75]; only the expected image keys were updated to reflect the 3-key GO_KEYS pool (Math.floor(r * 3) gives indices 0, 0, 1, 2 for those values).

expect(getMaxSequenceLength()).toBe(7);
});

it('increases by 1 for each additional level', () => {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is the same as the three before it. If we're doing to run a generic one here it should be further into the level count than levels 0-2. Have it test a much later level or remove this extra test.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in 12671d7. The test now advances to level 10 (30 consecutive correct no-go inhibitions) and asserts getMaxSequenceLength() === 15.

…s review comments

- Remove randomized sequence length generation; sequence is now always
  exactly BASE_MAX_SEQUENCE_LENGTH + level (5 at level 0, +1 per level)
- pickNextImage() compares sequencePosition against the live level-based
  value, so the sequence length adjusts immediately when the level drops
- Remove MIN_SEQUENCE_LENGTH constant and generateSequenceLength() helper
- getCurrentSequenceLength() now returns the same deterministic value
  as getMaxSequenceLength()
- Restore original it.each random values [0, 0.25, 0.5, 0.75] in
  pickNextImage test, updating expected keys for the 3-key GO_KEYS pool
- Update redundant getMaxSequenceLength 'increases by 1' test to assert
  at level 10 (value 15) instead of rechecking levels 0-2
- Expand getCurrentSequenceLength tests to cover level-drop behaviour

Agent-Logs-Url: https://github.com/acrosman/BrainSpeedExercises/sessions/e48782cc-c2de-4d6b-b7b9-fe1d558da4d7

Co-authored-by: acrosman <2972053+acrosman@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 29, 2026

Mas Sequence length does not step down when a player fails three times in a row and the player goes back to a lower level. It should also be the same for any given level of difficulty.

Fixed in 12671d7. The sequence length is now deterministic: pickNextImage() compares sequencePosition directly against BASE_MAX_SEQUENCE_LENGTH + level (the live value), so the length adjusts immediately whenever the level changes — including when a 3-wrong-streak drops the level. generateSequenceLength() and MIN_SEQUENCE_LENGTH have been removed entirely.

Copilot AI requested a review from acrosman April 29, 2026 03:01
Copy link
Copy Markdown
Owner

@acrosman acrosman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The goal was not to make it deterministic. The length of any given sequence of otters should be random, between zero (just show the fish) and the max length for the current level.

Go back to the previous version. Update the process so that when a player goes back two levels because they failed three sequences in a row it reduces the max sequence length to the correct length for the new level.

…lamping

- Restore MIN_SEQUENCE_LENGTH=0 (sequences range [0, BASE+level])
  allowing fish to appear immediately (length 0) per design intent
- Restore currentSequenceLength state variable and generateSequenceLength()
- Restore pickNextImage() to compare against currentSequenceLength and
  regenerate it when the fish is returned
- In recordResponse(), clamp currentSequenceLength to the new maximum
  whenever the level drops (fixes the core bug: sequences no longer
  stay too long after a 3-wrong-streak drops the player two levels)
- Update it.each rand=0 → rand=0.2 to guarantee a non-zero sequence
  in those tests; add initGame() call inside it.each after spy setup
- Fix 'starts a new go sequence after the fish' test to use a spy so
  the post-fish sequence is guaranteed non-zero
- Update getCurrentSequenceLength() tests: range assertions, level-drop
  clamping assertion, and regeneration-on-fish assertion

Agent-Logs-Url: https://github.com/acrosman/BrainSpeedExercises/sessions/f7bcb8f0-b2bb-4d2a-aa60-2efbbcf9b27a

Co-authored-by: acrosman <2972053+acrosman@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 29, 2026

The goal was not to make it deterministic. The length of any given sequence of otters should be random, between zero (just show the fish) and the max length for the current level.

Go back to the prev...

Fixed in 0a0c94e. Reverted to randomized sequence lengths. MIN_SEQUENCE_LENGTH is now 0 (fish can appear immediately), and sequences are picked uniformly from [0, BASE_MAX_SEQUENCE_LENGTH + level] each time. In recordResponse(), after any level drop the cached currentSequenceLength is immediately clamped to the new maximum (BASE_MAX_SEQUENCE_LENGTH + newLevel), so a 3-wrong-streak that drops two levels also shortens the upper bound of any in-flight sequence.

Copilot AI requested a review from acrosman April 29, 2026 03:16
@acrosman acrosman marked this pull request as ready for review April 29, 2026 03:31
@acrosman acrosman merged commit f499fd8 into main Apr 29, 2026
6 checks passed
@acrosman acrosman deleted the copilot/update-sequence-lengths-otter-stop branch April 29, 2026 03:33
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.

Update sequence lengths in Otter stop

2 participants