Docstrings
TerrariaWiringHelper.AndGate — Type
(AndGate|XorGate){T<:Integer, V<:AbstractVector{<:Integer}}(gatestate::Bool, args::T, lampstates::V) <:AbstractGate
CombGate{T, V} = Union{AndGate{T, V}, XorGate{T, V}}Combinatory gates in Terraria. gatestate tells the default (when all inputs are zero) state of the gate. args tells the number of inputs. lampstates lists how the inputs are wired to each logic lamp.
Example
Consider AndGate(false, 4, [0x12, 0x09, 0x04]). It's an AND gate whose default state is OFF. Since there are 4 args (named a-d), we consider the last 5 bits of each entry of lampstates. The leading bit tells the default state of the lamps. The other 4 bits (from lower to higher) tell which args are wired to the lamp. i.e.,
0x12 = 0b10010means the default state of the first lamp isONand onlybis connected to the lamp.0x09 = 0b01001means the default state of the second lamp isOFFandaanddare connected to the lamp.0x04 = 0b00100means the default state of the third lamp isOFFand onlycis connected to the lamp.
julia> AndGate(false, 4, [0x12, 0x09, 0x04])
&(~b, ad, c)The output is visualized via gate2string.
TerrariaWiringHelper.CombGate — Type
(AndGate|XorGate){T<:Integer, V<:AbstractVector{<:Integer}}(gatestate::Bool, args::T, lampstates::V) <:AbstractGate
CombGate{T, V} = Union{AndGate{T, V}, XorGate{T, V}}Combinatory gates in Terraria. gatestate tells the default (when all inputs are zero) state of the gate. args tells the number of inputs. lampstates lists how the inputs are wired to each logic lamp.
Example
Consider AndGate(false, 4, [0x12, 0x09, 0x04]). It's an AND gate whose default state is OFF. Since there are 4 args (named a-d), we consider the last 5 bits of each entry of lampstates. The leading bit tells the default state of the lamps. The other 4 bits (from lower to higher) tell which args are wired to the lamp. i.e.,
0x12 = 0b10010means the default state of the first lamp isONand onlybis connected to the lamp.0x09 = 0b01001means the default state of the second lamp isOFFandaanddare connected to the lamp.0x04 = 0b00100means the default state of the third lamp isOFFand onlycis connected to the lamp.
julia> AndGate(false, 4, [0x12, 0x09, 0x04])
&(~b, ad, c)The output is visualized via gate2string.
TerrariaWiringHelper.XorGate — Type
(AndGate|XorGate){T<:Integer, V<:AbstractVector{<:Integer}}(gatestate::Bool, args::T, lampstates::V) <:AbstractGate
CombGate{T, V} = Union{AndGate{T, V}, XorGate{T, V}}Combinatory gates in Terraria. gatestate tells the default (when all inputs are zero) state of the gate. args tells the number of inputs. lampstates lists how the inputs are wired to each logic lamp.
Example
Consider AndGate(false, 4, [0x12, 0x09, 0x04]). It's an AND gate whose default state is OFF. Since there are 4 args (named a-d), we consider the last 5 bits of each entry of lampstates. The leading bit tells the default state of the lamps. The other 4 bits (from lower to higher) tell which args are wired to the lamp. i.e.,
0x12 = 0b10010means the default state of the first lamp isONand onlybis connected to the lamp.0x09 = 0b01001means the default state of the second lamp isOFFandaanddare connected to the lamp.0x04 = 0b00100means the default state of the third lamp isOFFand onlycis connected to the lamp.
julia> AndGate(false, 4, [0x12, 0x09, 0x04])
&(~b, ad, c)The output is visualized via gate2string.
TerrariaWiringHelper.CombLogic — Method
CombLogic(lamps, inputs, outputs::AbstractVector{Bool})Return the lists of possible combinatory logics for given inputs and outputs.
Arguments
lamps::Integer: the number of logic lamps on the gate, from2to7.inputs::AbstractVector{<:Integer}: the list of input values specified by the lower bits of entries, with a1in front of the first bit.outputs::AbstractVector{Bool}: the expected return values of the logic. This should have the same length asinputs, although it's not strictly checked.
Example
Imagine we want to check if a 4-bit input can be divided by 3. Further, the input is expected to have only one decimal digit, i.e. in 0:9. We don't care how the logic behaves for inputs 10:15. The truth table would be
| in | out | in | out | |
|---|---|---|---|---|
| 0000 | true | 0101 | false | |
| 0001 | false | 0110 | true | |
| 0010 | false | 0111 | false | |
| 0011 | true | 1000 | false | |
| 0100 | false | 1001 | true |
Now we try to find a configuration with least lamps.
julia> inputs = 16:25; # `0:9` with the 5th last bit set to `1`
julia> outputs = [true, false, false, true, false, false, true, false, false, true];
julia> CombLogic(2, inputs, outputs) # there is no 2-lamp logic
Union{AndGate{Int64, StaticArraysCore.SVector{2, UInt8}}, XorGate{Int64, StaticArraysCore.SVector{2, UInt8}}}[]
julia> CombLogic(3, inputs, outputs) # there are 12 3-lamp logics, all of which use XOR gates
12-element Vector{Union{AndGate{Int64, StaticArraysCore.SVector{3, UInt8}}, XorGate{Int64, StaticArraysCore.SVector{3, UInt8}}}}:
^(~b, ad, c)
^(~b, abd, bc)
^(~ac, ad, ab)
^(~ac, abd, a)
^(~ac, cd, bc)
^(~ac, bcd, c)
^(~bd, c, a)
^(~bd, bc, ab)
^(~bd, cd, ad)
^(~bd, bcd, abd)
^(~acd, bc, c)
^(~acd, abd, ad)See also CombGate
TerrariaWiringHelper.fuse — Method
fuse(setup::Integer, input::Integer) = fuse(setup & input)Return the state of a tile connected to multiple wires. Each bit of setup represents the state of a wire, and each bit of input represents the connection of a wire to the tile.
TerrariaWiringHelper.fuse — Method
fuse(input::Integer)Return the state of a tile connected to multiple wires. Each bit of the input represents the state of a wire.
Examples
julia> TerrariaWiringHelper.fuse(0b0110)
false
julia> TerrariaWiringHelper.fuse(0b1011)
trueTerrariaWiringHelper.gate2string — Method
gate2string(G::CombGate)Convert a CombGate into a readable string. See also CombGate, lampstate2string, logicsymb.
TerrariaWiringHelper.hasallcolor — Method
hasallcolor(G::AbstractGate, mask::Integer)
hasallcolor(mask::Integer) = Fix2(hasallcolor, mask)Check if some gate is connect to some wires.
TerrariaWiringHelper.hascolor — Method
hascolor(lampstate::Integer, mask::Integer) = lampstate & mask
hascolor(mask::Integer) = Fix2(hascolor, mask)
hascolor(G::AbstractGate, mask::Integer) = any(hascolor(mask), lampstates(G))Check if some lamp is connected to some wire (combination), or if some gate has a such lamp.
TerrariaWiringHelper.lampstate2string — Method
lampstate2string(lampstate::Integer, args::Integer)Convert binary coded lampstate into a readable string. args tells the number of distinct inputs.
Examples
julia> lampstate2string(0b1111, 4)
"abcd"
julia> lampstate2string(0b11101, 4)
"~acd"
julia> lampstate2string(0b10000, 4)
"~"TerrariaWiringHelper.logicsymb — Method
logicsymb(::typeof(AND|XOR)|::CombGate)Return '&' or '^' according to input.