Options

Modeling Factorio with Category Theory: An extended puzzle

For several weeks now, I've been thinking about the video game Factorio as a kind of extended puzzle for many of the ideas presented in this course. I thought others might appreciate this puzzle too, so I wanted to share.

If you are unaware of the game, here's a brief summary. Factorio is an open-ended game where you build factories to harvest raw resources and convert them into a manufactured goods. You do this by building structures which convert some resources to other resources (at a certain rate). For example, a stone furnace smelts iron ore to iron plates (and requires coal for power). $$\mathrm{StoneFurnace}: \ \mathrm{IronOre} + \mathrm{Coal} \rightarrow \mathrm{IronPlate} $$ The wiki page has explanations for all game mechanics. You can probably already see the similarities to resources theories (Chapter 2) and codesign diagrams (Chapter 4).

Like real factories, we want to design efficient/effective factories that produce an end product at a given rate (or produce a given amount, etc.). A simple version of this question is this: how many factories do we need to make iron plates from iron ore and coal if we want to produce iron plates at a given rate \(r\)? As you can find here, the furnace makes 0.28 plates/sec so we would need \(n = \lceil \frac{r}{0.28} \rceil\) furnaces, and supply them with iron ore at a rate \(r\) and coal at a rate \(0.0225 n\) at least. This question is easy to answer with a single building, but gets harder as the factory gets more complicated. So the goal is to come up with a way to describe a factory using category theory, where

  • objects are resources/reagents/ingredients: iron ore, plates, etc.
  • morphisms are processes which convert resources/combinations of resources to other resources.

But with that category, we also want to be able to ultimately answer questions such as "How many furnaces do I need?", "At what rate do I need to produce a certain raw material to produce an end resource?"

I think there's several routes to an answer (as is often in science/math). Initially, I thought about this problem using feasibility relations (Chapter 4), but found it tricky to keep track of the resources. After reading Tai-Danae Bradley's booklet, I realized that the theme of functorial semantics is useful here. Instead of creating one category to capture both how recipes can be combined and the corresponding rates, we can split the problem into two slightly separate problems:

  1. Construct a category, call it \(\mathbf{Fact}\), which describes how recipes can be combined to produce bigger recipes.
  2. Construct a second category, call it \(\mathbf{Rate}\), which describes production, consumption, supply and demand rates for the resources and processes. And along with it, a functor \(F\) which maps recipe diagrams in \(\mathbf{Fact}\) to \(\mathbf{Rate}\) which tells us what the rates of production/consumption are.

Hopefully, this is enough info to get started. While I have some results for both problems, I'd rather not spoil the fun of discovering them for anyone else (at least until others have a chance to try it).

Comments

Sign In or Register to comment.