diff --git a/src/problems/problemData.ts b/src/problems/problemData.ts index 7b1200c7..9cb8f112 100644 --- a/src/problems/problemData.ts +++ b/src/problems/problemData.ts @@ -2914,71 +2914,71 @@ class MyTurtle { // ----------- 初級プログラミングⅡ 第1回 ここから ----------- multiObject1: { instrumented: ` -const t1 = new Turtle(1, 1); //trace -const t2 = new Turtle(3, 3); //trace -t1.forward(); -t1.turnRight(); -t2.forward(); -t2.turnLeft(); +const t1 = new Turtle(1, 1); // step +const t2 = new Turtle(3, 3); // step +t1.前に進む(); // step +t1.右を向く(); // step +t2.前に進む(); // step +t2.左を向く(); // step `.trim(), java: ` public class Main { public static void main(String[] args) { - Turtle t1 = new Turtle(1, 1); //sid - Turtle t2 = new Turtle(3, 3); //sid - t1.前に進む(); //sid - t1.右を向く(); //sid - t2.前に進む(); //sid - t2.左を向く(); //sid + Turtle t1 = new Turtle(1, 1); // step + Turtle t2 = new Turtle(3, 3); // step + t1.前に進む(); // step + t1.右を向く(); // step + t2.前に進む(); // step + t2.左を向く(); // step } } `.trim(), }, multiObject2: { instrumented: ` -const t1 = new Turtle(1, 1); //trace -t1.forward(); -t1.turnRight(); -const t2 = new Turtle(3, 3); //trace -t2.forward(); -t2.turnLeft(); -t2.forward(); +const t1 = new Turtle(1, 1); // step +t1.前に進む(); // step +t1.右を向く(); // step +const t2 = new Turtle(3, 3); // step +t2.前に進む(); // step +t2.左を向く(); // step +t2.前に進む(); // step `.trim(), java: ` public class Main { public static void main(String[] args) { - Turtle t1 = new Turtle(1, 1); //sid - t1.前に進む(); //sid - t1.右を向く(); //sid - Turtle t2 = new Turtle(3, 3); //sid - t2.前に進む(); //sid - t2.左を向く(); //sid - t2.前に進む(); //sid + Turtle t1 = new Turtle(1, 1); // step + t1.前に進む(); // step + t1.右を向く(); // step + Turtle t2 = new Turtle(3, 3); // step + t2.前に進む(); // step + t2.左を向く(); // step + t2.前に進む(); // step } } `.trim(), }, garbageCollection1: { instrumented: ` -let t1 = new Turtle(1, 1); // trace -t1.forward(); -t1.turnRight(); -let t2 = new Turtle(3, 3); // trace -t2.forward(); -t2.remove(); +let t1 = new Turtle(1, 1); // step +t1.前に進む(); // step +t1.右を向く(); // step +let t2 = new Turtle(3, 3); // step +t2.前に進む(); // step +t2.remove(); // step t2 = t1; -t2.forward(); +t2.前に進む(); // step `.trim(), java: ` public class Main { public static void main(String[] args) { - Turtle t1 = new Turtle(1, 1); // sid - t1.前に進む(); // sid - t1.右を向く(); // sid - Turtle t2 = new Turtle(3, 3); // sid - t2.前に進む(); // sid - t2 = t1; // sid - t2.前に進む(); // sid + Turtle t1 = new Turtle(1, 1); // step + t1.前に進む(); // step + t1.右を向く(); // step + Turtle t2 = new Turtle(3, 3); // step + t2.前に進む(); // step + t2 = t1; // step + t2.前に進む(); // step } } `.trim(), diff --git a/src/problems/traceProgram.ts b/src/problems/traceProgram.ts index 8f0b9ac6..1c818989 100644 --- a/src/problems/traceProgram.ts +++ b/src/problems/traceProgram.ts @@ -122,7 +122,7 @@ class Turtle { board[this.y][this.x] = this.color; turtles.push(this); } - forward(sid, self) { + 前に進む() { const index = dirs.indexOf(this.dir); this.x += dx[index]; this.y += dy[index]; @@ -130,9 +130,12 @@ class Turtle { throw new Error(\`Out of bounds: (\${this.x}, \${this.y})\`); } board[this.y][this.x] = this.color; + } + forward(sid, self) { + this.前に進む(); addTrace(sid, self); } - backward(sid, self) { + 後に戻る() { const index = dirs.indexOf(this.dir); this.x -= dx[index]; this.y -= dy[index]; @@ -140,6 +143,9 @@ class Turtle { throw new Error(\`Out of bounds: (\${this.x}, \${this.y})\`); } board[this.y][this.x] = this.color; + } + backward(sid, self) { + this.後に戻る(); addTrace(sid, self); } canMoveForward() { @@ -148,16 +154,21 @@ class Turtle { const ny = this.y + dy[index]; return nx >= 0 && nx < ${GRID_COLUMNS} && ny >= 0 && ny < ${GRID_ROWS}; } - remove(sid, self) { + remove() { turtles.splice(turtles.indexOf(this), 1); - addTrace(sid, self); } - turnRight(sid, self) { + 右を向く() { this.dir = dirs[(dirs.indexOf(this.dir) + 1) % 4]; + } + turnRight(sid, self) { + this.右を向く(); addTrace(sid, self); } - turnLeft(sid, self) { + 左を向く() { this.dir = dirs[(dirs.indexOf(this.dir) + 3) % 4]; + } + turnLeft(sid, self) { + this.左を向く(); addTrace(sid, self); } } @@ -222,7 +233,7 @@ ${modifiedCode.trim()} let lastCallerId = 0; for (const [index, line] of lines.entries()) { const refinedLine = line - .replace(/\s*\/\/\s*sid\s*(:\s*\d+|)\s*/, (_, sid) => { + .replace(/\s*\/\/\s*(?:sid|step)\s*(:\s*\d+|)\s*/, (_, sid) => { if (sid) { lastSid = Number(sid.slice(1)); } else { @@ -268,7 +279,7 @@ function modifyCode(instrumented: string): string[] { return `${newOrMethod}(${statementId}, this${delimiter}${args})${tail}`; } ) - .replace(/\s*\/\/\s*trace\s*/, (_) => { + .replace(/\s*\/\/\s*(?:trace|step)\s*/, (_) => { statementReplaced = true; return `addTrace(${statementId}, this);`; })