-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix various non-determinism bugs using useReducer
and other guards
#53
Conversation
src/components/FallingBlock.tsx
Outdated
@@ -9,7 +9,7 @@ export const FallingBlock = React.memo( ({ fallingLetters, durationRate }: {fall | |||
<FallingLetter | |||
fallingLetterBeforeAndAfter={fallingLetterBeforeAndAfter} | |||
durationRate={durationRate} | |||
key={`f${fallingLetterBeforeAndAfter[0].r}${fallingLetterBeforeAndAfter[0].c}`} | |||
key={`${Math.random()}${fallingLetterBeforeAndAfter[0].r}${fallingLetterBeforeAndAfter[0].c}`} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops! Removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs to be typed. See the individual comments.
src/GameLoop.tsx
Outdated
fallingLettersBeforeAndAfter: [], | ||
}; | ||
|
||
const reducer = (state, action) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need a better name than reducer
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inlined
src/GameLoop.tsx
Outdated
@@ -103,6 +103,39 @@ const timestamps = { | |||
playerInstantDropAnimDurationMilliseconds: 0, | |||
}; | |||
|
|||
const playerCellsInit = generateUserCells(); | |||
const initialState = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this global?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed
src/GameLoop.tsx
Outdated
fallingLettersBeforeAndAfter: [], | ||
}; | ||
|
||
const reducer = (state, action) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please type this. You probably won't need a default case if you type it correctly (as a discriminated union).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Do you have any suggested improvements for brevity?
src/GameLoop.tsx
Outdated
const playerCellsInit = generateUserCells(); | ||
const initialState = { | ||
boardCellMatrix: createBoard(BOARD_ROWS, BOARD_COLS), | ||
playerPos:[...spawnPos] as const, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably needs a format.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will format code afterwards
6933616
to
5925702
Compare
There are bugs regarding floating blocks lingering when falling, floating cells not falling, and cells not updating their
hasMatched
variable. I believe this is due to React's async state updates, causing game logic conditionals to perform at incorrectly. Various guards have been added to ensure these things do not affect gameplay.