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 摘要。