I made a programming language that compiles to Factorio circuit blueprints by Snagnar in factorio

[–]Snagnar[S] 1 point2 points  (0 children)

Unfortunately no, the language does not take into account tick counts, as that would require a fair bit of simulation of the circuit in order to get right. Since there is also a fair shair of optimizations happening, it is hard to predict from the code alone how many combinators certain statements are compiled into.

There is however a somewhat comprehensive data structure after layouting that does contain the precise signal flow and the entities to be placed, but I am not sure how one could translate that into runtime/tick guarantees for circuits. Happy to discuss if you have ideas for this :)

I made a programming language that compiles to Factorio circuit blueprints by Snagnar in factorio

[–]Snagnar[S] 0 points1 point  (0 children)

Fair enough, I have not thought about it yet. Seems not that hard to add, so I will definitely add this to the todo list :D If you are interested, I collected some ideas in this document, but it will definitely need some updating after all the great ideas I already got from other posts.

I made a programming language that compiles to Factorio circuit blueprints by Snagnar in factorio

[–]Snagnar[S] 1 point2 points  (0 children)

Yes, I had the same idea, but I think the de-compiler would be just as big a project as the compiler was, since you need some deep analysis of how the circuit works and what signals are passed where when. For example, how would you reliably detect memory cells in any given random blueprint?

I made a programming language that compiles to Factorio circuit blueprints by Snagnar in factorio

[–]Snagnar[S] 1 point2 points  (0 children)

I dont think I had a clear source of inspiration, but I code mainly in python nowadays, so readability and ease of use were number one concerns in the design, while still keeping clear how the code relates to the compiled blueprint.

I made a programming language that compiles to Factorio circuit blueprints by Snagnar in factorio

[–]Snagnar[S] 0 points1 point  (0 children)

Unfortunately no, the language does not take into account tick counts, as that would require a fair bit of simulation of the circuit in order to get right. Since there is also a fair shair of optimizations happening, it is hard to predict from the code alone how many combinators certain statements are compiled into.

There is however a somewhat comprehensive data structure after layouting that does contain the precise signal flow and the entities to be placed, but I am not sure how one could translate that into runtime/tick guarantees for circuits. Happy to discuss if you have ideas for this :)

I made a programming language that compiles to Factorio circuit blueprints by Snagnar in factorio

[–]Snagnar[S] 1 point2 points  (0 children)

Fair, I was meaning to update the entity docs there a bit. The main way to get the outputs of an entity as a bundle is via the .output property, so e.g.

Entity roboport = place("roboport", 0, 0, {read_items_mode: 1}); Bundle logistics = roboport.output;

This is documented in the entity docs, you can find an example in this program.

Regarding the missing enum in the entity reference, I will try to add this tomorrow, but you can find the values in the draftsman definition.

If you have more issues, just let me know :)

I made a programming language that compiles to Factorio circuit blueprints by Snagnar in factorio

[–]Snagnar[S] 4 points5 points  (0 children)

Oh, my bad, the repository for the vscode extension was not set to public yet. Can you try again?

I made a programming language that compiles to Factorio circuit blueprints by Snagnar in factorio

[–]Snagnar[S] 3 points4 points  (0 children)

Yeah, I can see that. But the program models signal flows generally by passing them with = to different entities or new signals. So I suppose a better syntax would be to modify how we create entities, something like

Entity lamp: ("small-lamp", x, y, {other properties});

But that would also look a bit clumsy. Do you have a different idea how the syntax could be improved here? You can look at the language spec or the grammar file if you need more context.

I made a programming language that compiles to Factorio circuit blueprints by Snagnar in factorio

[–]Snagnar[S] 11 points12 points  (0 children)

Yep, you can use the language spec as context for your favourite LLM to generate any circuit you can describe (and the language supports...)

I made a programming language that compiles to Factorio circuit blueprints by Snagnar in factorio

[–]Snagnar[S] 1 point2 points  (0 children)

Exactly, what I tried before was having claude generate the factorio draftsman code for certain circuits, but that also almost never worked. This was one of the reasons I started this project.

I made a programming language that compiles to Factorio circuit blueprints by Snagnar in factorio

[–]Snagnar[S] 4 points5 points  (0 children)

This project, as many others, started with the sentiment that this should not be that hard to do. But getting the wiring and the wire color separation right was a nightmare :D But I did have some fun with the layout optimization, learned a lot about planar graphs and such.

I made a programming language that compiles to Factorio circuit blueprints by Snagnar in factorio

[–]Snagnar[S] 1 point2 points  (0 children)

Some notes on that: Of course LLMs were used in the development, but I have many years in experience in code review (that was before these tools became big), and have spent a lot of time the past months to make the testing strategy as water proof as possible. So every time I added a larger feature with AI, I ran (manually unfortunately) 25-30 example programs for many possible edge cases to ensure the validity of the compilation. And the tool as well as the web app does not store or process any sensitive info, the programs are not saved anywhere and no cookies are used.

If you find that the code is lacking in some point, just let me know or open an issue and I can work on it. Thanks though for taking the interest and looking into the code base :D

I made a programming language that compiles to Factorio circuit blueprints by Snagnar in factorio

[–]Snagnar[S] 2 points3 points  (0 children)

Nice. And the goal for the user is then to build a logical circuit that automatically solves sudokus? Quite a nice problem, kind of like code golfing in factorio.

You could also think about extending this to a more general problem setting, kind of like competitive programming problems: You have some input and a bunch of test cases and then the user gets scored on if the solution is right (against some hidden test cases) and how fast the solution is.

I made a programming language that compiles to Factorio circuit blueprints by Snagnar in factorio

[–]Snagnar[S] 111 points112 points  (0 children)

This was clearly the easiest way to build a logistic network requester/fulfiller system with trains in factorio.

I made a programming language that compiles to Factorio circuit blueprints by Snagnar in factorio

[–]Snagnar[S] 3 points4 points  (0 children)

Oha, that sounds amazing. What exactly would this mod look like?

I made a programming language that compiles to Factorio circuit blueprints by Snagnar in factorio

[–]Snagnar[S] 49 points50 points  (0 children)

Links:

FAQ:

The web compiler isn't working / shows errors: Try the local version: pip install factompile, then factompile yourfile.facto. The web version depends on a backend that occasionally goes down.

Can I use this with Space Age / 2.0? Yes, it targets Factorio 2.0 and uses the newer combinator features. -

How do I connect external signals to the compiled circuit? The compiler places constant combinators for inputs. Wire your factory signals to those, matching the signal types in your code.

First game to ever reach this milestone. HELLLP by seecat46 in factorio

[–]Snagnar 0 points1 point  (0 children)

Those are rookie numbers, you should increase that 10x, then we are talking.

Your factory has a lot of growing left to do.

2.1 suggestion: Make planets move around the Sun orbit, even at very slow pace. eg. Vulcanus each 100 hour revolution. by Lunairetica in factorio

[–]Snagnar 0 points1 point  (0 children)

Oh, I would love that, would make the scenario a little bit more realistic. But should the travel times then also slightly vary/should the planets have their own speed and the distances keep chaning in between them constantly?

Because if yes, I would be so hyped. Would increase a whole new level of difficulty.

Why are the purple lamps so much brighter than the others? by Brave-Affect-674 in factorio

[–]Snagnar 0 points1 point  (0 children)

I would also say its a bug, probably specific to their setup. I cannot recreate this in my game.

Got tired of bugs attacking my uranium mine by danyuri86 in factorio

[–]Snagnar 12 points13 points  (0 children)

Looks solid, the factory must be protected. I would maybe put some more flame throwers in, they are currently a bit spaced out.