diff --git a/src/lib/turtle/TurtleExecuter.hx b/src/lib/turtle/TurtleExecuter.hx index 83055dc..39271c3 100644 --- a/src/lib/turtle/TurtleExecuter.hx +++ b/src/lib/turtle/TurtleExecuter.hx @@ -1,5 +1,6 @@ package lib.turtle; +import util.Pos3; import kernel.turtle.Turtle; using tink.CoreApi; @@ -11,6 +12,51 @@ class TurtleExecuter { this.instructions = instructions; } + public function getRequiredFuel(): Int { + var fuel = 0; + for(inst in instructions){ + if (inst == Forward || inst == Back || inst == Up || inst == Down) { + fuel++; + } + } + + return fuel; + } + + public function getRequiredBlocks(): Int { + var blocks = 0; + for(inst in instructions){ + switch inst { + case Place(_): + blocks++; + default: + } + } + + return blocks; + } + + public function getFinalOffset(): Pos3 { + var pos: Pos3 = {x:0, y:0, z:0}; + var forwardVec: Pos3 = {x: 1, y: 0, z: 0}; + + for (inst in instructions){ + switch inst { + case Forward: + pos = pos + forwardVec; + case Back: + pos = pos - forwardVec; + case TurnRight: + forwardVec = {x: -forwardVec.z, z: forwardVec.x, y: forwardVec.y}; + case TurnLeft: + forwardVec = {x: forwardVec.z, z: -forwardVec.x , y: forwardVec.y}; + default: + } + } + + return pos; + } + public function execute() { for (inst in instructions){ executeInst(inst);