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

Đang mở Phù hợp với người mới
#88 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
Dưới một giờ
Mức phù hợp với người mới
84/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
typescript
Lĩnh vực
game-dev

Hướng nghiên cứu

Bắt đầu tại games/snake/scenes/GameScene.ts: init() (khoảng dòng 105-123) đặt lại trạng thái theo từng lượt chơi nhưng không đặt lại this.food, còn create() (dòng 141) gọi randomFreeCell() (dòng 462-468) và hàm này vẫn thấy thức ăn của lượt trước. Khai báo food là private food: Cell | undefined và xóa nó trong init(). Sau đó kiểm tra freeCells trong games/snake/logic.ts và lựa chọn có seed trong shared/rng.ts có hoạt động đúng như issue mô tả hay không. Hoàn thành khi ô thức ăn hằng ngày đầu tiên khớp nhau sau khi tải mới, sau PLAY AGAIN và sau RESTART, chế độ bình thường không thay đổi và npm test chạy thành công.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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

Ngôn ngữ chính
TypeScript
Star
3
Fork
3
Merge trung bình
8 giờ 13 phút
Pull request đã merge (30 ngày)
2

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của TMHSDigital/GH-Arcade

Tất cả issue của TMHSDigital/GH-Arcade

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.