by bmgxyz · 5y ago · 0 comments
Of course, the compiler would have no way to lay out the factory with respect to available resource deposits. Maybe that would have to be part of the specification as well? Or maybe the programmer (player?) could pass an empty map file as a compiler argument.
Also, this doesn't give any consideration to the tech tree or enemies within the game. I guess those could be compiler flags, as long as we're dreaming.
Look, all I'm saying is that it would be really cool to be able to check factories into version control.
https://github.com/ekimekim/factoriocalc/tree/generator
The factory it generates is a main bus design, with discrete "steps" on the bus that take certain inputs, process them in a standardized area, then put the output onto the bus. It also stops every so often for "compaction" where it reduces several low-throughput belts into fewer high-throughput belts. The whole area is covered by roboports to enable automated construction (no logistic robots are used, production is entirely done by belt) along with power lines etc.
The full layout looks like this:
||bus||
||||||| ...beacons...
vvvvvv\-> input to process
||||||
||||||/-- output from process
||||||| ...beacons...
in a repeating pattern, each process step sandwiched between two lines of beacons.It is very much not optimised, the idea was to make something as simple as possible that would work.
There's also a blueprint-to-ascii-art renderer which I added to help debug layout issues.
I haven't played factorio in a while but I do plan to keep working on this. Due to some poor choices early on implementing the last few fiddly (and less interesting) bits ended up being the bottleneck. In its current state it can go from raw inputs to a full suite of science packs, though some of the recipes are probably out of date, and I think there's some bugs in a few of the layouts that manifest in the finished blueprint as belts the wrong way around, etc.
You'd need some empirical data on train acceleration and top speed, but once you have that plus some generous assumptions about latency tolerances, you can probably automatically lay out tracks and train routes and resource outposts.
At some point, the inserter-to-belt interface becomes a serious bottleneck. CPU load does too. As for enemies, you can basically treat them as a solved or solvable problem after artillery even if you don’t turn them off.
Just connect blocks A and B in some hardware description language. Further describe B as an assembly of blocks A and C.
Ask a compiler such as yosys to flatten your hierarchy down to a set of primitive blocks (say, A and C). Once you have the diagram, use a custom placer and router to position it.
There might be additional constraints while placing blocks. In silicon, this relates to impedance, design rules, and making sure the clocks are properly synchronized (adding buffers, etc). In factorio, this could be making sure conveyors are the same length, placing extractors on resources, etc. But the general topology doesn't change, since you are the one specifying it.
Note: I've done some, but very little logic synthesis, this is really a bird view.
Does Verilog allow the description of throughput or a capacity constraint? I'm imagining a situation where a specific component (or belt) can only allow so many messages per second or needs less than a specified amount of current. Or is this concept somehow handled in a different way when specifying circuits?
---
It would be cool to have a CPU/GPU/Circuit design game that literally made a game out of designing logic gates and instructions as a game - but based on real-world circuit design....
As for your idea, Zachtronics had one for a while, but it was flash, so I don’t know if it still exists.
Thats the one
Most tools operate on the compressed, binary header including, base64 encoded blueprint strings, not the raw blueprint JSON payload.
The "compilers" for these languages have very sophisticated "routing" algorithms which synthesize efficient physical layouts of circuits.
Programs like Quartus even let you edit your description visually as an abstract block diagram by dragging around wires/placing blocks.
Electronics is just inherently 'parallelised', and software generally isn't, I get that. But some how we built up from parallel hardware to procedural synchronous (I know it isn't all but let's be honest it ~~all is) software, then built up further to sometimes wanting parallel again, and it's just sort of hard (er than it seems it should need to be) to use?
I challenge anyone who's used exclusively procedural languages to try an HDL (like Verilog or VHDL) or at least a high level declarative language (like Prolog or HCL/Terraform, as long as you view it as a language rather than config files) and not feel refreshed.
> Programs like Quartus
Egh, if I have nightmares tonight I'll know why!
Building complex logic ins declarative languages is one of the most rewarding things I've ever done. I tend to prefer a strong focus on type transformation when approaching a problem in any paradigm (I'd tend to read "Get the user's name" as "Create a transformation from a User ID to the User's Name and then cast the value") but just putting all the blocks for declarative programming together and then saying "Now, go!" is quite satisfying.
Clock signals do seem like a very useful abstraction (when I have my software-hat on) - not sure how you'd do it for a general purpose CPU however.
But 98% of the problem remains: generating a layout.
This probably gets the most interesting in the super-late game where players have unlocked all of the tech and are building megabases. Now that the making of everything has been automated, perhaps the building of everything should be automated as well.
Comparing Factorio to Satifactory (basically a simpler Factorio but in 3d space) - component layout gets a lot easier to optimize since you can essentially float rando chunks of logic in random parts of the sky - Factorio does have an interesting mod[1] to allow what's essentially a black-box subroutine but the majority of the headache is trying to build a relatively compact (and thus defensible) layout while also allowing yourself the room to re-tool the setup as needs change.
Building absolutely can be automated - there are a lot of self-replicating structures out there, most of which automate the forward deployment of defenses since that's a real issue you're going to need to deal with.
Yup that's exactly what I was thinking about. If you don't have to optimize, then you can mix and match heuristics to get the job done. If you have to optimize... now the search space gets real big real fast.
Optimizing layout is a very interesting problem and one interest component in Factorio in particular is that you have some real values to measure as output like:
1. Total space used
2. Total energy required (more inserters means more power - more belts usually means more space)
3. Throughput
4. Pollution produced
5. Tile-ability of the design.
6. Proportion of unused space within a bounding box
Probably a few other fun ones - it actually sounds like a pretty approachable problem to get objectively good results out of.
Given that sub factories in Factorio can be graded numerically on units/s output, and given that Factorio has a built in blueprint system, could one use ML to automatically create the most efficient blueprint possible for a given output?
This would be a great application for ML or genetic programming.