-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmytunnel
121 lines (106 loc) · 1.8 KB
/
mytunnel
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
function updateLocation()
if dir == "north" then
z = z + 1
elseif dir == "south" then
z = z - 1
elseif dir == "east" then
x = x + 1
elseif dir == "west" then
x = x - 1
end
end -- updateLocation
function right()
turtle.turnRight()
if dir == "north" then
dir = "east"
elseif dir == "east" then
dir = "south"
elseif dir == "south" then
dir = "west"
elseif dir == "west" then
dir = "north"
end
end -- right
function left()
turtle.turnLeft()
if dir == "north" then
dir = "west"
elseif dir == "west" then
dir = "south"
elseif dir == "south" then
dir = "east"
elseif dir == "east" then
dir = "north"
end
end -- right
function forward()
while not turtle.forward() do
turtle.dig()
end
updateLocation()
end -- forward
function up()
while not turtle.up() do
turtle.digUp()
end
y = y + 1
end -- up
function down()
while not turtle.down() do
turtle.digDown()
end
y = y - 1
end -- down
function mineRow()
if width > 1 then
if x == 1 then
right()
while x < width do
forward()
end
left()
else
left()
while x > 1 do
forward()
end
right()
end
end
end -- row
function mineCrossSection()
mineRow()
if y == 1 then
while y < height do
up()
mineRow()
end
else
while y > 1 do
down()
mineRow()
end
end
end -- mineCrossSection()
function main(args)
if #args ~= 3 then
print( "Usage: mytunnel <width> <height> <length>" )
error()
end
width = tonumber(args[1])
height = tonumber(args[2])
length = tonumber(args[3])
x = 1
y = 1
z = 0
dir = "north"
while z < length do
forward()
mineCrossSection()
end
while y > 1 do
down()
end
end -- main
args = { ... }
main(args)