Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1] 2

Author Topic: A simple RNG for dwarfputing, Fun production, etc.  (Read 2001 times)

FearfulJesuit

  • Bay Watcher
  • True neoliberalism has never been tried
    • View Profile
A simple RNG for dwarfputing, Fun production, etc.
« on: December 07, 2011, 04:40:42 pm »

My current fortress defenses consist of upright spikes that can be raised and lowered.

It's easy enough to use a repeater, but what's the fun in that? Although you can- theoretically- design a repeater with a period above any number you care to choose, they're all basically working the same way, and they all repeat. Really, that just isn't any fun. Sooner or later, even if it's a decade from now, as the invaders get smarter, Toady's going to implement goblins that might have a shot at predicting the actions of a repeater-run upright spike system. And then, what will you do?

Fear not, dwarflings, I have the answer!

There are other pseudorandom number generators out there, I believe. There's at least one I know of, but it's pretty complex. I can't remember who designed it, but if I recall correctly you put a whole line of waterwheels under a dwarf-made waterfall, so that some of them had flow, and others didn't, and it changed every frame.

This RNG (PRNG?) is simpler.

First, you build...a repeater! There are many designs you could probably adapt if you so felt, but the one I would use is the pump-based repeater, which is at the bottom of the page here. Start it up and watch it grow.

Note that that repeater repeats every 400 steps, and goblins simply can't move fast enough to avoid upright spikes controlled by such a repeater. But no true dwarf attacks a dangerous mechanical project of limited purpose by making a merely adequate solution.

This is the gear setup:

Code: [Select]
  ☼
☼☼☼=====
  ☼☼
  ☼

where the ☼'s are gears, and the ====represents the power train going in. With a little ingenuity, you can make a separate axle traveling from each gear.

Each axle- and note, you'll have to input a crapload more power than 62 to keep this baby going, but I promise you it'll be worth it- will travel to a pump. Each pump draws from an unlimited supply of water. Here's how it should work, with a cross-section of a multi-Z level diagram: (+= floor, %%=pump, 0= wall, 7=unlimited source of water tile)

Code: [Select]
%%                          %%     
70                          07 
+0                          0+
 0                          0
 0                          0
 0++++++++++++++++++++++++++0


The pumps- there's more than one- pump water out of the water source and into a big chamber.

Now, you should find a random number generator- www.random.org is a pretty good one- to generate your key. Let's say we want a 7 by 7 chamber. We might line the walls with 3 pumps on each side. Then, we should put a pressure plate triggered by water on each of the floor spaces in the chamber. What we want, then, is to generate, in some fashion, a 49-digit number in base 8. In addition, this 49-digit number must contain no 0s- only 1 through 7. You can also get a 49-digit number in base 7, but you can't convert from base 10 to base 7 on your desktop calculator (I use Windows; dunno about Macs), while it's easy to convert from 10 to 8. It doesn't really matter how you do this, but for maximum effectiveness, do it in random or pseudorandom fashion.

Now, take that 49-digit number and write it in 7 strings of 7 digits each. I generated such a number:
3173472
2652346
4164762
1456455
2246376
7264136
2525727

This is the water depth you're assigning to each pressure plate. Now, assign each pressure plate to an upright spike trap- or anything else you need an RNG for, including a dwarfputer. Oh yes. You see now why this is much simpler and more useful than the waterwheel design? It may be a good policy to include some open floor hatches, else you'll get a big tub of 7/7 water before long. In any case, what you'll find is that you have an upright spike pattern that doesn't repeat. It isn't completely random, of course, but it is very close to it, and it's random enough for almost any purpose you might need. If it isn't quite random enough, this isn't a hard and fast design- you can expand it to be as big and as random as you need.
« Last Edit: December 07, 2011, 10:29:28 pm by dhokarena56 »
Logged


@Footjob, you can microwave most grains I've tried pretty easily through the microwave, even if they aren't packaged for it.

Ivir_Baggins

  • Bay Watcher
    • View Profile
Re: A pseudorandom number generator
« Reply #1 on: December 07, 2011, 05:00:02 pm »

This sounds awfully complicated. Let's do it!
Logged
Moab is my washpot, and over Edom shall I cast out my shoe.

