v50 Steam/Premium information for editors
  • v50 information can now be added to pages in the main namespace. v0.47 information can still be found in the DF2014 namespace. See here for more details on the new versioning policy.
  • Use this page to report any issues related to the migration.
This notice may be cached—the current version can be found here.

v0.31:Creature logic

From Dwarf Fortress Wiki
Revision as of 01:49, 7 March 2012 by Quietust (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
This article is about an older version of DF.

Creature logic functions by taking advantage of creature's natural path-finding goals to trigger pressure plates. Creature logic is complete-- you can build memory, repeaters, or any sort of logical circuit.

Creature logic vs mechanical or fluid logic[edit]

Pro:

  • Creature logic requires no fluid or wind. In dry, windless environments, creature logic is the only kind of logic you can use.
  • Similarly, creature logic requires no infrastructure-- you can build your circuits anywhere, without worrying about bring water or power from one end of your map to the other.
  • All creature logic circuits can be designed with only stone and a pick-- although you're free to use wood or metal if you prefer!
  • Creature logic doesn't need anything but creatures to send or receive signals. There's no need to translate signals as with with mechanical logic.
  • Creature logic can be very intuitive. Watching creatures physically travel through your logic pathways simplifies debugging.
  • It's fun to watch the creatures run around!

Con:

  • Reliable creature logic requires a lot of hatches, doors, and mechanisms.
  • Creature logic requires creatures-- sometimes, a great number of creatures. Sometimes, those creatures die or have babies. Sometimes, they interrupt your dwarves. Sometimes, your dwarves fill them full of crossbow bolts.
  • Creature logic is vulnerable (surprise) to the presence of unexpected creatures in the logic circuits. Because creature logic circuits require a path either to the map edge or to the meeting hall (in most cases), this is a real possibility.
  • Creature logic requires large amounts of space.
  • It is (probably) not possible to design perfect delays with creatures in an unmodded game. Any creature logic timing devices will only ever work probabilistically.

Free range or one path[edit]

There are two incompatible design philosophies associated with creature logic-- mostly, the creatures you use will determine which is appropriate.

Free range creature logic generally gives a path to creatures when certain criteria are met, and otherwise, lets them wander (in a constrained space). This simplifies design and permits constant evaluation of criteria, but any creature that paces in captivity can easily foul up your circuits-- for instance, a pacing creature may prevent a door from closing, causing an AND to evaluate as true even though both operands were never true at the same time. Additionally, it gives no clear indication that an evaluation has been completed-- if you want to evaluate your AND statement, you only ever know that it's been evaluated as true, never as false.

One path design constrains creatures to a single tile when they have no path available. Whenever the creature is permitted movement for evaluation of operands, the creature is guaranteed one and only one path. This requires explicit designation of 'else' paths, and requires that operands be evaluated at specific times rather than undergoing constant evaluation, but guarantees complete reliability, and allows the circuit to return both 'true' and 'false' evaluations, meaning that you can know for sure that a signal has been evaluated, rather than guessing if the creature has had sufficient time to path or not path.

Gates[edit]

Creature logic relies on the ability or inability of a creature to path through a specific area. "One path" design requires explicit 'else' arms. Because of that, the following logic gates are shown in complementary pairs to guarantee a path to the creature.

All of these gates can be easily altered to take more than two operands.

Key[edit]

In all of the following diagrams, the creature is assumed to start at s (if given). p means that the square contains a path to the creature's pathing goal. Doors and hatches ¢ are displayed in the same color as the pressure plate ^ that links to them. If no pressure plate exists for a color, furniture of that color is opened or closed from outside of the circuit pictured; if a hatch and a door are the same color, that means they receive signals from the same source. Output pressure plates are displayed in magenta ^, as is any furniture in the circuit that is linked with the output plate. In the rare case that part of a circuit is linked with multiple elements, it will be displayed with foreground and background colors and explained in text-- for instance, ^ is linked both to cyan furniture and output.

Identity with NOT gate[edit]

^
s + O O + p
¢ +

This function takes a single operand. If the operand is true, the creature travels through the upper path (identity); otherwise, the creature takes the lower path (NOT). The pressure plate signals when the operand is true. This gate is the basis of all to follow.

Identity is also a simple delay. When the path receives a signal, it propagates it after a short period. That period depends on the speed of the creature moving through the gate.

AND gate with NAND gate[edit]

^
s + O O + p
+ ¢ +
¢

The doors at the top are both open if both operands are true (AND); the hatches at the bottom permit path if either operand is false (NAND). The pressure plate will signal when both operands are true.

NOR gate with OR gate[edit]

¢ ¢ ^
s + O O + p
+ +

The hatches at the top permit path only if neither operand is true (NOR); the doors at the bottom permit path if either operand is true (OR). The pressure plate will signal when neither operand is true.

XOR gate with expanded XNOR gate[edit]

O ¢
+ + ¢ ^
s + O O + p
+ + +
+ O O +
¢ ¢


As XOR is the intersection of OR and NAND, it is simply an OR followed by a NAND. The XNOR, as the union of AND and NOR, requires two arms. Each operand is linked to one door and one hatch in the XOR path, and to one door and one hatch in the XNOR path. The pressure plate will signal when either operand is true but not both are true. When modifying the XOR to take more than two operands, be careful to leave space between the doors and hatches as shown; this space is unnecessary for evaluation of two operands. Similarly, the expanded XNOR is appropriate when dealing with more than two operands, but a condensed version for taking only two operands exists (shown in the next circuit).


Expanded XOR with XNOR: Ordinal compare[edit]

This expanded XOR/XNOR can serve as an ordinal comparison-- XNOR implies equality, while the two arms of XOR, from north to south, imply that the first operand is greater than or less than the second operand.

¢
+ O O ^
+ ¢ +
s + O O + p
+ ¢ +
¢

The pressure plate will signal when the first operand is greater than the second operand. It can be adjusted to signal for less than, equal to, or any combination.

Multiple use[edit]

The gates above are single use gates; the creatures will escape after pathing through each gate. Circuits which return the creature to the beginning of the path are possible via altering the path in-route.

p
¢
s ¢ ^ O
p

This is one such device for re-routing creatures mid-path. Upon stepping on the pressure plate, the creature opens two hatches, thus blocking retrograde motion as well as access to its pathing goal, and opens a door, giving access to a new pathing goal. This new pathing goal can lead back to the original position of the creature. This principle is demonstrated in the designs to follow. Because the creature is constrained on the pressure plate, the door can be opened by outside mechanisms rather being linked to the pressure plate, permitting controlled movement of a creature through one or more arms of a circuit.

Creature memory[edit]

p ¢ ^ ¢ ¢ ^ ¢ p

This is a low latency version (not the simplest version, not the most full-featured) of creature-based memory. Each pressure plate is linked to each adjacent hatch. Memory is set by sending an open (followed closely by a close) to either door.

Note that in this diagram, both ends need to lead to the pathing goal. The creature can enter by either side, but will be constrained to either pressure plate during normal operation.

Clock generation, repeaters, and delay[edit]

Probabilistic movement rates combined with attribute rust make perfect clock generation impossible-- or at least, no one has done it yet. Without rust, however, its possible to design a device that will measure the speed of a given creature to any arbitrary level of confidence (less than total). Repeaters based on the rate with which creatures fall through open space hold promise for the design of perfect creature-driven delay.

The memory design above, slightly modified, can make a decent (not perfectly regular) repeater.

¢
p ¢ ^ ¢ ¢ ^ ¢ p
¢

Here, each pressure plate is linked to the two orthogonally adjacent hatches. The southern hatch is linked to the eastern pressure plate, while the northern hatch is linked to western pressure plate. This repeater tends to fire about every 250 ticks, with open and close signals offset by about 125 ticks, when built as shown. Although it's not a perfect delay, over sufficient repetitions, after attribute rust has run its course, the repeater will behave as a regular repeater-- that is, as the time for which it has ran approaches infinity, the repeater approaches full reliability. In other words: it's very effective at rapidly triggering any device with a refractory period of 100, and it's perfectly acceptable for running a calendar. Similar, non-repeating systems can be used to institute delay.

Linking both pressure plates to output doubles its rate, turning it into very effective spike repeater. The period can be increased by introducing floor space into the center of the design.

Signal management[edit]

Unlike mechanical logic, creature logic is sensitive to the precise messages sent by and to buildings-- that is to say, it differentiates between open and close signals. This can be seen as a curse or a boon. The following circuits are unlikely to be seen independent of other creature logic circuits; rather, these principles are likely to be integrated into circuits that also evaluate operands or store values.

Signal multiplication[edit]

p p
¢ ¢
O ^ ^ ¢ ^ O
¢ O O ¢
+ + ^ + +

North of the circuit is the pathing goal. The eastern and western pressure plates are linked to adjacent hatches. Input is linked to the hatch southeast of the eastern pressure plate and to the door. The central and southern pressure plates are linked to output. This circuit generates both an open and a close every time it is sent an open or a close signal from input -- that is, it generates two properly-ordered signals for every properly-ordered signal it is sent, allowing for edge triggered logic. Either output pressure plate can be removed to send an open and a close only upon receiving one kind of signal or the other kind of signal. Output can linked to the same device or to two different devices.

Signal division[edit]

p p
¢ ¢
O ^ + + + + + + + + ¢ ^ O
¢ O O ¢
+ + + + + + + + + + + +

The eastern and western pressure plates are linked to all adjacent hatches. Input is linked to the door and to the hatch southeast of the eastern pressure plate (which is also linked to the eastern pressure plate). The western pressure plate sends an output signal. This circuit generates an open signal the first time it is sent an open-close signal, and a close signal the second time it is sent an open-close. That is, the circuit generates one properly-ordered signal for every two properly-ordered signals it is sent. The order of these signals depends on creature placement-- with lever-based pre-toggling, the circuit could just as easily be understood to send a close signal and then an open signal. The circuit needs to be sufficiently long so that the creature does not reach the eastern pressure plate before the close part of the input signal is sent.

Alternative design[edit]

Multiple choices of furniture are available for the doors or hatches in the above diagrams. Various reasons exist for substitution.

Doorless design[edit]

Of all alternative designs, doorless design is the most practical. All doors are replaced with hatches over stairs or ramps, and the path continues one z-level down or up. This makes it more difficult to visualize the circuit, and some very efficient designs may require more significant changes, but every circuit possible can be created without doors. Use of hatches instead of doors protects against the effects of doors being blocked open by unexpected creatures or objects-- the original bug, after all, took the form of vermin remains. Retracting bridges can be used the same way, but lead to problematic delays.

Hatchless design[edit]

Hatchless design is much more difficult and of very limited use. Signal inversion can make a door act like a hatch; a raising bridge acts like a hatch. Both of these institute delays in processing that require large expansion of logic circuits and limit the effectiveness of memory, but they may be necessary when using submerged logic or flyers-- bragging rights for a logic system submerged in magma that processes via fire imps may be worth the headache.

Floodgate design[edit]

Floodgates can be used instead of any of the doors pictured; with signal inversion, they can also be used instead of hatches. Floodgates respond much more slowly than doors, but if obstructed, they close as soon as the obstruction is removed. This can be important, for instance, if your creatures give birth inside of your logic circuit.

Bridge design[edit]

Bridge design uses bridges instead of both doors and hatches. Doors are replaced with retracting bridges over ramps or staircases; hatches are replaced with raising bridges, or with retracting bridges over channels. Bridge design causes frustrating delays, but it is the only way to use building destroyers in a logic circuit. The irony of making your minotaur run an impossible labyrinth may be worth the design headache. As an added bonus, bridges are nearly unobstructable-- offensive vermin remains in your logic circuits will be smashed from this plane.

Creature choice[edit]

Multiple choices exist for creatures to run logic circuits. Each has its own advantages and disadvantages.

Domestic animals[edit]

Domestic animals are valid choices for creature logic, but come with a host of disadvantages. Many females are capable of giving birth inside of your logic gates; their children can block the closing of doors or set off pressure plates. Grazers, of course, will starve inside most logic circuits, although some special designs may be capable of supporting a grazer. Some domestics are too small to set off pressure plates; some are capable of flight, requiring hatchless design. All domestic animals will die of old age, requiring periodic replacement. Most domestic animals have relatively short lifespans. Logic involving domestic animals must be built with pressure plates that can be triggered by citizens, and building these circuits may turn into a nightmare of job cancellations and stranded, starving dwarves. Domestic animals have one huge advantage, however: the location of their pathing goal can be altered with direct, unmediated action of the player, by placement of a meeting zone.

Invaders[edit]

Invaders are readily available on most maps, rarely or never give birth, and require no sustenance. Pressure plates don't need to be built triggerable by citizens. Elves and goblins will never die of old age. However, invaders cause their own problems. Invaders can cause job cancellations, and in some circuits may escape, wreaking havoc deep in your fortress. Dwarves armed with bolts and crossbows will take potshots at your computers periodically. Finally, invader-based logic must have a path to the map edge for predictable pathing. If your logic circuit is inside of your fortress, walling off, even through something as simple as raising a bridge at your entrance, will lead to unpredictable pathing.

Dwarves[edit]

Dwarves themselves can be used to run logic circuits, and are perhaps the most interesting choice. While longer-lived than most domestics, dwarves starve and dehydrate easily, requiring frequent, careful maintenance. Idle dwarves path unpredictably; dwarves are vulnerable to drowsiness, leading to very high latency. Married female dwarves are fecund. At the same time, dwarves are excellent choices for logic circuits because of their varied pathing goals that can be altered through direct interaction by the player. Dwarves can trigger events both through the use of pressure plates and through the use of levers. In fact, one can see the entire game of Dwarf Fortress as one big logic circuit with dwarves as the driving creature.

Other choices[edit]

There are a few things to stay away from, but in general, any sufficiently understood creature can be used for creature logic. Building destroyers are problematic, but full-bridge design is possible. Likewise, flyers and swimmers cause difficulty, but nothing that can't be worked around. Creatures with trapavoid are unfortunately useless (with the possible exception of gremlins, who might be able to output via levers), as are creatures with a size less than 10000, as they're too small to set off pressure plates. The essence of creature logic, however, is predictable pathing. This may or may not exclude the use of certain types of wildlife.

Animal logic[edit]

Animal logic relies on a special case of free range creature logic that is specific to animals that are unable to open doors, by pathing them through tightly closed doors. Animal logic can be very space efficient and easy to build in comparison to most kinds of creature logic.