Skip to content

Commit

Permalink
fix: fix quantum computer
Browse files Browse the repository at this point in the history
  • Loading branch information
notnotmelon committed Aug 29, 2024
1 parent a9d3050 commit 4ed40c1
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 28 deletions.
7 changes: 4 additions & 3 deletions data.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
local tech_tree_screenshot_mode = false
if tech_tree_screenshot_mode then
for _, t in pairs(data.raw.technology) do
t.enabled = false
if t.normal then t.normal.enabled = false end
if t.expensive then t.expensive.enabled = false end
t.enabled = false
if t.normal then t.normal.enabled = false end
if t.expensive then t.expensive.enabled = false end
end
end

require 'lib.lib'
Expand Down
3 changes: 1 addition & 2 deletions info.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
"author": "notnotmelon, ArchEzekiel",
"homepage": "https://github.com/notnotmelon/maraxsis",
"description": "Dive into the uncharted waters of Maraxsis, a world where the sea covers everything. Utilize submarines to explore, deploy fiber optics for long-distance signals, build pressure domes, and master the challenges of deep-sea logistics. But BEWARE: You aren't alone in these depths...",
"factorio_version": "2.0",
"factorio_version": "1.1",
"dependencies": [
"base",
"space-age",
"! pystellarexpedition"
]
}
2 changes: 1 addition & 1 deletion locale/en/locale.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ h2o-quantum-coraldynamics=QCD (quantum-coraldynamics)
[tips-and-tricks-item-description]
h2o-maraxsis=todo
h2o-quantum-coraldynamics=QCD (quantum-coraldynamics) is used to create [item=h2o-heart-of-the-sea] via color confinement.\n\nThere are 6 quarkals:\n - [item=h2o-up-coral]\n - [item=h2o-down-coral]\n - [item=h2o-top-coral]\n - [item=h2o-bottom-coral]\n - [item=h2o-strange-coral]\n - [item=h2o-charm-coral]\n\nEach of these are combined in the [entity=h2o-quantum-computer].\nThere are 2^6-1 = 63 diffrent possible combinations.\n\nThe correct combination is randomized and unknown. It must be determined by an experiment.\nTo preform an experiment, add your quarkals to the [entity=h2o-quantum-computer] and provide 50 [fluid=brackish-water] to catalyze it.\nDuring a correct experiment a [item=h2o-heart-of-the-sea] is created and the secret combination will re-randomize.\n\nThe correct combination can be represented as a binary number where each quarkal is a bit.\nFor example if the secret was 101100 then the correct combination would be\n[item=h2o-up-coral] [item=h2o-top-coral] [item=h2o-bottom-coral].\n\nA failed experiment will generate some data about this hidden bit representation.\n\n[item=h2o-up-coral]:\n You have matched more bits than the previous experiment.\n\n[item=h2o-down-coral]:\n You have matched less bits than the previous experiment.\n\n[item=limestone]:\n You have matched the same amount of bits as the previous experiment.\n Limestone is always returned during the first experiment.\n\nNote that a combination of 000000 is impossible.\nMultiple [entity=h2o-quantum-computer] will have separate and unrelated correct combinations.
h2o-quantum-coraldynamics=QCD (quantum-coraldynamics) is used to create [item=h2o-heart-of-the-sea] via color confinement.\n\nThere are 6 quarkals:\n - [item=h2o-up-coral]\n - [item=h2o-down-coral]\n - [item=h2o-top-coral]\n - [item=h2o-bottom-coral]\n - [item=h2o-strange-coral]\n - [item=h2o-charm-coral]\n\nEach of these are combined in the [entity=h2o-quantum-computer].\nThere are 2^6-2 = 62 diffrent possible combinations.\n\nThe correct combination is randomized and unknown. It must be determined by an experiment.\nTo preform an experiment, add your quarkals to the [entity=h2o-quantum-computer] and provide 100 [fluid=brackish-water] to catalyze it.\nDuring a correct experiment a [item=h2o-heart-of-the-sea] is created and the secret combination will re-randomize.\n\nThe correct combination can be represented as a binary number where each quarkal is a bit.\nFor example if the secret was 101100 then the correct combination would be\n[item=h2o-up-coral] [item=h2o-top-coral] [item=h2o-bottom-coral].\n\nA failed experiment will generate some data about this hidden bit representation.\n\n[item=h2o-up-coral]:\n You have matched more bits than the previous experiment.\n\n[item=h2o-down-coral]:\n You have matched less bits than the previous experiment.\n\n[item=limestone]:\n You have matched the same amount of bits as the previous experiment.\n Limestone is always returned during the first experiment.\n\nNote that a secret combination of 000000 or 111111 is impossible.\nMultiple [entity=h2o-quantum-computer] will have separate and unrelated correct combinations.
[equipment-description]
nightvision-disabled-underwater=[img=utility/warning_icon] Nightvision does not function in Maraxsis trenches.
9 changes: 8 additions & 1 deletion prototypes/collision-mask.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ local water_placeable_blacklist = {
'container', -- haha
'curved-rail',
'electric-energy-interface',
'electric-pole',
--'electric-pole', todo: uncomment this when fiber optic is finished
'electric-turret',
'fire',
'fluid-turret',
Expand Down Expand Up @@ -49,6 +49,13 @@ local special_exceptions = {
'h2o-submarine-leg',
'h2o-diesel-submarine',
'h2o-nuclear-submarine',
'ee-infinity-accumulator-primary-output',
'ee-infinity-accumulator-secondary-output',
'ee-infinity-accumulator-tertiary-output',
'ee-infinity-accumulator-primary-input',
'ee-infinity-accumulator-secondary-input',
'ee-infinity-accumulator-tertiary-input',
'ee-infinity-accumulator-tertiary-buffer',
}
do
local temp = {}
Expand Down
13 changes: 2 additions & 11 deletions prototypes/quantum-computer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -163,18 +163,9 @@ data:extend {{
production_type = 'input',
pipe_picture = furnacekpipepictures_a(),
pipe_covers = pipecoverspictures(),
base_area = 0.5,
base_area = 1,
base_level = -1,
pipe_connections = {{type = 'input', position = {-4.5, 0}}},
secondary_draw_orders = {north = -1},
},
{
production_type = 'input',
pipe_picture = furnacekpipepictures_b(),
pipe_covers = pipecoverspictures(),
base_area = 0.5,
base_level = -1,
pipe_connections = {{type = 'input', position = {4.5, 0}}},
pipe_connections = {{type = 'input', position = {-4.5, -0.5}}, {type = 'input', position = {4.5, -0.5}}},
secondary_draw_orders = {north = -1},
},
},
Expand Down
6 changes: 3 additions & 3 deletions prototypes/tips-and-tricks/color-confinement.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ There are 6 quarkals:
- [item=h2o-charm-coral]

Each of these are combined in the [entity=h2o-quantum-computer].
There are 2^6-1 = 63 diffrent possible combinations.
There are 2^6-1 = 62 diffrent possible combinations.

The correct combination is randomized and unknown. It must be determined by an experiment.
To preform an experiment, add your quarkals to the [entity=h2o-quantum-computer] and provide 50 [fluid=brackish-water] to catalyze it.
To preform an experiment, add your quarkals to the [entity=h2o-quantum-computer] and provide 100 [fluid=brackish-water] to catalyze it.
During a correct experiment a [item=h2o-heart-of-the-sea] is created and the secret combination will re-randomize.

The correct combination can be represented as a binary number where each quarkal is a bit.
Expand All @@ -31,5 +31,5 @@ A failed experiment will generate some data about this hidden bit representation
You have matched the same amount of bits as the previous experiment.
Limestone is always returned during the first experiment.

Note that a combination of 000000 is impossible.
Note that a secret combination of 000000 or 111111 is impossible.
Multiple [entity=h2o-quantum-computer] will have separate and unrelated correct combinations.
82 changes: 75 additions & 7 deletions scripts/quantum-computer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ local BIT_ORDER = {
['h2o-strange-coral'] = 16,
['h2o-charm-coral'] = 32,
}
local TOTAL_BITS = table_size(BIT_ORDER)

local function calculate_matching_bits(secret, experiment)
local matching_bits = 0
for _, bit_value in pairs(BIT_ORDER) do
if bit32.band(bit_value, secret) == bit32.band(bit_value, experiment) then
matching_bits = matching_bits + 1
end
end
return matching_bits
end

h2o.on_event('on_init', function()
global.quantum_computers = global.quantum_computers or {}
Expand All @@ -22,7 +33,7 @@ h2o.on_event('on_init', function()
end)

local function generate_new_secret()
return math.random(1, 64)
return math.random(1, 63)
end

local function get_smallest_bucket_index()
Expand All @@ -48,7 +59,7 @@ h2o.on_event('on_built', function(event)
local quantum_computer_data = {
entity = entity,
unit_number = entity.unit_number,
previous_experiment = 0,
previous_experiment = nil,
secret = generate_new_secret()
}

Expand All @@ -57,18 +68,75 @@ h2o.on_event('on_built', function(event)
table.insert(global.quantum_computers_by_tick[bucket_index], quantum_computer_data)
end)

local HEART_OF_THE_SEA = 'h2o-heart-of-the-sea'
local LIMESTONE = 'limestone'
local DOWN_CORAL = 'h2o-down-coral'
local UP_CORAL = 'h2o-up-coral'

local function do_experiement(quantum_computer_data, current_experiment)
local secret = quantum_computer_data.secret
local current_matching_bits = calculate_matching_bits(secret, current_experiment)

if current_matching_bits == TOTAL_BITS then
quantum_computer_data.previous_experiment = nil
quantum_computer_data.previous_matching_bits = nil
quantum_computer_data.secret = generate_new_secret()
return HEART_OF_THE_SEA
end

local previous_experiment = quantum_computer_data.previous_experiment
local previous_matching_bits = quantum_computer_data.previous_matching_bits
quantum_computer_data.previous_experiment = current_experiment
quantum_computer_data.previous_matching_bits = current_matching_bits

if not previous_experiment then
return LIMESTONE
end

if not previous_matching_bits then
previous_matching_bits = calculate_matching_bits(secret, previous_experiment)
end

if current_matching_bits > previous_matching_bits then
return UP_CORAL
elseif current_matching_bits < previous_matching_bits then
return DOWN_CORAL
else
return LIMESTONE
end
end

--- invariant: quantum_computer_data.entity.valid
local function update_quantum_computer(quantum_computer_data)
local entity = quantum_computer_data.entity
local previous_experiment = quantum_computerata.previous_experiment
local secret = quantum_computer_data.secret

local fluidbox = entity.fluidbox[1]
if not fluidbox then return end
if fluidbox.amount < 49.999 then return end

local input = entity.get_inventory(defines.inventory.assembling_machine_input)
if fluidbox.amount < 99.999 then return end

local output = entity.get_inventory(defines.inventory.assembling_machine_output)
if not output.is_empty() then return end
local input = entity.get_inventory(defines.inventory.assembling_machine_input)
if input.is_empty() then return end

game.print('has input')

local contents = input.get_contents()
local experiment = 0
for coral, bit_value in pairs(BIT_ORDER) do
if contents[coral] then
experiment = experiment + bit_value
end
end

game.print('bits: ' .. experiment)

local result = do_experiement(quantum_computer_data, experiment)
output.insert {name = result, count = 1}

for item in pairs(contents) do
input.remove {name = item, count = 1}
end
end

h2o.on_nth_tick(UPDATE_RATE, function()
Expand Down

0 comments on commit 4ed40c1

Please sign in to comment.