Snake daily: first food depends on the previous run, so the board differs per player

Aperta Adatta ai principianti
#88 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
Meno di un'ora
Idoneità per principianti
84/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
typescript
Ambito
game-dev

Direzione di ricerca

Inizia da games/snake/scenes/GameScene.ts: init() (intorno alle righe 105-123) reimposta lo stato per partita ma non this.food, e create() (riga 141) chiama randomFreeCell() (righe 462-468), che vede ancora il cibo della partita precedente. Dichiara food come private food: Cell | undefined e azzeralo in init(). Poi verifica che freeCells in games/snake/logic.ts e la scelta con seed in shared/rng.ts si comportino come descritto nell'issue. È completato quando la prima cella di cibo giornaliera coincide dopo un caricamento da zero, dopo PLAY AGAIN e dopo RESTART, la modalità normale resta invariata e npm test passa.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug good first issue severity: medium

Summary

In Neon Snake's daily challenge, where the first food appears depends on the last food of the previous run played on the same page. The board is supposed to be the same for everyone who steers the same way, but it isn't.

Where

  • games/snake/scenes/GameScene.ts:105-123 (init, never resets food)
  • games/snake/scenes/GameScene.ts:141 (create, this.food = this.randomFreeCell())
  • games/snake/scenes/GameScene.ts:462-468 (randomFreeCell)

Details

Phaser reuses the scene instance, and init() resets bonus, score, eaten and the rest, but not this.food. On the second and later runs on a page, create() calls randomFreeCell() while this.food still holds the previous run's last food cell:

private randomFreeCell(): Cell {
  const taken = this.players.flatMap((p) => p.segments);
  if (this.food) taken.push(this.food);
  if (this.bonus) taken.push(this.bonus.cell);
  const free = freeCells(taken);
  return this.cellRng ? this.cellRng.pick(free) : Phaser.Utils.Array.GetRandom(free);
}

freeCells() lists cells in row-major order, so excluding one extra cell shifts every index after it. The seeded cellRng.pick(free) then lands on a different cell, and every later pick follows from that different board.

Impact

Daily scores are not comparable. A player who played a normal run, a previous daily run, or pressed RESTART before the daily gets a different food sequence from a player who opened the daily fresh. Replaying the daily on the same page is not the same board either.

Steps to reproduce

  1. Open games/snake/?mode=daily, start DAILY, and note the first food cell. Then die.
  2. Choose PLAY AGAIN.
  3. The first food cell is often different (whenever the previous run's last food sat before the picked index).

Suggested fix

Clear this.food in init() (declare it as private food: Cell | undefined), so the first randomFreeCell() of every run sees only the snake.

Acceptance criteria

  • The first daily food cell is the same on a fresh page load and after PLAY AGAIN, RESTART or a normal run.
  • Normal mode behaviour is unchanged.

Getting started

  • Relevant files: games/snake/scenes/GameScene.ts, games/snake/logic.ts (freeCells), shared/rng.ts (dailyRng)
  • How to run tests: npm test
  • Related: #78 (Snake daily mode)

Filed by repo-audit/full-audit at de2b25b. Severity: medium. Effort: S. audit-key: bug|games/snake/scenes/GameScene.ts|randomFreeCell

Lingua principale
TypeScript
Stelle
3
Fork
3
Merge medio
8h 13m
PR unite (30g)
2

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di TMHSDigital/GH-Arcade

Tutte le issue di TMHSDigital/GH-Arcade

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.