Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local robot = require("robot")
- local robomove = {}
- function robomove.forward(x)
- if x ~= 0 then
- if x > 0 then
- for i = 1, x do
- robot.forward()
- end
- else
- for i = 1, -x do
- robot.back()
- end
- end
- end
- end
- function robomove.back(x)
- if x ~= 0 then
- if x > 0 then
- robot.turnRight()
- robot.turnRight()
- for i = 1, x do
- robot.forward()
- end
- else
- robot.turnLeft()
- robot.turnLeft()
- for i = 1, -x do
- robot.back()
- end
- end
- end
- end
- function robomove.up(x)
- if x ~= 0 then
- if x > 0 then
- for i = 1, x do
- robot.up()
- end
- else
- for i = 1, -x do
- robot.down()
- end
- end
- end
- end
- function robomove.down(x)
- if x ~= 0 then
- if x > 0 then
- for i = 1, x do
- robot.down()
- end
- else
- for i = 1, -x do
- robot.up()
- end
- end
- end
- end
- function robomove.right(x)
- if x >= 0 then
- robot.turnRight()
- if x > 0 then
- for i = 1, x do
- robot.forward()
- end
- end
- else
- for i = 1, -x do
- robot.back()
- end
- robo.turnLeft()
- end
- end
- function robomove.left(x)
- if x >= 0 then
- robot.turnLeft()
- if x > 0 then
- for i = 1, x do
- robot.forward()
- end
- end
- else
- for i = 1, -x do
- robot.back()
- end
- robo.turnRight()
- end
- end
- function robomove.path(m,x)
- local movment = {}
- movment["f"] = robomove.forward
- movment["b"] = robomove.back
- movment["u"] = robomove.up
- movment["d"] = robomove.down
- movment["r"] = robomove.right
- movment["l"] = robomove.left
- movment[m](x)
- end
- return robomove
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement