fix: every field excursion is a different field (#3) - #47
Conversation
CI failed: Prettier code formatting check failed during the lint script because lib/game.js does not conform to style rules.OverviewOne change-related failure was found in the CI run where the lint script failed due to a Prettier formatting violation in lib/game.js across 1 log analyzed. FailuresPrettier Formatting Check Failed (confidence: high)
Summary
Code Review
|
| Auto-apply | Compact |
|
|
Important
Your trial ends in 7 days — upgrade now to keep code review, CI analysis, auto-apply, custom automations, and more.
Was this helpful? React with 👍 / 👎 | Gitar
| this.excursion++ | ||
| const seed = | ||
| (this.excursion * 2654435761 + this.player.xp * 40503 + this.player.gold) >>> 0 | ||
| this.field = new Field({ player: this.player, seed }) |
There was a problem hiding this comment.
⚠️ Bug: excursion counter isn't persisted or reset on load
The excursion field is initialized to 0 in the constructor, incremented on every field entry, but never written to saveState() nor reset in loadSlot(). As a result the derived seed after loading a save depends on how many excursions happened earlier in the current session: reloading the same save twice yields different fields, and two players loading an identical save file (same xp/gold) get different maps. This contradicts the PR's stated goal that "una misma partida sigue siendo reproducible." Persist excursion in saveState() and restore it in loadSlot() (and reset it in the constructor path used for new games) so the seed is a pure function of saved state.
Persist and restore the excursion counter so the field seed is reproducible from saved state.:
// in saveState() return object:
return {
name: this.name,
player,
location,
excursion: this.excursion,
...
}
// in loadSlot(), before deriving the seed:
this.excursion = Number(saved.excursion) || 0
- Apply fix
Check the box to apply the fix or reply for a change | Was this helpful? React with 👍 / 👎
| this.excursion++ | ||
| const seed = | ||
| (this.excursion * 2654435761 + this.player.xp * 40503 + this.player.gold) >>> 0 | ||
| this.field = new Field({ script: this.scriptSource, player: this.player, seed }) |
There was a problem hiding this comment.
💡 Quality: Seed derivation formula duplicated in two places
The identical (this.excursion * 2654435761 + this.player.xp * 40503 + this.player.gold) >>> 0 expression appears in both loadSlot() and enter(). Duplicating the magic constants risks the two paths drifting apart. Extract a small helper (e.g. nextFieldSeed() that also does this.excursion++) and call it from both sites.
Centralize the seed derivation so both field entry points stay in sync.:
nextFieldSeed() {
this.excursion++
return (this.excursion * 2654435761 + this.player.xp * 40503 + this.player.gold) >>> 0
}
// both call sites:
const seed = this.nextFieldSeed()
- Apply fix
Check the box to apply the fix or reply for a change | Was this helpful? React with 👍 / 👎
fix: cada salida al campo es un campo distinto (#3)
ES
Problema.
new Field({ player })no recibia semilla ylib/field.jscae aseed ?? 1: todas las excursiones generaban el mismo mapa con los mismos bichos.Arreglo. Contador
this.excursionen el constructor y semilla derivada enlas puertas de salida al campo (glifo
>viaenter()y restauracion departida guardada en el campo):
Derivada y no aleatoria: una misma partida sigue siendo reproducible (misma
secuencia de acciones -> mismos campos), pero dos excursiones distintas ya no
coinciden. El progreso del personaje (xp/gold) entra en la mezcla para que ni
siquiera dos partidas nuevas clonadas compartan campos.
Test nuevo: abre excursion, vuelve con
t, suma oro, abre otra vez — lassemillas difieren. Negativo verificado: sin el arreglo el contador no existe y
el test no compila/semillas iguales; con el arreglo 66/66 green.
EN
Field excursions now derive their seed from an excursion counter plus the
character's progress (xp/gold) instead of falling back to the hardcoded seed 1,
so every excursion is a different map while a single save stays reproducible.
Regression test asserts two consecutive excursions get different seeds. 66/66
tests green.