-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpyramid.lua
73 lines (58 loc) · 1.63 KB
/
pyramid.lua
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
local settings = {
channel = 129,
base = 511
}
local function getModem()
local sides = {'left', 'right', 'top', 'bottom', 'front', 'back' }
for i=1, table.getn( sides ) do
if peripheral.isPresent( sides[i] ) and peripheral.getType( sides[i] ) == 'modem' then
return peripheral.wrap( sides[i] )
end
end
return nil
end
local function waitForMessage( modem )
local event, modemSide, senderChannel, replyChannel, message = os.pullEvent( 'modem_message' )
message = textutils.unserialize( message )
return {
cmd = message.cmd,
send = function( resp )
modem.transmit( replyChannel, senderChannel, textutils.serialize( resp ) )
end
}
end
local function beController()
local modem = getModem()
modem.open( settings.channel )
local jobs = generateJobs()
while true do
message = waitForMessage( modem )
if message.cmd == 'getjob' then
-- TODO: work on this
end
end
end
local function miningJob( x, z )
return {
x = x,
y = 0,
z = z,
length = settings.base
}
end
local function generateJobs()
local jobs = PQueue( function( j1, j2 )
local diff = j1.z - j2.z
if diff ~= 0 then
return -diff -- z starts at 0, but we go down
end
return j1.x - j2.x
end)
--just go down to 100. If we run out of jobs, more can be generated, but I assume we're closer than 100
for z = 0, -100, -3 do
for x = 0, settings.base - 1 do
jobs.insert( miningJob( x, z ) )
end
end
return jobs
end