class: center, middle # Instant Architecture in Minecraft using Box-Split Grammars ## Markus Eger ### Cal Poly Pomona ### www.slothlab.info --- # Grammars $$ S \rightarrow a S a \\\\ S \rightarrow b S b \\\\ S \rightarrow \varepsilon $$ * Grammars are a rewriting system * Repeatedly replace "nonterminal symbols" (variables) with "terminal symbols" (constants) * You could also see it as "refinement" * Very popular for text-based PCG --- class: medium # Shape Grammars and Such * I intentionally left "variables" and "constants" vague in this description * Instead of text, it could be "anything", like a shape * Enter Shape Grammars (Stiny and Gips, 1971)
.tiny[*Shape grammars and the generative specification of painting and sculpture.*, Stiny and Gips, 1971] --- class: medium # Box-Split Grammars * Geometric queries make Shape Grammars complex to implement * That's where the view of grammars as "refinement" comes in * We start with a large shape, like a box, and associate it with a nonterminal symbol * A rule splits such a labeled box into smaller boxes, and associates each with a new nonterminal symbol * Eventually we reach a "terminal" box, that we turn into a concrete material --- # Split Rules $$ N \rightarrow A\: B\: C\: [\text{split}(x, [1,2,1])] $$ * We need to specify a direction the split is performed in (here: x) * We need to specify sizes for the smaller boxes (here: 1, 2, and 1) * We then associate each smaller box with a new non-terminal (here A, B, and C) * The rules for A, B, and C then determine what happens to the smaller boxes --- # Split Rules in Python $$ N \rightarrow A\: B\: C\: [\text{split}(x, [1,2,1])] $$ In Python: ```Python @rule def N(): with split(Dimension.X, [1,2,1]): A(), B(), C() ``` Each rule has a straightforward Python-representation! --- class: medium # Function calls?! * To "associate" a box with a non-terminal, we just called a function, e.g. `A()` * But what if we want non-determinism? (Very relevant for PCG!) * Enter the `@rule`-decorator: It modifies the function such that when we call e.g. `A()` a **random** function among all functions named `A` is called! * In other words: The `@rule`-decorator determines which rules are **applicable** in each situation, and picks one among those * Applicable? --- # Rule Constraints * Say you want to build a castle * There are crennelations along the wall, i.e. an alternation between a stone and a gap * Depending on whether the length is even or odd, you will have a gap at the beginning and end, or only one one side ```Python @rule(constraint=(Dimension.X%2 == 1)) def Crennelations(): # other rule content ``` --- class: medium # Probabilistic Rules * For PCG, we often want variety * This was the reason for choosing a random rule (among all applicable ones) * But we don't necessarily want all rules to be used equally often ```Python @rule(probability=4) def N(): # rule content @rule(probability=1) def N(): # other rule content ``` This interacts nicely with rule constraints! Probabilities are normalized among all applicable rules. --- # Applications * The Box-Split Grammar system is implemented to be suitable for use in MCEdit * The system itself is actually domain-agnostic, with a small adapter for use with Minecraft * It is also designed to integrate nicely with other approaches: All you need is a box, and you can use any of the smaller boxes however you see fit * But you can do a lot just with the grammars by themselves! --- # Greek Temples * Greek temples are highly systematic * The base type (and name) depends on the number of columns across the front * Behind the columns there is usually a chamber ("naos"), which can have multiple styles of entrances * There may or may not be columns on the side and behind the naos as well * Grammar rules can encode the variety, as well as the necessary numbering constraints --- # Temple Floorplans
--- # Variety * Rule constraints select a fitting temple style * Different styles are chosen randomly (with controllable probabilities) * We can also add variety by adding different styles of roofs
--- # Using Images as the Backend
---
--- class: center, middle # Thank You For Your Attention ## meger@cpp.edu ## Twitter: @yawgmoth46 ## Code: https://github.com/yawgmoth/BoxSplitGrammars ## Slides: http://slothlab.info/fdg22