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

未關閉 適合新手
#88 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
2/5
預估耗時
1 小時以內
新手友好度
84/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
typescript
領域
game-dev

研究方向

從 games/snake/scenes/GameScene.ts 開始:init()(約第 105-123 行)會重置每一局的狀態,但沒有重置 this.food;create()(第 141 行)呼叫 randomFreeCell()(第 462-468 行),它仍然會看到上一局的食物。將 food 宣告為 private food: Cell | undefined,並在 init() 中清空它。接著檢查 games/snake/logic.ts 中的 freeCells 以及 shared/rng.ts 中帶種子的選取是否與 issue 描述的行為一致。完成標準是:全新載入、PLAY AGAIN 和 RESTART 之後,第一個每日食物格子保持一致;一般模式不受影響;npm test 通過。

由索引模型根據 Issue 內容生成。

描述

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

主要語言
TypeScript
星號
3
分支
3
平均合併
8 小時 13 分鐘
30 天內合併 PR
2

環境準備

這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

TMHSDigital/GH-Arcade 的其他 Issue

查看 TMHSDigital/GH-Arcade 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。