Loud Whispers

  • Bay Watcher
  • They said we have to aim higher, so we dug deeper.
    • View Profile
    • I APPLAUD YOU SIRRAH
Re: A pseudorandom number generator
« Reply #2 on: December 07, 2011, 05:35:40 pm »

Yay for random death dealing machine!

Ok you, you, you, you and you? YEAH YOU. You're dead.

FearfulJesuit

  • Bay Watcher
  • True neoliberalism has never been tried
    • View Profile
Re: A pseudorandom number generator
« Reply #3 on: December 07, 2011, 07:44:36 pm »

I should probably add that this is currently theoretical, but I can't see why it won't work. I'll try it tonight.

Alright.

To speed up the process, I made a custom world with the highest possible number of embark points. I brought a shitton of wood and stone and brought three mechanics and as many masons. A seventh guy was a carpenter. We also brought 50 war dogs for protection because why the hell not? It proved to be a good choice, because the embark is infested by badger men; they stay away.

EDIT: I'm just about done with this baby. However, my internet is gone now, so I'll update tomorrow.


DOUBLE EDIT: I was able to get it done better than I thought. Here's the save- the pressure plates open and close a line of doors, except for two that the dwarves hadn't hooked up by the time I let the water in. I'll post some screenies tomorrow- otherwise, download this and take a look. It opens and closes the doors more slowly than I had hoped, but it works. Sooner or later, the draining chamber below it is going to fill up, and then you'll have to figure out something else. However, it does function as proof of concept.
« Last Edit: December 07, 2011, 09:24:24 pm by dhokarena56 »
Logged


@Footjob, you can microwave most grains I've tried pretty easily through the microwave, even if they aren't packaged for it.

stormtemplar

  • Bay Watcher
    • View Profile
Re: A pseudorandom number generator
« Reply #4 on: December 07, 2011, 08:32:26 pm »

If this works, I <3 you. Random complicated death dealing is epically dwarfy.
Logged
It's needlessly complicated and a hazard to cats.

I'll take twenty!

FearfulJesuit

  • Bay Watcher
  • True neoliberalism has never been tried
    • View Profile
Re: A pseudorandom number generator
« Reply #5 on: December 07, 2011, 10:10:18 pm »

Thanks.

I think the thing with the waterwheels had a problem: it's easy to think about, but it's hard to turn into a working machine- also, it's not as random. The reason for the latter is that, unless you are not hooking up any waterwheels to each other (and I think you'll have to because of space constraints), the output is a number. That sounds good for a random number generator, but in DF it's not, because then you have to translate that number into something- a number of gear assemblies that are on, probably. That's difficult to do. Also, depending on how much water there is in there, there may not be that much variance in the numbers produced, unless you make it really monstrous. In other words, although the waterwheel design is doable, it's as random as the most discerning of us might like, and it's a hell of a lot of work.

This design, on the other hand, isn't very much work at all compared to the waterwheels. You have to have a large number of mechanics, but a mature fortress shouldn't have much trouble with that. This design was up and running by mid-autumn of the first year, but you could probably do it in a season and a half in a big fort. It's also a lot more compact than the waterwheel design.

I think, and I know this sounds arrogant but I do believe it, that this is something that we've been looking for for a while but didn't know we were searching for. An easy-to-set-up, low-maintenance, compact RNG like this can be set up by anyone who knows their way around a dwarven mechanic's workshop, and the uses are probably endless. You could, for example, create a fortress with a very large RNG plate (that being the term for the floor with pressure plates on them), and put a door at the entrance to every room, even restricting access to parts of the fortress with doors. This creates a pleasantly labyrinthine setup, in which every door is hooked up to a plate, but you can never know when it will be opened or closed. This creates a very small but not insignificant Fun potential, for example if your booze stockpile is only accessible through a door that, by the whim of the gods, hasn't opened for six months and might open tomorrow, next week or not for another year.

And, on walking back home, I figured out an easy way to speed things up- hook everything up to more than one pressure plate. That's more time consuming, but if you need speed it's the best (only? probably not) way.

