[Project] "Universal" Logic Gate (can be adapted to a variety of functions depending on wiring)

Discussion in 'Terraria Discussion Groups' started by DicemanX, Dec 7, 2014.

  1. DicemanX

    DicemanX Brain of Cthulhu

    Just wanted to share a neat little mechanism that can be used to simulate any logic gate. Here is the minimal set-up:

    [​IMG] [​IMG]

    S = incoming pulse
    X and Y = inputs
    A, B, and C = potential outputs


    The incoming pulse activates the skeleton statue and instantly teleports the skeleton to the right teleporter and onto the hoik tooth. The hoik tooth propels the skeleton to the right, where it can take one of three paths, depending on whether one or both of the darkened blocks are in the actuated or deactuated state. If the middle block (a bottom hoik) is actuated then the skeleton will use the top hoik and be propelled upwards, passing over a pressure plate resulting in signal output A. If the bottom hoik is deactuated, but the block below it remains actuated then the skeleton is hoiked downwards, passing over a pressure plate that results in output C. Finally, if both blocks are deactuated then the skeleton is hoiked to the right, passing over a pressure plate that results in signal B.


    X=actuated Y=actuated
    output signal = A

    X=actuated Y=deactuated
    output signal = A

    X=deactuated Y=deactuated
    output signal = B

    X=deactuated Y=actuated
    output signal = C

    This universal gate can be used to simulate every possible logic gate although the starting actuated or deactuated state of the blocks might need to be set differently than what is depicted in the pic. All logic gates can be built so long as there are at least 3 potential outputs for the 4 possible input states, since any two potential outputs can be combined into one actual output by connecting the pressure plates with the same color wire. Furthermore, the skeleton statue can be replaced with a king or queen statue (and the lava needs to be removed) so that the player can be far away from any of the logic gates in the world and have them still function.

    The universal logic gate generates output signals in 3/60th of a second after an incoming pulse activates the statue (assuming the activation of the skeleton statue and teleportation is instantaneous), since jumping from one tooth to another tooth takes 1/60th of a second. Even though certain specific logic gates might be simpler to construct (the AND gate for instance can be trivially constructed with one hoik track), this "universal" gate is more flexible and can be adapted to suit various needs.
    Last edited: Dec 7, 2014
    Aditya, Smiffy, Mimp and 2 others like this.
  2. SharkB8

    SharkB8 Terrarian

    wow really good joe!
    this can bring so many new ideas in to play...:eek: :joy:
  3. Vendidurt

    Vendidurt Eye of Cthulhu

    This is awesome. Awesome to the max!!
  4. ZeroGravitas

    ZeroGravitas The Destroyer

    Good solid start on standardising hoiktronic logic. I think that the designs will vary a lot by context of implementation (not wholey modular), but it's very important to first understand the hoik switching principles, like this. :)
    I'd call this type-2 hoiktronics: free-flowing NPCs, as opposed to captive NPCs (type-1), as in my counter video. Either approach has it's advantages and disadvantages. For example an important limitation to note about your implementation (or type-2 in general) is statue spawn rate; you can only fire that logic gate once every 0.5s, as it is. And this is not an entirely trivial problem to overcome, although recycling NPCs (via teleporters and/or hoik flow returns) could help, for a start.

    As for your universal gate logic, I think the operation truth-table is as follows:
    Active/de-actuated/activation = 1, inactive/actuated/no-activation = 0
    Inputs|  Outputs  |
    X | Y | A | B | C |
    0 | 0 | 1 | 0 | 0 |
    0 | 1 | 1 | 0 | 0 |
    1 | 0 | 0 | 0 | 1 |
    1 | 1 | 0 | 1 | 0 |
    Note that fathoming the polarity of "(de)actuated" does my head in! :confused: lol. Is there even a recognised standard way of specifying this? (1 = solid, 0 = background seems clearer.)

    A = NOT(X)
    B = AND(X,Y)
    A + C = NAND(X,Y)
    ... I'm not seeing any more, is this right? Have you tried actuating the up-sloped tooth in the gate? And/or a square block directly above it?

    As far a future standards go, big questions are:
    • Do you reset the input gates after each activation?
    • Does linked circuitry rely on simultaneous activation (synchronous) or ripple-through (asynchronous)?
    • Others?...
    Very minor point: does the topmost up sloped block in the diagram not push the skeleton out to the left? (Irrelevant if he dies quickly anyway, of course).
    DicemanX likes this.
  5. DicemanX

    DicemanX Brain of Cthulhu

    Indeed, an NPC recycler can overcome that problem (we might have to use NPCs anyways for more elaborate projects). Alternately, if a Skeleton statue is used, it's possible to overcome the 0.5s limitation depending on the nature of the pulse. For instance, if the pulse comes from a prior mob activating a pressure plate embedded in a hoik, then you could set up multiple successive pressure plates connected to multiple skeleton statue activation points.

    The easiest however would be to recycle via teleporter, and have the incoming pulse deactuate the hoik tooth above the teleporter (tooth would be actuated again when returning via teleporter).

    The universal logic gate cannot be assigned a set truth table because for certain logic gate functions you'll have to reverse the actuation of one of the blocks that's currently actuated, or you'll have to extend the wiring from X or Y to cover both actuated blocks. For instance, based on your assignment, you cannot have an XOR gate, because the X=0 Y=0 and X=0 Y=1 states have the same output A.

    To have an XOR gate, one way to do it is to extend the green wire from Y so that it extends to both actuated blocks. This way when neither X nor Y inputs are activated the signal will be A. If there is an input at X, the signal will be C. If there is an input at Y, the signal will be at B. If there is a signal at X and Y, the down hoik will remain actuated leading to signal A. Then connecting the outputs B and C with the same wire will result in an XOR gate.

    Thus we need to be careful with assigning truth tables to this universal logic gate, because X/Y=0/1 will have different meanings in different wiring set-ups.

    It tries to escape but dies before it gets a chance.
    Last edited: Dec 7, 2014
  6. ZeroGravitas

    ZeroGravitas The Destroyer

    So what can we define here, in this thread? Are you working on illustrating how each specific type of logic gate can be wired?

    Also, you're not advocating building these as isolated wiring devices, are you? They could be receiving skeletons (or friendly NPCs) as inputs (and outputs).
    BYW, I used that term loosely, above, to mean all non-player characters, including monsters; skeletons may be worth recycling too, ofc. Do you think "NPC" should be reserved for the Guide and cohorts?
  7. DicemanX

    DicemanX Brain of Cthulhu

    The wiring can remain as illustrated for (N)AND and (N)OR gates since those are based on which of the potential outputs A, B or C is the true output. The wiring has to change slightly for X(N)OR gates by extending the input signal from X (or from Y) to both blocks with actuators on them. Thus if it helps some we could generate two separate truth tables, although I think truth tables can make things harder to follow especially in the case of the X(N)OR gate because X or Y being equal to 0 or 1 no longer correlates to actuated/deactuated states.

    Anything goes really when it comes to inputs or outputs so I'm not advocating anything specific.

    Yes - although the term NPC technically applies to mobs as well, I'd propose reserving that term for the guide and his cohorts.
  8. ZeroGravitas

    ZeroGravitas The Destroyer

    Makes it one hell of a lot easier for me to follow! (And keep in my head.) Anyway, it shouldn't matter what the internal workings of the gate are doing, the 0/1 input states are what we see on applied to the input, the state a torch would be in on the input wire. What you're saying is that we can define X and Y's input either way around. So:
    With X flipped (from my table 0s -> 1s), then OR = A + B (i.e. output from two plates on one wire), NOR = C.

    Then, like you say, EXOR and EXNOR require rewiring, which is a good trick (2 inputs to one block).
  9. Vendidurt

    Vendidurt Eye of Cthulhu

    I didnt know you could even MAKE logic gates until now! Now minecraft has got nothin on us!
  10. stupidjesse

    stupidjesse Official Terrarian

    im not sure if this is minecraft or terraria!!! im so confused!
  11. SharkB8

    SharkB8 Terrarian

    Definately terraria... Nothing of this measure is capable in minecraft. (With the compactnesss of this by any means)
  12. Vendidurt

    Vendidurt Eye of Cthulhu

    Not a modular one at least. I never have a lack of room in my buildings because I have hollows between floors of my houses and castles just for future wirings.
  13. SharkB8

    SharkB8 Terrarian

    Right. The way this is so densely packed is crazy compared to the various wirings behind minecraft builds. Thats all I am saying. I have no hate towards minecraft at all. :)
  14. inomanoms

    inomanoms Eye of Cthulhu


    It's funny that I independently came up with the exact same junction while working on the half adder of the Ripple Carry Adder and thought I had created something new.

    I reused this junction in my recent post on Simple Logic Gates in the guides forum. In comparison to your version, the hoiking actor here is immediately teleported into the junction and then hoiked to one of the three teleporters within a game tick. I also have the slanted block of the junction deactuated and the wiring from what would be "Y" in your schematic running through both blocks of the junction so "A" collects the result from when either Y or X is true. This, I find, is much more useful basic formulation of the junction since none of the basic logic gates differentiate between results from inputs 01 or 10. (Yes, I understand you addressed this in the post) It also allows you to create any and all of the basic gates with one junction without rewiring.

    I find it interesting how this is a four outcome junction that by block collision priority is reduced three outcomes. Do gates that differentiate between 01 and 10 actually exist?

    @ZeroGravitas, this is the second time I have seen you use the terms synchronous and asynchronous...

    DicemanX likes this.
  15. DicemanX

    DicemanX Brain of Cthulhu

    Yes. Three-state logic gates have three outputs: 0,1, and a high impedance state. The high impedance state is designed to render the gate inactive, and it uses a control input for that purpose. In that sense, the logic gate differentiates between the inputs. Here are the truth tables:


    These types of gates are typically used when multiple devices use the same output line, and these three-state logic gates make it so that only one device can use the output line at a time.

    Of course there's no need for such gates in Terraria engineering since Terraria allows us to "cheat" and accomplish the same goals as these gates in more efficient ways, but if we wanted to strictly emulate real-world logic gates then the Terraria universal logic gates in this thread can be used as three-state logic gates.
    Last edited: Dec 10, 2015
    inomanoms likes this.
  16. inomanoms

    inomanoms Eye of Cthulhu

    So if I wanted to try to recreated this gate, would a "0" suffice for HIZ, or there is there some fundamental difference here that I am not understanding?

    I don't know if I could incorporate this gate into my universal logic gate without making it unnecessarily complicated. I see two options. Either I have two wiring versions of the three way junction, or I try to move to a 4-way junction. Problem is, with my current 4 way junction from the full adder, the hoiking actor is teleported away from different locations in relation to the teleporter pad. Maybe there is a way to create a 4 way junction that maintains the hoiking actors position?
  17. DicemanX

    DicemanX Brain of Cthulhu

    Yes, a 0 for the control input would suffice for HiZ.

    For a universal logic gate with 4 output lines, you can join the two output lines that correspond to the 0 state of the control input and have that as the "HiZ" output line. The impedance can be simulated downstream by, for instance, altering a signaling agent's path so that it doesn't do anything regardless of the state of the other input. However, this is about as useful as having an internal reset in a logic gate - we don't bother because we use global resets. Similarly, there's really no need for a HiZ line because we have simple path selectors instead of systems where signals get sent through every logic gate, which would necessitate blocking those signals in all but one gate.
    inomanoms likes this.
  18. inomanoms

    inomanoms Eye of Cthulhu

    I think you could interprete HiZ differently in Terraria, if I understand what it is correctly. HiZ could be interpreted as avoiding path selection altogether, by teleporting the agent to the correct choice of path. Kind of like the figurative difference between a if, else if, else if... and a switch statement.

    You mean that you don't bother with internal resets because you use global resets ;D. Custom complex gates with global resets still have a drawback in terms of modularity and reuseability. Personally, I prefer custom logic gates too. Still love you Joe.
  19. DicemanX

    DicemanX Brain of Cthulhu

    Yes indeed, that's what I had in mind when I said we could use a simple path selector. A perfect example of a teleporter-based path selector is the selection of the appropriate hoik track to display a number or letter in a segmented display. A lesser known example is transferring the contents of different registers to the binary-to-decimal converter in the ALU.


    Agreed, in the case of recursive mechanisms an internal reset would be necessary. Also, once 1.3.1 is released, the logic gates will be a bit simpler to work with since they won't need a global reset of inputs and outputs - just the inputs.
  20. Cyborgium

    Cyborgium Terrarian

    This logic gate takes (coincidentally?) exactly one Minecraft tick (1/20 s), compared to Minecraft gates which take 1/10 s to 1/20 s.