refactor: update turnToFace method to synchronize turtle facing state with global variable
This commit is contained in:
@@ -130,13 +130,13 @@ export class BaseState {
|
|||||||
const diff = (targetFacing - currentFacing + 4) % 4;
|
const diff = (targetFacing - currentFacing + 4) % 4;
|
||||||
|
|
||||||
if (diff === 1) {
|
if (diff === 1) {
|
||||||
await this.exec('return turtle.turnRight()');
|
await this.exec(`turtle.turnRight(); _G._turtleFacing = ${targetFacing}`);
|
||||||
this.turtle.facing = targetFacing;
|
this.turtle.facing = targetFacing;
|
||||||
} else if (diff === 2) {
|
} else if (diff === 2) {
|
||||||
await this.exec('turtle.turnRight(); return turtle.turnRight()');
|
await this.exec(`turtle.turnRight(); turtle.turnRight(); _G._turtleFacing = ${targetFacing}`);
|
||||||
this.turtle.facing = targetFacing;
|
this.turtle.facing = targetFacing;
|
||||||
} else if (diff === 3) {
|
} else if (diff === 3) {
|
||||||
await this.exec('return turtle.turnLeft()');
|
await this.exec(`turtle.turnLeft(); _G._turtleFacing = ${targetFacing}`);
|
||||||
this.turtle.facing = targetFacing;
|
this.turtle.facing = targetFacing;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user