Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Scripting for Dwarf Fortress  (Read 2418 times)

smarmius

  • Bay Watcher
    • View Profile
Scripting for Dwarf Fortress
« on: August 23, 2010, 08:52:44 pm »

Hey,

So long time lurker coming off a Dwarf Fortress break. I'm interested in writing some automated scripts to do who knows what with Dwarf Fortress, but I'm not sure the best way to go about it. I'm a fairly competent programmer but I have no experience with scripting or writing a program that launches and provides input to another. If anyone has any tips for launching an instance of Dwarf Fortress and providing it input they'd be much appreciated. I'm most comfortable with C/C++ and Python, but if you know how to do it in another language that is awesome too!

Thanks,
    Smarmius
Logged
"Pie Time. It's like bullet time, but with pies."

nbonaparte

  • Bay Watcher
    • View Profile
Re: Scripting for Dwarf Fortress
« Reply #1 on: August 23, 2010, 08:55:54 pm »

Well, there are 2 ways to go about this. Either raw input (it'll work, but it won't be pretty), or memory hacking. DFHack is a library for memory hacking in DF.
Logged
A service to the forum: clowns=demons, cotton candy=adamantine, clown car=adamantine tube, circus=hell, circus tent=demonic fortress.

smarmius

  • Bay Watcher
    • View Profile
Re: Scripting for Dwarf Fortress
« Reply #2 on: August 23, 2010, 09:21:08 pm »

I think I'm looking more for raw input rather than dfhack, although that might come in handy later. Basically I became interested in machine learning and artificial neural networks over the summer and was thinking a fun way to explore these topics would be with an Automatic Dwarf Fortress Thingamajigger, even though I don't know if I'll be able to do it.
Logged
"Pie Time. It's like bullet time, but with pies."

nbonaparte

  • Bay Watcher
    • View Profile
Re: Scripting for Dwarf Fortress
« Reply #3 on: August 23, 2010, 09:26:56 pm »

That gave me an idea: DF playing genetic algorithm.
Logged
A service to the forum: clowns=demons, cotton candy=adamantine, clown car=adamantine tube, circus=hell, circus tent=demonic fortress.

smarmius

  • Bay Watcher
    • View Profile
Re: Scripting for Dwarf Fortress
« Reply #4 on: August 23, 2010, 09:30:25 pm »

That would be awesome. I'd love writing something that would try to create the 'perfect' fortress over several tries.
Logged
"Pie Time. It's like bullet time, but with pies."

nbonaparte

  • Bay Watcher
    • View Profile
Re: Scripting for Dwarf Fortress
« Reply #5 on: August 23, 2010, 09:34:09 pm »

that would take a long time, taking into account that you can't speed up a game. It's already stretching the processor as it is.
Logged
A service to the forum: clowns=demons, cotton candy=adamantine, clown car=adamantine tube, circus=hell, circus tent=demonic fortress.

smarmius

  • Bay Watcher
    • View Profile
Re: Scripting for Dwarf Fortress
« Reply #6 on: August 23, 2010, 09:38:22 pm »

Yeah, that could be a problem. If I ever make any progress on this I'll definitely post about it, but I'd probably just see what kind of fortress would evolve if I just ran the fortress for a year before restarting.
Logged
"Pie Time. It's like bullet time, but with pies."

smarmius

  • Bay Watcher
    • View Profile
Re: Scripting for Dwarf Fortress
« Reply #7 on: August 23, 2010, 10:39:59 pm »

If anyone's interested I stumbled across a Python module called SendKeys that will simulate keypresses. It's current up to Python 2.6 but I believe only works for windows. For linux users, you might be able to use a module called pexpect but I don't know much about that.
Logged
"Pie Time. It's like bullet time, but with pies."

Tilla

  • Bay Watcher
  • Slam with the best or jam with the rest
    • View Profile
Re: Scripting for Dwarf Fortress
« Reply #8 on: August 24, 2010, 03:51:24 am »

that would take a long time, taking into account that you can't speed up a game. It's already stretching the processor as it is.

This is why you need multiple computers running for this project :P
Logged

3

  • Bay Watcher
    • View Profile
Re: Scripting for Dwarf Fortress
« Reply #9 on: August 24, 2010, 03:53:44 am »

Just so you know, there's already a powerful program for this sort of thing (which also allows the user to modify other stuff besides).
Logged

smarmius

  • Bay Watcher
    • View Profile
Re: Scripting for Dwarf Fortress
« Reply #10 on: August 24, 2010, 10:04:51 am »

That looks interesting, but I don't think it does quite what I want to do. It looks like at this stage in the development Dwarf Script is just DF Therapist via command prompt but later will support some more advanced scripting (job batches, automatic job switching, etc.). I'm just going by what is said completed in the To-Do list and what is listed in the minor features though.
Logged
"Pie Time. It's like bullet time, but with pies."