-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinit.lua
More file actions
254 lines (213 loc) · 7.91 KB
/
init.lua
File metadata and controls
254 lines (213 loc) · 7.91 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
local function add_vectors(vector1, vector2)
if type(vector1) == "table" and type(vector2) == "table" then
local result = {
x = (vector1.x or 0) + (vector2.x or 0),
y = (vector1.y or 0) + (vector2.y or 0),
z = (vector1.z or 0) + (vector2.z or 0)
}
return result
else
error("Both arguments must be tables representing vectors")
end
end
ie = minetest.request_insecure_environment()
local function insecure_load_file()
local mod_path = minetest.get_modpath("latticesurgery")
local json_file_path = mod_path .. "/crossings/grover_3.json"
f = ie.io.open(json_file_path)
s = f:read("a")
ie.io.close(f)
return minetest.parse_json(s)
end
local function insecure_load_crossings(index)
local mod_path = minetest.get_modpath("latticesurgery")
local json_file_path = mod_path .. "/crossings/crossings_3d_" .. index ..".json"
f = ie.io.open(json_file_path)
s = f:read("a")
ie.io.close(f)
return minetest.parse_json(s)
end
local function sleep(n)
ie.os.execute("sleep " .. tonumber(n))
end
local function array_to_s(a)
local r = ""
for i, k in pairs(a) do
r = r .. k
end
return r
end
local function stitch_border(border, patch_type)
if border == "AncillaJoin" then return true end
if border == "SolidStiched" then return true end
if border == "DashedStiched" then return true end
if border == "Solid" then return false end
if border == "Dashed" then return false end
if border == "None" and patch_type == "DistillationQubit" then return true end
return false
end
local function is_dead_cell(cell)
if cell['patch_type'] == "Ancilla" and
cell['edges']['Top'] == "None" and
cell['edges']['Bottom'] == "None" and
cell['edges']['Left'] == "None" and
cell['edges']['Right'] == "None"
then
return true
end
return false
end
local function max(a,b)
if a > b then
return a
else
return b
end
end
local function max_key(start, ll)
acc = start
for k,v in pairs(ll) do
acc = max(acc, k)
end
return acc
end
local function place_layers(starting_point, slices)
for t = 1, #slices do
for r, rval in pairs(slices[t]) do
for c, cval in pairs(slices[t][r]) do
local value = slices[t][r][c]
if value and (not is_dead_cell(value)) and value['patch_type'] ~= 'DistillationQubit' then
local connections = {0, 0, 0, 0, 1, 1};
if stitch_border(value['edges']['Top'], value['patch_type']) then connections[1] = 1 end
if stitch_border(value['edges']['Bottom'], value['patch_type']) then connections[2] = 1 end
if stitch_border(value['edges']['Left'], value['patch_type']) then connections[3] = 1 end
if stitch_border(value['edges']['Right'], value['patch_type']) then connections[4] = 1 end
if value['patch_type'] == 'Ancilla' then
if not value['routing_connect_to_prec'] then
connections[5] = 0;
end
if not value['routing_connect_to_next'] then
connections[6] = 0;
end
end
local name = string.format("latticesurgery:routing_%i_%s",t%12+1, array_to_s(connections))
if is_dead_cell(value) then
name = "latticesurgery:dead_cell"
elseif value['patch_type'] == 'DistillationQubit' then
name = string.format("latticesurgery:distillation_%s", array_to_s(connections))
elseif value['patch_type'] == 'Qubit' then
name = string.format("latticesurgery:qubit_%s", array_to_s(connections))
end
local position = add_vectors(starting_point, { x = r, y = t, z = c })
local existing_node = minetest.get_node(position)
if existing_node.name ~= "air" then
minetest.remove_node(position)
end
minetest.place_node(position, { name = name })
end
end
end
end
end
NUM_ROUTING_COLOURS = 12
for j = 0, 63, 1 do
-- j to bit string
local bitstring = {
math.floor(j / 32) % 2,
math.floor(j / 16) % 2,
math.floor(j / 8) % 2,
math.floor(j / 4) % 2,
math.floor(j / 2) % 2,
math.floor(j / 1) % 2};
minetest.register_node(string.format("latticesurgery:qubit_%s", array_to_s(bitstring)), {
description = string.format("Qubit %s", array_to_s(bitstring)),
tiles = {"qubit.png"},
drawtype = "nodebox",
node_box = {
type = "connected",
drawtype = "nodebox",
fixed = {
-3/8 - bitstring[1] * 1/8,
-3/8 - bitstring[5] * 1/8,
-3/8 - bitstring[3] * 1/8,
3/8 + bitstring[2] * 1/8,
3/8 + bitstring[6] * 1/8,
3/8 + bitstring[4] * 1/8},
},
groups = {cracky = 1} -- , falling_node=2}
})
minetest.register_node(string.format("latticesurgery:distillation_%s", array_to_s(bitstring)), {
description = string.format("Distillation volume", array_to_s(bitstring)),
tiles = {"distillation.png"},
drawtype = "nodebox",
node_box = {
type = "connected",
drawtype = "nodebox",
fixed = {
-3/8 - bitstring[1] * 1/8,
-3/8 - bitstring[5] * 1/8,
-3/8 - bitstring[3] * 1/8,
3/8 + bitstring[2] * 1/8,
3/8 + bitstring[6] * 1/8,
3/8 + bitstring[4] * 1/8},
},
groups = {cracky = 1} -- , falling_node=2}
})
for i = 1, 12, 1 do
minetest.register_node(string.format("latticesurgery:routing_%i_%s",i, array_to_s(bitstring)), {
description = string.format("Routing Volume color variation %i %s",i, array_to_s(bitstring)),
tiles = {string.format("routing_%i.png",i)},
drawtype = "nodebox",
node_box = {
type = "connected",
drawtype = "nodebox",
fixed = {
-3/8 - bitstring[1] * 1/8,
-3/8 - bitstring[5] * 1/8,
-3/8 - bitstring[3] * 1/8,
3/8 + bitstring[2] * 1/8,
3/8 + bitstring[6] * 1/8,
3/8 + bitstring[4] * 1/8},
},
groups = {cracky = 1} -- , falling_node=2}
})
end
end
minetest.register_node("latticesurgery:dead_cell", {
description = "Dead Cell",
tiles = {"dead.png"},
drawtype = "glasslike",
groups = {cracky = 1} -- , falling_node=2}
})
LS_LOCAL_START_POS = nil
local function set_pos(name, param)
local player = minetest.get_player_by_name(name)
LS_LOCAL_START_POS = player:get_pos()
end
minetest.register_chatcommand("set_pos", {
func = set_pos
})
local function crossings(name, param)
local slices = insecure_load_crossings(param)
if LS_LOCAL_START_POS ~= nil then
place_layers(LS_LOCAL_START_POS, slices)
else
local player = minetest.get_player_by_name(name)
place_layers(player:get_pos(), slices)
end
end
minetest.register_chatcommand("crossings", {
func = crossings
})
local function do_compile(name, param)
local slices = insecure_load_file()
if LS_LOCAL_START_POS ~= nil then
place_layers(LS_LOCAL_START_POS, slices)
else
local player = minetest.get_player_by_name(name)
place_layers(player:get_pos(), slices)
end
end
minetest.register_chatcommand("do_compile", {
func = do_compile
})