And in case you were wondering, the repeater is important. Here is why: suppose that the pumps are always on, and that the output tile of a pump had a pressure plate on it that triggered whenever there were just 2 units of water on it. Once the pump was turned on, that pressue plate would trigger. However, because it's an output tile, there are always going to be more than 2 units of water on it. To put it in mathematical terms, you could view the output of the save as a 14-digit (there were two holes in a 4 by 4 grid to let water into the draining chamber below) binary number. Let's say that that 2-unit output tile is read as the first digit of the numeral, and all the pressure plates are off: thus, 00.000.000.000.000 is the number before the screws are turned on. When they are turned on, we almost get a random number: we get 1x.xxx.xxx.xxx.xxx (x's being either 0s or 1s). AND THAT'S NOT RANDOM, because there's a predictable digit. If you actively changed the output tile's number so that it would cycle on and off, you'd have a non-random key (that is, the base 7 number which you randomly generated and assigned one digit of to each pressure plate), and that isn't random either, although it produces numbers that are more random than if you had a constant digit in all of your outputs.  That is why the repeater is important- and the more complex the repeater, the more randomness you can introduce. In the save, for example, the four gear assemblies that get turned on and off can be represented in a square:
xx
xx

But, because of the way the repeater works, they are on and off in the following cycle:
01 00 10 11
01 11 10 00

which works well enough for almost all purposes, but if somebody can find a better repeater, that introduces more randomness. In fact, the only reason you'd need another repeater would be to introduce more randomness in an application where any more randomness probably won't make any difference. The RNG you're seeing is as random as anybody'll ever need, but if you want a mental exercise, another sort of repeater might not be a terrible idea.

(By the way, I made the pressure plates only trigger when there was the assigned amount on top of them; you could make them trigger when there was that number or less, or that number or more, if you wished.)

tl;dr: the above machine uses the computer's pseudorandom number generator to produce binary numbers of any number of digits from a base-7 key with the same number of digits. Can be used to simulate randomness.
« Last Edit: December 07, 2011, 10:27:41 pm by dhokarena56 »
Logged


@Footjob, you can microwave most grains I've tried pretty easily through the microwave, even if they aren't packaged for it.

Anathema

  • Bay Watcher
    • View Profile
Re: A simple RNG for dwarfputing, Fun production, etc.
« Reply #6 on: December 07, 2011, 11:53:38 pm »

Please correct me if I misunderstand, but .. it's not really random, is it? I mean the initial pressure plate numbers you generate are random, but as long as those numbers don't change the system should ultimately repeat itself at some interval; it looks like a (potentially very large, but still finite) set of random outputs that get regularly repeated.

For example if a 1 plate and a 4 plate are beneath a certain pump, you should consistently see the 1 plate triggered immediately and the 4 plate triggered a certain (predictable) amount of time later. If two pumps are each over different 1 tiles, and your repeater has the first pump trigger immediately and the second pump triggers halfway through the repeater cycle, then you'll consistently see that first 1 trigger first and that second 1 trigger half a repeater cycle later, right? Sure by making the RNG plate bigger, or the repeater more complicated, you can make your finite set of outputs longer, but ultimately the whole set should still repeat predictably if I'm understanding it properly.

Wouldn't it be more random to just scatter pressure plates over areas your dwarves normally walk through, or even animal pens? (I've considered this same problem, trying to trigger something in a way that isn't regular/predictable, and that's the best solution I've thought of. You can even get things to trigger more or less often by choosing carefully where you put the pressure plate, i.e. dining hall vs. little-used stockpile, but either way it should not fall into any kind of repeated pattern).
« Last Edit: December 08, 2011, 12:18:27 am by Anathema »
Logged
The good news is that ghosts die of old age.

NightlinerSGS

  • Bay Watcher
    • View Profile
Re: A simple RNG for dwarfputing, Fun production, etc.
« Reply #7 on: December 08, 2011, 03:43:39 am »

Dwarf Fortress, the only game where players build complicated and pointless machines to solve problems that don't even exist yet.
Logged
Like I always say, elven females serve a... better purpose to me than the males.
This is a masterfully derailed thread. It depicts Necro in magma-silk thread. This relates to the great derailing of the Divorce Thread in 2011. Necro is holding up a pig-tail fiber sock. Necro is swimming. Necro is striking a defiant pose.

FearfulJesuit

  • Bay Watcher
  • True neoliberalism has never been tried
    • View Profile
Re: A simple RNG for dwarfputing, Fun production, etc.
« Reply #8 on: December 08, 2011, 08:30:00 am »

Please correct me if I misunderstand, but .. it's not really random, is it? I mean the initial pressure plate numbers you generate are random, but as long as those numbers don't change the system should ultimately repeat itself at some interval; it looks like a (potentially very large, but still finite) set of random outputs that get regularly repeated.

For example if a 1 plate and a 4 plate are beneath a certain pump, you should consistently see the 1 plate triggered immediately and the 4 plate triggered a certain (predictable) amount of time later. If two pumps are each over different 1 tiles, and your repeater has the first pump trigger immediately and the second pump triggers halfway through the repeater cycle, then you'll consistently see that first 1 trigger first and that second 1 trigger half a repeater cycle later, right? Sure by making the RNG plate bigger, or the repeater more complicated, you can make your finite set of outputs longer, but ultimately the whole set should still repeat predictably if I'm understanding it properly.

Wouldn't it be more random to just scatter pressure plates over areas your dwarves normally walk through, or even animal pens? (I've considered this same problem, trying to trigger something in a way that isn't regular/predictable, and that's the best solution I've thought of. You can even get things to trigger more or less often by choosing carefully where you put the pressure plate, i.e. dining hall vs. little-used stockpile, but either way it should not fall into any kind of repeated pattern).

I mean, you can't generate random. You can generate almost-random. And the machine I have is pretty almost-random.


Anathema: It might be more random; but this is a lot more systematic, and it's easier to do. And I'm not altogether sure, with the way dwarves path, that it would be very much more random. And if you're choosing carefully where you're putting your plates to create things that seem random...it's not random! This device tries to be as random as possible, and the place where there is the most room for improvement is the repeater. But that's not the part I invented- it's just a method for making the plate do its magic.

And no, it's not going to repeat predictably. Perhaps a certain plate (an output plate, for example) would act predictably, but every so often the other water on the plate will flow in such a way that the plate triggers when you didn't think it would. I mean, of course you can't generate true randomness in DF. As the plates get further away from the pumps, the less predictable it will become. It's very hard to generate true randomness- in real life you use either random.org, or you use a lump of radioactive material, neither of which are available to us (except random.org, in generating a plate). What this machine is is a device that is easy to set up and that will generate numbers that are as random as you need.
Logged


@Footjob, you can microwave most grains I've tried pretty easily through the microwave, even if they aren't packaged for it.

krenshala

  • Bay Watcher
    • View Profile
Re: A simple RNG for dwarfputing, Fun production, etc.
« Reply #9 on: December 08, 2011, 09:38:01 am »

I've been trying to think if there is a way to take advantage of the already sorta-random (as opposed to pseudo-random) way water moves and spreads out in DF that would simplify things for this ...

I'm not having much luck, however, coming up with something more than is already here other than this observation: what if your room was + shaped, with each arm being an odd number of tiles wide with a pump adding water in each outside corner, and a drain in at least the middle of the plus to prevent the water level from getting to high. Don't put plates in the pump output tiles or the drain tile(s) since they have predictable values (full or mostly empty). we know the water will flow toward the drain from teh pump, but the exact water level will fluctuate.  testing what those levels are at should allow us to select plate triggers that make this work about as random as you can get on a computer, in a program driven by procedural output. ;)
Logged
Quote from: Haspen
Quote from: phoenixuk
Zepave Dawnhogs the Butterfly of Vales the Marsh Titan ... was taken out by a single novice axedwarf and his pet war kitten. Long Live Domas Etasastesh Adilloram, slayer of the snow butterfly!
Doesn't quite have the ring of heroics to it...
Mother: "...and after the evil snow butterfly was defeated, Domas and his kitten lived happily ever after!"
Kids: "Yaaaay!"

