Does headless factorio have an API for playing the game? - Looking to train an AI to do so

Place to get help with not working mods / modding interface.
Post Reply
beyarkay
Manual Inserter
Manual Inserter
Posts: 1
Joined: Thu Nov 23, 2023 6:57 pm
Contact:

Does headless factorio have an API for playing the game? - Looking to train an AI to do so

Post by beyarkay »

Hi there,

I'm a CS student interested in training an AI to play my favourite game so the factory can grow even when I'm not playing. There's a couple of things that would make this nice, and I'm wondering if factorio supports them:

- Speed up play: It would really speed up training if I could run factorio at 10x or 100x speed
- Headless communication: I believe this already exists via a headless server
- Player control: I believe this exists via LuaPlayer although I'd rather write the training script in a non-Lua language and have my script talk to factorio. Maybe I can write a mod that communicates to an external script which actually does the controlling?
- Some way of getting information about the state of the game: I'm guessing this is also trivially feasible via the Lua interface.

Apologies for the slightly rambly post, I'm confident I could get the machine learning parts to work but I'm not sure how easy it will be to get the ML parts to chat to factorio. Thanks for all your help!

Qon
Smart Inserter
Smart Inserter
Posts: 2120
Joined: Thu Mar 17, 2016 6:27 am
Contact:

Re: Does headless factorio have an API for playing the game? - Looking to train an AI to do so

Post by Qon »

beyarkay wrote:
Thu Nov 23, 2023 7:12 pm
- Speed up play: It would really speed up training if I could run factorio at 10x or 100x speed
- Headless communication: I believe this already exists via a headless server
- Player control: I believe this exists via LuaPlayer although I'd rather write the training script in a non-Lua language and have my script talk to factorio. Maybe I can write a mod that communicates to an external script which actually does the controlling?
- Some way of getting information about the state of the game: I'm guessing this is also trivially feasible via the Lua interface.
/c game.speed = 100
beyarkay wrote:
Thu Nov 23, 2023 7:12 pm
- Headless communication: I believe this already exists via a headless server
Yes.
beyarkay wrote:
Thu Nov 23, 2023 7:12 pm
- Player control: I believe this exists via LuaPlayer although I'd rather write the training script in a non-Lua language and have my script talk to factorio. Maybe I can write a mod that communicates to an external script which actually does the controlling?
- Some way of getting information about the state of the game: I'm guessing this is also trivially feasible via the Lua interface.
You can write you AI in any language and have a binding layer in Lua, injecting the commands via RCON and getting info from the world back with RCON.
mod communicating with the outside world

vjbone
Fast Inserter
Fast Inserter
Posts: 143
Joined: Sun Feb 14, 2016 10:02 am
Contact:

Re: Does headless factorio have an API for playing the game? - Looking to train an AI to do so

Post by vjbone »

Check this https://github.com/gotyoke/Factorio-AnyPct-TAS
Its not "ai" but could be great inspiration

leo_85
Burner Inserter
Burner Inserter
Posts: 6
Joined: Wed Nov 22, 2023 10:30 am
Contact:

Re: Does headless factorio have an API for playing the game? - Looking to train an AI to do so

Post by leo_85 »

beyarkay wrote:
Thu Nov 23, 2023 7:12 pm
Hi there,

I'm a CS student interested in training an AI to play my favourite game so the factory can grow even when I'm not playing. There's a couple of things that would make this nice, and I'm wondering if factorio supports them:

- Speed up play: It would really speed up training if I could run factorio at 10x or 100x speed
- Headless communication: I believe this already exists via a headless server
- Player control: I believe this exists via LuaPlayer although I'd rather write the training script in a non-Lua language and have my script talk to factorio. Maybe I can write a mod that communicates to an external script which actually does the controlling?
- Some way of getting information about the state of the game: I'm guessing this is also trivially feasible via the Lua interface.

Apologies for the slightly rambly post, I'm confident I could get the machine learning parts to work but I'm not sure how easy it will be to get the ML parts to chat to factorio. Thanks for all your help!
i'm working exactly on that: creating a restfull api for factorio via rcon, if you want we can team up: you work on your AI and I work on my API with a focus on what you need, you have what you want and I have a tester for my API. win/win (do you have discord?)

Post Reply

Return to “Modding help”