-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscanner.lua
More file actions
98 lines (80 loc) · 1.93 KB
/
scanner.lua
File metadata and controls
98 lines (80 loc) · 1.93 KB
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
local shell = require("shell")
local args,ops = shell.parse(...)
local component = require("component")
local serial = require("serialization")
local computer = require("computer")
local startTime = computer.uptime()
local foundsTable = {}
local fi = 1
function add(a, b)
local c = {}
if #a==#b then
for i,v in pairs(a) do
c[i]=a[i]+b[i]
end
end
return c
end
function div(a , d)
for i,v in pairs(a) do
a[i]=a[i]/d
end
return a
end
function quarters(quarter)
local quarters = {}
if quarter == 1 then
quarters.pi,quarters.ki = 0,32
quarters.pj,quarters.kj = 0,32
else if quarter == 2 then
quarters.pi,quarters.ki = -32,-1
quarters.pj,quarters.kj = 0,32
else if quarter == 3 then
quarters.pi,quarters.ki = -32,-1
quarters.pj,quarters.kj = -32,-1
else if quarter == 4 then
quarters.pi,quarters.ki = 0,32
quarters.pj,quarters.kj = -32,-1
end
end
end
end
return quarters
end
function scannPredict(quart)
local predictTable = {}
local found={}
for i=quart.pi,quart.ki do
predictTable[i]={}
os.execute("postep "..(i-quart.pi).." 32")
for j=quart.pj,quart.kj do
predictTable[i][j]=component.geolyzer.scan(i,j)
local count = math.floor((math.abs(i)+math.abs(j))/8)
for c=0,count do
predictTable[i][j]=add(predictTable[i][j],component.geolyzer.scan(i,j))
end
predictTable[i][j]=div(predictTable[i][j],count+2)
for z=1,64 do
if predictTable[i][j][z] > 2.5 then
found.x = i
found.y = j
found.z = z-32
found.hardness = predictTable[i][j][z]
component.modem.broadcast(101, serial.serialize(found))
end
end
end
end
end
local quart = quarters(1)
scannPredict(quart)
print(1)
quart = quarters(2)
scannPredict(quart)
print(2)
quart = quarters(3)
scannPredict(quart)
print(3)
quart = quarters(4)
scannPredict(quart)
print(computer.uptime()-startTime)