Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- do -- Robot state
- local turtleState = {
- position = {x = 85, y = 66, z = 165},
- orientation = {x = 0, z = -1},
- }
- local _turtleForward = turtle.forward
- turtle.forward = function()
- turtleState.position.x = turtleState.position.x + turtleState.orientation.x
- turtleState.position.z = turtleState.position.z + turtleState.orientation.z
- return _turtleForward()
- end
- local _turtleBack = turtle.back
- turtle.back = function(...)
- turtleState.position.x = turtleState.position.x - turtleState.orientation.x
- turtleState.position.z = turtleState.position.z - turtleState.orientation.z
- return _turtleBack(...)
- end
- local _turtleUp = turtle.up
- turtle.up = function(...)
- turtleState.position.y = turtleState.position.y + 1
- return _turtleUp(...)
- end
- local _turtleDown = turtle.down
- turtle.down = function(...)
- turtleState.position.y = turtleState.position.y - 1
- return _turtleDown(...)
- end
- local _turtleTurnLeft = turtle.turnLeft
- turtle.turnLeft = function(...)
- local oldOrientationX = turtleState.orientation.x
- local oldOrientationZ = turtleState.orientation.z
- turtleState.orientation.x = oldOrientationZ
- turtleState.orientation.z = -oldOrientationX
- return _turtleTurnLeft(...)
- end
- local _turtleTurnRight = turtle.turnRight
- turtle.turnRight = function(...)
- local oldOrientationX = turtleState.orientation.x
- local oldOrientationZ = turtleState.orientation.z
- turtleState.orientation.x = -oldOrientationZ
- turtleState.orientation.z = oldOrientationX
- return _turtleTurnRight(...)
- end
- turtle.getPosition = function()
- return turtleState.position.x, turtleState.position.y, turtleState.position.z
- end
- turtle.getOrientation = function()
- return turtleState.orientation.x, turtleState.orientation.z
- end
- end
- turtle.forward()
- turtle.forward()
- turtle.turnLeft()
- turtle.back()
- turtle.up()
- local x, y, z = turtle.getPosition()
- print(x, y, z)
- local ox, oz = turtle.getOrientation()
- print(ox, oz)
Advertisement
Add Comment
Please, Sign In to add comment