Dice inside the computer
Würfel im Computer
Games need dice. Where does the spider stand? Which sword does the chest hold? Is this cube a meadow or a lake?
Spiele brauchen Würfel. Wo steht die Spinne? Welches Schwert liegt in der Truhe? Ist dieser Würfel eine Wiese oder ein See?
But a computer is an exact machine. It does the same thing every time. It cannot really roll a die!
Aber ein Computer ist eine ganz genaue Maschine. Er macht jedes Mal dasselbe. Er kann gar nicht richtig würfeln!
So it uses a trick. It takes a number and puts it through a scrambling formula. Out comes a new number that looks random. Put that one through the formula again, and you get the next one. And so on, forever.
Darum benutzt er einen Trick. Er nimmt eine Zahl und steckt sie in eine Durcheinander-Formel. Heraus kommt eine neue Zahl, die zufällig aussieht. Steck die wieder in die Formel, und du bekommst die nächste. Und so weiter, für immer.
The very first number is called the seed. Everything grows from the seed, like a plant.
Die allererste Zahl heißt Seed (englisch für Samenkorn). Alles wächst aus dem Seed, wie eine Pflanze.
The big secret
Das große Geheimnis
The same seed always gives exactly the same numbers, in the same order.
Derselbe Seed gibt immer genau dieselben Zahlen, in derselben Reihenfolge.
So the same seed gives the same world: the same hills, the same rivers, the same monsters in the same places.
Also gibt derselbe Seed dieselbe Welt: dieselben Hügel, dieselben Flüsse, dieselben Monster an denselben Stellen.
Try it in the game: ?seed=123 and then ?seed=124.
Visit them twice. The town is always there, but the cubes behind it change with the seed.
Probier es im Spiel aus: ?seed=123 und dann ?seed=124.
Besuch jede zweimal. Die Stadt ist immer da, aber die Würfel dahinter ändern sich mit dem Seed.
Try it: same seed, same dice
Probier es: gleicher Seed, gleiche Würfel
Seed A and seed B start the same. Roll a few times: the seeded rows are the same every time. The bottom row uses the browser's own Math.random(), which picks a new secret seed itself, so it changes.
Seed A und Seed B fangen gleich an. Würfel ein paarmal: Die Reihen mit Seed sind jedes Mal gleich. Die unterste Reihe benutzt das eigene Math.random() des Browsers, das sich selbst einen geheimen Seed ausdenkt. Darum ändert sie sich.
This uses the game's real dice, the function mulberry32 from src/core/util.js.
Hier laufen die echten Würfel des Spiels, die Funktion mulberry32 aus src/core/util.js.
Why "not really random" is great
Warum "nicht wirklich zufällig" super ist
Hunting bugs
Fehlerjagd
If a bridge is broken in world 123, a developer can open world 123 and see the exact same broken bridge. Fixing a bug you cannot see again is almost impossible.
Wenn in Welt 123 eine Brücke kaputt ist, kann ein Entwickler Welt 123 öffnen und genau dieselbe kaputte Brücke sehen. Einen Fehler zu reparieren, den man nicht wiederfinden kann, ist fast unmöglich.
Tests
The game's tests build hundreds of worlds with fixed seeds and check them. Because the seeds are fixed, a test that passes today passes tomorrow, unless the code changed.
Die Tests des Spiels bauen Hunderte Welten mit festen Seeds und prüfen sie. Weil die Seeds fest sind, besteht ein Test, der heute besteht, auch morgen, außer der Code hat sich geändert.
No cheating
Kein Schummeln
What a monster drops is decided by the world seed and the monster's name. If you die and the monster comes back, it drops the same thing again. Dying on purpose does not give you better loot!
Was ein Monster fallen lässt, hängt vom Welt-Seed und vom Namen des Monsters ab. Wenn du stirbst und das Monster wiederkommt, lässt es dasselbe wieder fallen. Absichtlich sterben bringt dir keine bessere Beute!
Every cube gets its own dice
Jeder Würfel bekommt eigene Würfel
If the whole world used one row of dice, building cube A first or cube B first would change both of them. Messy!
Würde die ganze Welt eine einzige Würfelreihe benutzen, dann würde es beide verändern, ob zuerst Würfel A oder Würfel B gebaut wird. Chaos!
So every cube makes its own seed: it mixes the world seed with its own name, like "2,-1,0" (that is: 2 east, depth 1, 0 south).
Darum macht sich jeder Würfel seinen eigenen Seed: Er mischt den Welt-Seed mit seinem eigenen Namen, zum Beispiel "2,-1,0" (also: 2 nach Osten, Tiefe 1, 0 nach Süden).
The mixer is called a hash: a formula that turns anything into a number that looks random. A tiny change in the name gives a totally different number.
Der Mixer heißt Hash: eine Formel, die alles in eine Zahl verwandelt, die zufällig aussieht. Eine winzige Änderung im Namen gibt eine völlig andere Zahl.
The walls between cubes, the monsters, the loot and the decorations get their own streams too.
Die Wände zwischen Würfeln, die Monster, die Beute und die Deko bekommen auch eigene Zahlenreihen.
A bag of marbles
Ein Beutel voller Murmeln
Not everything should be equally likely. A rare sword should be rare! So the game uses weights: imagine a bag with 24 grey marbles (Junk), 40 white (Common), 22 green (Uncommon) and 8 blue (Rare). Grab one without looking.
Nicht alles soll gleich wahrscheinlich sein. Ein seltenes Schwert soll selten sein! Darum benutzt das Spiel Gewichte: Stell dir einen Beutel vor mit 24 grauen Murmeln (Junk = Schrott), 40 weißen (Common = gewöhnlich), 22 grünen (Uncommon = ungewöhnlich) und 8 blauen (Rare = selten). Greif blind hinein.
The game uses this for almost every choice: which kind of cube, which archetype, which monster, which sword, which name.
Das Spiel benutzt das für fast jede Wahl: welche Art Würfel, welcher Archetyp, welches Monster, welches Schwert, welcher Name.
The real dice: mulberry32
Die echten Würfel: mulberry32
Don't worry about every symbol. Here is the idea:
Keine Sorge wegen jedem einzelnen Zeichen. Das ist die Idee:
mulberry32(seed)gives you a function. Each time you call it, you get the next number between 0 and 1.mulberry32(seed)gibt dir eine Funktion. Jedes Mal, wenn du sie aufrufst, bekommst du die nächste Zahl zwischen 0 und 1.- Inside,
aremembers where we are. Each call adds a big odd number to it. - Innen merkt sich
a, wo wir gerade sind. Jeder Aufruf zählt eine große ungerade Zahl dazu. Math.imul,^and>>>multiply, flip and shift the bits: they shuffle the number like a deck of cards.Math.imul,^und>>>multiplizieren, kippen und verschieben die Bits: Sie mischen die Zahl wie ein Kartenspiel.- Dividing by 4294967296 (that is 232) squeezes the result between 0 and 1.
- Das Teilen durch 4294967296 (das ist 232) quetscht das Ergebnis zwischen 0 und 1.
To roll a die: Math.floor(R() * 6) + 1.
Um einen Würfel zu werfen: Math.floor(R() * 6) + 1.
The real marble bag
Der echte Murmelbeutel
This bag picks a cube's archetype, its one big shape. Read it like the marble demo:
Dieser Beutel wählt den Archetyp eines Würfels, seine eine große Form. Lies es wie die Murmel-Demo:
wis the list of choices and their weights. The theme sets them, and the kind of cube leans them: a lake cube makes islands three times more likely.wist die Liste der Möglichkeiten mit ihren Gewichten. Das Thema legt sie fest, und die Art des Würfels neigt sie: Ein See-Würfel macht Inseln dreimal wahrscheinlicher.R() * sumthrows the needle onto the line.R() * Summewirft die Nadel auf die Linie.- The loop walks along: subtract each weight. When we go below zero, that's our pick.
- Die Schleife läuft entlang: Zieh jedes Gewicht ab. Wenn wir unter null kommen, ist das unsere Wahl.
- The last line is a safety net that should never be needed.
- Die letzte Zeile ist ein Sicherheitsnetz, das nie gebraucht werden sollte.