Dwarf Fortress Computer - help me understand

A person with too much time on his hands apparently built a working calculator inside the computer game Dwarf Fortress using only elements from the game. Link has lots of images and a video as well. To me this thing looks ridiculously complex, and I just cannot figure out how it works. I do find it extremely cool, though.
So: Dwarf Fortress experts and binary calculator mavens of the Dope: Fight my ignorance about this thing. How does it work, what principles are applied, and how on earth can you construct something like this within a game?

Mods: Please don’t move this to CS - even though it is a question about a game, I think the chances of getting an answer will be better here.

Well, it’s entirely possible to build all of the components of a calculator using only binary gates (AND, OR, ,etc.). For instance, here’s a binary multiplier.

If Dwarf Fortress allows the game designer to create game objects that behave like gates, then the designer can string those objects together to create scenes that behave like circuits constructed from those gates. Presumably one needs to understand the game to know how to input data and read the output.

Ridiculously complex is about the size of it!

But yeah, at the fundamental level, you only need a few very simple primitives to build a computer. As cwthree says, at the abstract level, the basic binary logic operations are sufficient; in fact, you can get away with only a single operation if it is functionally complete, like NAND.

So the trick to building a Dwarf Fortress computer would be coming up with designs for the fundamental components (logic gates) and the components derived from them, like I/O and memory cells. And then, of course, getting your dorfs to actually build thousands of those components, and keeping them sufficiently well supplied with booze during the construction so they don’t snap and bring the whole project down in an orgy of manic-depressive rage and violence. :smiley:

Of course, Dwarf Fortress gives you a lot of things to play around with, so just designing a DF NAND gate and then deriving the rest of your computer from that would be incredibly inefficient. A lot of things you should be able to build directly. There is a breakdown of the design of a lot of the basic components in the Dwarfputer Project Sheet which is linked to on that DFMA page. It looks like his memory cells, for example, are implemented with fluid pumps and hatches to regulate the amount of water in a recessed area. If there’s enough water in the cell, it contains a “1”, otherwise it contains a “0”. A memory cell can be queried by applying power to one of the gear assemblies attached to it, in which case another of the assemblies, one designated as output, will become powered (or unpowered) depending on the water content.

Another component is the decoder. This is a unit that takes as input an n-bit number (IOW, it was n “input wires”), and depending on what that number is, activates the corresponding one of 2^n “output wires.” Here is a simple 2-bit decoder, built using only AND gates and NOT gates. If the inputs {A0,A1} are equal to {1,1} (binary for the number 3), the output wire D3 will be “on” and all the others will be “off.” If the input is {0,0}, output D0 will be on and D1,D2,D3 will be off.

A decoder is useful in many, many ways, but one way in particular is to translate a memory address so that a line going to the correct bank of memory cells is activated. For example, Jong’s Dwarfputer has 256 bits of memory that are arranged as 32 eight-bit “words.” So his design uses a 5-bit decoder (5 inputs to 32 outputs). To retrieve the contents of memory address 25, the number 25 is sent as the binary signal “11001” on the five wires of the address decoder. The address decoder then activates its 26th output wire. That output wire is physically connected to the “read” inputs of a whole row of eight memory cells – so now each of them will transmit their contents onto the waiting memory read bus.

There are many, many more little details, of course, but they’re all variations on the same basic gates. It would probably be easier to just give you a basic overview of simple microprocessor design, and then talk about how the various fiddly bits could be implemented in Dwarf Fortress. How deep is your curiosity? :smiley:

Recently (last couple of months or so), someone posted a link to a video demonstrating binary addition with a wooden mechanical calculator. I can’t remember the thread*, but does that sound familiar to anyone?

In any case, it was an excellent visual representation of how to perform simple operations with binary. While it didn’t deal with logic gates mentioned above, it would be useful if the OP doesn’t understand how a series of full and empty chambers of water (1s and 0s) let you do useful operations.

*-Yes, I did spend a couple of minutes googling threads, but without remembering what the thread was about, I didn’t accomplish much. I vaguely remember talk of water-powered analog computer, if that helps anyone else.

Was it this device?

Yep! Thanks.

Thanks Stealth Potato - I do actually remember something from high school about breaking down complex calculations into simpler logic operations. Just reading your explanation makes me realize that this guy is crazier than I thought. It seems like Dwarf Fortress gives the player a lot of freedom to act in and on the game world. Could something like this be built in other sandbox games - like Sim City for instance?

I’m sure there are other games in which things like this could be built - there are lots of videos online of Rube Goldberg contraptions built using the game engine of some FPS or other - I don’t see why a Babbage-style mechanical computer wouldn’t be possible there.
I don’t think Sim City would easily support the necessary complexity or logic - most elements of the game are statistical with some kind of random factor in them - and the things that flow (traffic, water, power) are also statistical across the network, rather than discrete.

The closest thing that comes to mind is the calculator someone built in Little Big Planet: http://www.youtube.com/watch?v=ZiRgYBHoAoU&NR=1

Wow. That is amazing. It looked rather unimpressive at first, but when it zooms out towards the end you can really see the complexity of the thing. I really admire people who do stuff like this - though I can’t always see why; there seems to be no practial application of in-game machines like these. Proof of concept, perhaps?

It reminds me of some of the crazy Fantastic Contraption-machines people have built. Also the Sim City 3000 Magnasantiproject. I would love to see someone build something new and innovative - not just reproduce a real-world device.

You get a whole lot of freedom in DF, but it comes at the cost of severe micromanagement. You can’t just design a new level and be done with it; you have to make your dwarfs:

  1. dig out the space in the rocks or build walls and floors brick by brick (DF is a true 3D game; if you hadn’t noticed, the whole construction is over 30 levels high - click the “side view” or up/down buttons)
  2. gather all the raw material - wood (that you have to cut from trees), clay, rock, iron ore (that you have to smelt), animals (that you can skin to make leather), and then combine them into useful parts. Though cutting down into rock at least means you don’t have to construct bricks first.
  3. defend the construction and the workers against all kinds of invaders and psychotic coworkers (each and every dwarf “evolves” his own personality traits, and they can get frustrated and angry and highly dangerous to everything around them). Also; catsplosions and fish.
  4. keep your workforce fed, happy, drunk and alive long enough to get better at building and dragging materials around.
  5. for this kind of project, you need a power source; here it appears to be streaming water, which you usually have to dig for.

Is that a fairly recent addition? I played the game for a while some time back, and either I missed an entire dimension or it was not an option at that time.

It’s been in there at least for half a year, probably longer but that’s when I first tried it.

ETA: I just found a reference to Z-Levels dating from late 2007.

Well, damn. I must have missed it. Not that my fortresses were ever grand enough that I NEEDED another dimension, but it would have been cool nonetheless.

In the words of the game’s creator, “I think I made the fish too hardcore.”