side-scrolling-snake isPositionValid admits cols/rows — A* can enqueue OOB grid cells #1024

Closed
opened 2026-08-12 08:41:10 +00:00 by spikerj · 1 comment
Owner

Summary

SideScrollingSnakeComponent.isPositionValid uses x < cols + 1 and y < rows + 1 (with x > 0 / y > 0), so coordinates (cols, y) and (x, rows) are treated as walkable even though grid only has indices [0..cols-1] / [0..rows-1].

Impact

aStarPath → getValidDirections can enqueue those cells; the next iteration does this.grid[newPos.y][newPos.x].commitType and throws when the snake explores the right/bottom edge.

Repro (unit)

With cols=7, isPositionValid(7, 2) returns true but grid[2][7] is undefined.

Expected

Bounds should be x >= 0 && x < cols && y >= 0 && y < rows (or whatever playable rectangle is intended — today column/row 0 are also excluded).

Found by

Wave 6 coverage tick 11 / agent a1 (side-scrolling-snake.component.spec.ts).

## Summary `SideScrollingSnakeComponent.isPositionValid` uses `x < cols + 1` and `y < rows + 1` (with `x > 0` / `y > 0`), so coordinates `(cols, y)` and `(x, rows)` are treated as walkable even though `grid` only has indices `[0..cols-1]` / `[0..rows-1]`. ## Impact `aStarPath` → `getValidDirections` can enqueue those cells; the next iteration does `this.grid[newPos.y][newPos.x].commitType` and throws when the snake explores the right/bottom edge. ## Repro (unit) With `cols=7`, `isPositionValid(7, 2)` returns `true` but `grid[2][7]` is `undefined`. ## Expected Bounds should be `x >= 0 && x < cols && y >= 0 && y < rows` (or whatever playable rectangle is intended — today column/row 0 are also excluded). ## Found by Wave 6 coverage tick 11 / agent a1 (`side-scrolling-snake.component.spec.ts`).
Author
Owner

Already present on spikersoft-angular master. isPositionValid uses x < cols && y < rows, so A* cannot enqueue grid[y][cols] / grid[rows][x]. Closing.

Already present on `spikersoft-angular` `master`. `isPositionValid` uses `x < cols && y < rows`, so A* cannot enqueue `grid[y][cols]` / `grid[rows][x]`. Closing.
Sign in to join this conversation.