Skip to content

Recompute new state if board is modified#33

Merged
TudorEsan merged 5 commits intomainfrom
fix/reset-to-initial-state
Sep 17, 2025
Merged

Recompute new state if board is modified#33
TudorEsan merged 5 commits intomainfrom
fix/reset-to-initial-state

Conversation

@TudorEsan
Copy link
Collaborator

Motivation

Fixed game state management to prevent drawings from disappearing when navigating through generations.

Proposal

  • Always compute fresh generations when moving forward (truncateFutureHistory)
  • Save board modifications at any generation to history (replaceCurrentState)
  • Clear future history when resetting to initial state

Test Plan

tested it locally

@TudorEsan TudorEsan requested a review from ma2bd September 17, 2025 06:37
- fixed comment typo
- No unnecessary differentiation between initial state and updates
- removed truncateFutureHistory
- removed redo functionality
// If we have a valid history position, replace it
if (this.currentHistoryIndex >= 0 && this.currentHistoryIndex < this.history.length) {
this.history[this.currentHistoryIndex] = state;
} else if (this.currentHistoryIndex === -1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This damn zero-indexing :) we could also treat index === 0 as the initial, empty state. Then the if above changes to this.currentHistoryIndex > 0.

Not sure if we need to do this change right now, maybe too risky, but it'd simplify the logic.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes, if its ok I can change it in a refactoring after the launch to not modify the logic this close :)

@TudorEsan TudorEsan merged commit f001d09 into main Sep 17, 2025
2 checks passed
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.

2 participants