BIG FORMATING COMMIT

This commit is contained in:
2023-07-30 15:55:22 +02:00
parent 088fce0aaa
commit 91972107eb
103 changed files with 1610 additions and 1585 deletions

View File

@@ -7,16 +7,15 @@ import kernel.turtle.Turtle;
using tink.CoreApi;
class TurtleExecuter {
private var instructions:Array<TurtleInstruction>;
public function new(instructions:Array<TurtleInstruction>) {
this.instructions = instructions;
}
public function getRequiredFuel(): Int {
public function getRequiredFuel():Int {
var fuel = 0;
for(inst in instructions){
for (inst in instructions) {
if (inst == Forward || inst == Back || inst == Up || inst == Down) {
fuel++;
}
@@ -25,9 +24,9 @@ class TurtleExecuter {
return fuel;
}
public function getRequiredBlocks(): Int {
public function getRequiredBlocks():Int {
var blocks = 0;
for(inst in instructions){
for (inst in instructions) {
switch inst {
case Place(_):
blocks++;
@@ -42,11 +41,11 @@ class TurtleExecuter {
Return the offset of the turtle after executing the instructions.
The origin is the starting position of the turtle.
**/
public function getFinalOffset(): {offset: Pos3, faceing: Pos} {
var pos: Pos3 = {x:0, y:0, z:0};
var forwardVec: Pos3 = {x: 1, y: 0, z: 0};
public function getFinalOffset():{offset:Pos3, faceing:Pos} {
var pos:Pos3 = {x: 0, y: 0, z: 0};
var forwardVec:Pos3 = {x: 1, y: 0, z: 0};
for (inst in instructions){
for (inst in instructions) {
switch inst {
case Forward:
pos = pos + forwardVec;
@@ -55,21 +54,21 @@ class TurtleExecuter {
case TurnRight:
forwardVec = {x: -forwardVec.z, z: forwardVec.x, y: forwardVec.y};
case TurnLeft:
forwardVec = {x: forwardVec.z, z: -forwardVec.x , y: forwardVec.y};
forwardVec = {x: forwardVec.z, z: -forwardVec.x, y: forwardVec.y};
default:
}
}
return {offset:pos,faceing: new Pos({x:forwardVec.x, y:forwardVec.z})};
return {offset: pos, faceing: new Pos({x: forwardVec.x, y: forwardVec.z})};
}
public function execute() {
for (inst in instructions){
for (inst in instructions) {
executeInst(inst);
}
}
private function executeInst(instruction: TurtleInstruction): Outcome<Noise,String> {
private function executeInst(instruction:TurtleInstruction):Outcome<Noise, String> {
switch instruction {
case Forward:
return Turtle.instance.forward();