FearfulJesuit

  • Bay Watcher
  • True neoliberalism has never been tried
    • View Profile
Re: A simple RNG for dwarfputing, Fun production, etc.
« Reply #10 on: December 08, 2011, 09:47:31 am »

I'm not sure...I don't think water would flow backwards towards the pump and it's probably going to stabilize before long.

Unless you have something in mind different from what I'm thinking...do you have a screenshot?
Logged


@Footjob, you can microwave most grains I've tried pretty easily through the microwave, even if they aren't packaged for it.

eggrock

  • Bay Watcher
    • View Profile
Re: A simple RNG for dwarfputing, Fun production, etc.
« Reply #11 on: December 08, 2011, 11:19:16 am »

66666
66666
66766

6 = 6/7 water
7 = 7/7 water

Pressure plate (or plates) trigger at 7/7

Random. Done.

With controls to start and stop:

77777
77777
777XX

7 = 7/7 water
X = Floodgate

Fill reservoir (with floodgates closed) to 7/7.
Start by opening both floodgates.
Stop by closing/opening both floodgates (or fill reservoir back to 7/7)

Opening the floodgates (both link to same lever) result in one tile @ 7/7 and the rest at 6/7. The 7/7 tile moves around more or less randomly. The larger the area, the longer the period.
« Last Edit: December 08, 2011, 11:23:57 am by eggrock »
Logged

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: A simple RNG for dwarfputing, Fun production, etc.
« Reply #12 on: December 08, 2011, 11:26:56 am »

