From 18da6b79f727a5ce8f3703548345eb9d4021d5e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=E3=81=95=E3=82=93?= <72796532+HackberryA3@users.noreply.github.com> Date: Thu, 19 Dec 2024 17:04:27 +0900 Subject: [PATCH] feat: change canMoveForward() in Turtle (#251) Co-authored-by: Sakamoto, Kazunori --- src/problems/traceProgram.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/problems/traceProgram.ts b/src/problems/traceProgram.ts index f103fc9..65d58e7 100644 --- a/src/problems/traceProgram.ts +++ b/src/problems/traceProgram.ts @@ -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);