Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- robot= require('robot')
- c= require('component')
- SOUTH= 0 -- юг +z
- EAST= 3 -- восток +x
- NORTH= 2 -- север -z
- WEST= 1 -- запад -x
- Max_World_Y= 300
- Min_World_Y= 0
- local SEEDCELL= 15
- io.write('Side:')
- local sides= io.read()+0
- io.write('X:')
- local x= io.read()+0
- io.write('Y:')
- local y= io.read()+0
- io.write('Z:')
- local z= io.read()+0
- function turnLeft()
- sides= sides-1
- if (sides<0) then sides= 3 end
- robot.turnLeft()
- end
- function turnRight()
- sides= sides+1
- if (sides>3) then sides= 0 end
- robot.turnRight()
- end
- function forward()
- if (robot.detect()) then
- return false
- end
- if (sides == SOUTH) then
- z=z+1
- elseif (sides == EAST) then
- x= x+1
- elseif (sides == NORTH) then
- z= z-1
- elseif(sides == WEST) then
- x= x-1
- end
- robot.forward()
- end
- function up()
- if (y>=Max_World_Y) then
- y= Max_World_Y
- elseif (robot.detectUp() ~= true) then
- y= y+1
- robot.up()
- end
- end
- function down()
- if (y<=Min_World_Y) then
- y= Min_World_Y
- elseif (robot.detectDown() ~= true) then
- y= y-1
- robot.down()
- end
- end
- function turns(side)
- while true do
- if (side == sides) then
- break
- end
- turnRight()
- end
- end
- function right()
- turnRight()
- robot.swing()
- forward()
- turnRight()
- end
- function left()
- turnLeft()
- robot.swing()
- forward()
- turnLeft()
- end
- function gotos(X,Y,Z,side)
- while true do
- if (y < Y) then
- if (robot.detectUp() ~= true) then
- up()
- else
- robot.digUp()
- end
- elseif(y > Y) then
- if(robot.detectDown() ~= true) then
- down()
- else
- robot.digDown()
- end
- elseif(y == Y) then
- break
- end
- end
- while true do
- if (z < Z) then
- turns(0)
- if (robot.detect() ~= true) then
- forward()
- else
- robot.dig()
- end
- end
- if (z > Z) then
- turns(2)
- if (robot.detect() ~= true) then
- forward()
- else
- robot.dig()
- end
- end
- if (z == Z) then
- break
- end
- end
- while true do
- if (x < X) then
- turns(3)
- if (robot.detect() ~= true) then
- forward()
- else
- robot.dig()
- end
- end
- if (x > X) then
- turns(1)
- if (robot.detect() ~= true) then
- forward()
- else
- robot.dig()
- end
- end
- if (x == X) then
- break
- end
- end
- turns(side)
- end
- function createField(x,y)
- local Y= 0
- local stats= 0
- local waterCellX= 8
- local waterCellY= 7
- while Y<=y do
- local X= 0
- Y= Y+1
- waterCellY= waterCellY+1
- while X<=x do
- print(waterCellX,waterCellY)
- if (waterCellX >= 8 and waterCellY >= 8) then
- waterCellX= 0
- robot.swingDown()
- end
- if (X+1 ~= x) then
- forward()
- end
- X= X+1
- waterCellX= waterCellX+1
- end
- if (stats == 0) then
- right()
- stats= 1
- elseif (stats == 1) then
- left()
- stats= 0
- end
- if (waterCellY >= 8) then
- waterCellY= 0
- end
- end
- end
- local startX= x
- local startY= y
- local startZ= z
- local sidess= sides
- local stats= 0
- local length_x,length_y= 0,0
- io.write('Enter length X:')
- length_x= io.read()+0
- io.write('Enter length Y:')
- length_y= io.read()+0
- stat= true
- createField(length_x,length_y)
- gotos(0,0,0,sidess)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement