Skip to content

Commit

Permalink
feat: change canMoveForward() in Turtle (#251)
Browse files Browse the repository at this point in the history
Co-authored-by: Sakamoto, Kazunori <[email protected]>
  • Loading branch information
HackberryA3 and exKAZUu authored Dec 19, 2024
1 parent 8e25c3b commit 18da6b7
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/problems/traceProgram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ class Turtle {
const index = dirs.indexOf(this.dir);
const nx = this.x + dx[index];
const ny = this.y + dy[index];
return nx >= 0 && nx < ${GRID_COLUMNS} && ny >= 0 && ny < ${GRID_ROWS};
const isNoTurtle = !turtles.some(t => t.x === nx && t.y === ny);
return nx >= 0 && nx < ${GRID_COLUMNS} && ny >= 0 && ny < ${GRID_ROWS} && isNoTurtle;
}
remove() {
turtles.splice(turtles.indexOf(this), 1);
Expand Down

0 comments on commit 18da6b7

Please sign in to comment.