I don't think that this design is nearly as random as it looks. To clarify, imagine (or build) a long tunnel with non-pressurized infinite water (either an aquifer tile or a diagonal connection to pressurized water) on one side and a drain on the other. If you let this setup run for long enough, the water levels will look sort of like this:
Code: [Select]
777676766656655554545455444434343332332322212212112111Almost totally linear.
So almost everywhere, you normally get variations of only one water level. So if you have a pressure plate toggling on 5 at the right end, it will never toggle. And if you have a pressure plate with 3 on the far left, you get the idea. Now, even if you have a pressure plate triggering on 4 at a place where it triggers often, but not always, there is still the pressure plate reset delay which makes the pressure plate be stuck on 'on', because it is triggered too often to eventually turn off.
Now if you connect the pumps to repeaters, the water level will fluctuate predictably, and the pressure plates will be triggered once per cycle. That's not random.
Now if you make the water slope steeper, the water may fluctuate a bit more, but there is still a recognizable sloping, out-of-place pressure plates will not trigger and in-place pressure plates will trigger too fast.
The real trick is to get it to trigger slow enough to let the pressure plate cool down.
A much more random and efficient strategy is to just fill a tank covered in 3/7 pressure plates with 2/7 water and add one or two buckets of water that slosh around. If you make the tank big enough and link spear traps up to multiple randomly chosen pressure plates, you'll get nice random behaviour. To make the spears go faster, add more linkups, not more buckets.

Edit: So Ninja'd.
Logged

FearfulJesuit

  • Bay Watcher
  • True neoliberalism has never been tried
    • View Profile
Re: A simple RNG for dwarfputing, Fun production, etc.
« Reply #13 on: December 09, 2011, 08:28:10 am »

Oh.

Well, that's much simpler... Kids, you should do that.

How do you get a chamber of just 2/7 water, though?
Logged


@Footjob, you can microwave most grains I've tried pretty easily through the microwave, even if they aren't packaged for it.

wierd

  • Bay Watcher
  • I like to eat small children.
    • View Profile
Re: A simple RNG for dwarfputing, Fun production, etc.
« Reply #14 on: December 09, 2011, 12:16:07 pm »

Compared to dreaming up an rng, getting a room at exactly 2/7 water is pretty easy.

Think about how you would go about watering a cavern growing room without a soil floor. You build a cistern of a certain size that can be filled from one end, and can be drained from another. To flood the room safely you close the cistern fill gate, then open the cistern release gate. This floods the room safely, reducing the amount of !fun! you get to enjoy.

Now, let's assume you have a 10x10 cistern, which you fill to 7/7. You want it to drain down to 2/7 evenly, the same as the room you want to flood to exactly 2/7.  This means you have (5*10*10)-2 units of water. (You have to subtract the water caught in the control gate when it closes.) This equals 498 units of water.  Square root that number, then divide by 2, and you have the number of tiles on each side of the square room to be flooded.

The cistern method ensures that only a fixed and controllable volume of water goes in.  I suppose that if you don't calculate for the destroyed/trapped water in the floodgate, you would get a few tiles of deeper water randomly floating between the cistern and the pressure switch room, which might be desirable.
Logged
Pages: [1] 2