Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1] 2 3

Author Topic: Dwarf Fortress AI  (Read 8466 times)

KojaK

  • Bay Watcher
  • KojaK cancels job: interrupted by Dwarf Fortress
    • View Profile
Dwarf Fortress AI
« on: May 12, 2011, 01:35:33 pm »

Not sure if this goes here, or in the modding section, but whatever.

I've been thinking about combining my two passions, programming and psychology. I have ultimately decided to attempt to create a basic artificial intelligence based on my own psychological models of consciousness, and Maslow's hierarchy of needs. Now, of course, a computer plugged into the wall has no real survival needs to speak of, except maybe going into sleep mode to save battery power, so I was stuck. I needed a way to teach a computer how to satisfy basic needs, and even a bit of planning and foresight. Then it hit me, Dwarf Fortress!

Managing a fortress is a large task. Those little guys can't be trusted to comb their own beards without setting something on fire or throwing a rock at someone. Jobs need to be scheduled, plants grown, areas dug and irrigated, mines tended to, etc.

So, why not write a program that handles the mind-numbing labor-intensive managerial aspects of DF?

I'm planning on having it manage food and booze to start with. It'll watch the stocks of food and alcohol, measure consumption, construct new barrels, and allocate the raw materials accordingly.

I can later move on to having it watch different industries like weaving, masonry, carpentry, etc. But for now, I'll just focus on farming.

So, aside from announcing my project here, I have a question:
How, exactly, does Dwarf Therapist connect to Dwarf Fortress, and how does it read and edit the memory? Would I need to talk to the guys who run that project, or is it listed somewhere by Toady?

(Edit: I'm an idiot. I just found DFHack. My question still stands though, does DFHack support what I would need it to support? Does Dwarf Therapist use DFHack?)

My plan is to have the AI watch a few variables, and when it needs to, send the keystrokes to DF to pause the game and do whatever it is it needs to do.

And when I get done with the project, would anyone out there like to use it?

Jack
« Last Edit: May 12, 2011, 01:47:24 pm by KojaK »
Logged
Quote from: Airpi
A normal ballista does damage by piercing with overlarge arrows, a dwarven ballista does damage by crushing with entire trees.

They will run, naked, into the caverns and roll around in whatever nearby filth is available.  Watch for gory explosions.

Ultimuh

  • Bay Watcher
  • BOOM! Avatar gone! (for now)
    • View Profile
Re: Dwarf Fortress AI
« Reply #1 on: May 12, 2011, 01:43:09 pm »

Some here would not like it, but I think it's a neat idea.
It would take away some micromanagement off from the game, sadly also some of the fun stuff.
Logged

nymall

  • Bay Watcher
    • View Profile
Re: Dwarf Fortress AI
« Reply #2 on: May 12, 2011, 01:46:11 pm »

I'd most defiantly like to see this in action. It should be cool.
Logged

Keldane

  • Bay Watcher
    • View Profile
Re: Dwarf Fortress AI
« Reply #3 on: May 12, 2011, 01:46:44 pm »

Believe it or not, a project of this sort already exists. Titled Dwarf Foreman, it has been under development by a forumite named devek for some time. Sorry to burst your bubble.
Logged
WARNING:Side effects may include fatal badgerstorm and sudden appreciation for nobles.

Girlinhat

  • Bay Watcher
  • [PREFSTRING:large ears]
    • View Profile
Re: Dwarf Fortress AI
« Reply #4 on: May 12, 2011, 01:47:03 pm »

You'll probably have more luck looking into DFHack.  As I understand it, DFHack is the base of all third party gear, as they figure out the memory offsets and that enables everyone else to access the memory.  If you can use that to talk with DF, then it should be a relatively simple matter of getting the stocks data and the locations of certain buildings using the (R)ooms menu, namely farm plots.  After that, all of the logic gates and programming psychology would be program-based, it just takes a snapshot of DF, runs a few checks and ifs, maybe a few loops, and then outputs the commands.  Check Dwarf Foreman as well, it's supposed to be able to assign manager tasks with some amount of automation.

If you could expand upon this, and enable it to handle something like military training, that would be -amazing-.  Like, the player names a dwarf as "Spear" or something, and it then places the new recruit into a squad with other new recruits, where they spar in safety until reaching X level, and are then moved to a fighting squad where they equip metal weapons and armor and are put on the front lines, renaming and reassigning squads as needed.  If automated -just- right, you could even have it grab migrants, giving you a completely automated military that would work wonderfully for the millennium fortress style!

Either way, this sounds fantastic.  I would love to help with the logic-based code, though I really suck at the memory-based stuff.  I can do plenty of surface level programming, but once you start accessing memory and stuff, I'm lost.

NINJA: Those who do not like it will not use it.  Same as tilesets and even "basic" tools like Therapist.  If they refuse to use it they will not use it.

KojaK

  • Bay Watcher
  • KojaK cancels job: interrupted by Dwarf Fortress
    • View Profile
Re: Dwarf Fortress AI
« Reply #5 on: May 12, 2011, 01:57:06 pm »

Believe it or not, a project of this sort already exists. Titled Dwarf Foreman, it has been under development by a forumite named devek for some time. Sorry to burst your bubble.

No worries mate, my bubble isn't burst. Even if this project exists already, I think I'd like to work on my own version, just for the fun of it. I did see Dwarf Foreman already. I don't have experience with the program, so I can't say what the similarities and differences will be.

And yes, like I edited in my first post, DFHack is something I'm definitely looking into. Military training shouldn't be -that- hard, if Dwarf Therapist can find new migrants based on waves, my program should be able to as well. Then it's just a matter of sending it the keystroke to pause, and managing the military screen via keystrokes or memory editing.

As to the removal of fun because of micromanagement, I might not even use some of the features myself. I do enjoy digging out mining shafts and irrigation, military training and all that. What I do *NOT* enjoy is constantly having to track food and booze supplies, scheduling new jobs and running out of barrels. That is annoying. But, because this is going to be the foundation for my larger project, I will code some aspects of fortress management that I might end up turning off for myself eventually.
Logged
Quote from: Airpi
A normal ballista does damage by piercing with overlarge arrows, a dwarven ballista does damage by crushing with entire trees.

They will run, naked, into the caverns and roll around in whatever nearby filth is available.  Watch for gory explosions.

billybobfred

  • Bay Watcher
  • [PRONOUN: she:her:hers:herself]
    • View Profile
Re: Dwarf Fortress AI
« Reply #6 on: May 12, 2011, 02:07:25 pm »

if Dwarf Therapist can find new migrants based on waves, my program should be able to as well.
It guesses based on their unit number. Normally migrants are created out of thin air when they "arrive". The occasional migrant who actually existed before moving in will throw it off.

... I'm looking for a link to where I got that info, but I can't remember at all. =/
Logged
urist mcgeorg, who lives in boatmurdered and makes over 10,000 bad decisions each day,

Girlinhat

  • Bay Watcher
  • [PREFSTRING:large ears]
    • View Profile
Re: Dwarf Fortress AI
« Reply #7 on: May 12, 2011, 02:08:51 pm »

I think I'd like to try and attempt a full AI fort.  I'm a sucker for anything automated, so I'd love to tweak it far enough to dig out its own tunnels, place furniture, and accommodate a growing fort.  If you let me into the program once you figure out the memory access, I'd probably end up making a program that runs from embark to fall, automated and growing.  I would love to see what sort of forts the program would dig out all on its own.

Also, use a Therapist-like tool, which gathers the dwarf's skill set.  If it's one that has dodging, fighting, shield use, make it a soldier.  If it's got none of these skills, make it a hauler with potential for soldiering.

Keldane

  • Bay Watcher
    • View Profile
Re: Dwarf Fortress AI
« Reply #8 on: May 12, 2011, 02:45:03 pm »

No worries mate, my bubble isn't burst. Even if this project exists already, I think I'd like to work on my own version, just for the fun of it. I did see Dwarf Foreman already. I don't have experience with the program, so I can't say what the similarities and differences will be.

Ah, a project for the project's sake, then? I'm glad I wasn't being a buzzkill.
Logged
WARNING:Side effects may include fatal badgerstorm and sudden appreciation for nobles.

o_O[WTFace]

  • Bay Watcher
    • View Profile
Re: Dwarf Fortress AI
« Reply #9 on: May 12, 2011, 03:58:18 pm »

Someone did actually make a fully automated fortress with just macros.  It even had a way to automatically assign jobs to children once they grow up, so in theory it could last for centuries.     
Logged
...likes Dwarf Fortresses for their terrifying features...

KojaK

  • Bay Watcher
  • KojaK cancels job: interrupted by Dwarf Fortress
    • View Profile
Re: Dwarf Fortress AI
« Reply #10 on: May 12, 2011, 03:59:25 pm »

if Dwarf Therapist can find new migrants based on waves, my program should be able to as well.
It guesses based on their unit number. Normally migrants are created out of thin air when they "arrive". The occasional migrant who actually existed before moving in will throw it off.

... I'm looking for a link to where I got that info, but I can't remember at all. =/

The Dwarf Therapist readme bugs section. I read the same thing. It's accurate enough for me though. (I'm eventually going to work on a more involved process, but it will do for the moment)

I think I'd like to try and attempt a full AI fort.  I'm a sucker for anything automated, so I'd love to tweak it far enough to dig out its own tunnels, place furniture, and accommodate a growing fort.  If you let me into the program once you figure out the memory access, I'd probably end up making a program that runs from embark to fall, automated and growing.  I would love to see what sort of forts the program would dig out all on its own.

Also, use a Therapist-like tool, which gathers the dwarf's skill set.  If it's one that has dodging, fighting, shield use, make it a soldier.  If it's got none of these skills, make it a hauler with potential for soldiering.

I am hesitant to say this, as it's a bit of a stretch, but at the end of this project, I would like my program to run an entire fort from start to eternity. Obviously this AI isn't going to build any megaprojects, but it will attempt to make the fort as profitable as possible.

Now I see how just using a program to make a profitable fortress that runs itself isn't very fun, but I also see how certain parts of the program can be used to automate parts of the game that are a bit boring or mind-numbing.

I also see it like this, if I can make a program that can run a profitable fortress with invaders and have a success rate anywhere close to equal to that of a human, I'll have passed an early turing test.
Logged
Quote from: Airpi
A normal ballista does damage by piercing with overlarge arrows, a dwarven ballista does damage by crushing with entire trees.

They will run, naked, into the caverns and roll around in whatever nearby filth is available.  Watch for gory explosions.

Girlinhat

  • Bay Watcher
  • [PREFSTRING:large ears]
    • View Profile
Re: Dwarf Fortress AI
« Reply #11 on: May 12, 2011, 04:34:05 pm »

I want it to build megaprojects...  and if allowed, I'd probably figure out a good way to make it build large, sprawling structures.  Catacombs would be the most fun, as death is the only assured part of a dwarf's life, and thus a stable population of 50 will always use 50 bedrooms, but may consume 2 extra tombs every year, making the burial into the most area-extensive portion.

Sadrice

  • Bay Watcher
  • Yertle et al
    • View Profile
Re: Dwarf Fortress AI
« Reply #12 on: May 12, 2011, 04:40:16 pm »

Seems like migrants would be easy.  Refresh your list occasionally, and anyone who's new and isn't an infant or a trader is a migrant.  Do migrants ever bring infants?  I know they bring children...  The occasional slipup on a baby is probably not a big deal, it's not like you can draft them anyways.
Logged

Girlinhat

  • Bay Watcher
  • [PREFSTRING:large ears]
    • View Profile
Re: Dwarf Fortress AI
« Reply #13 on: May 12, 2011, 04:45:09 pm »

Therapist can tell the difference between children and adults, I assume this could be applied to the AI.  Furthermore, it could not care.  It could just keep a list/array of dwarves, and then when it finds a new one it adds them to the list with some notes.  Thus, it ignores children and only focuses on adults.  Or it could be made to read relationships (if this is possible) to place mothers in training or archery squads and handle married couples and children differently.

KojaK

  • Bay Watcher
  • KojaK cancels job: interrupted by Dwarf Fortress
    • View Profile
Re: Dwarf Fortress AI
« Reply #14 on: May 12, 2011, 04:49:43 pm »

Seems like migrants would be easy.  Refresh your list occasionally, and anyone who's new and isn't an infant or a trader is a migrant.  Do migrants ever bring infants?  I know they bring children...  The occasional slipup on a baby is probably not a big deal, it's not like you can draft them anyways.

Actually yeah, that's what I was thinking. Though I have to watch out for mistaking invaders, traders, pets, and wild animals as new migrants. Oh, and ghosts.

Edit: and I can just ignore children until they grow up too. They'll be discovered with the new group of migrants. Or I can just implement what I do, which is check every so often for new dwarfs... which isn't really that effective of a method, so I see this as an area that can be improved.

I want it to build megaprojects...  and if allowed, I'd probably figure out a good way to make it build large, sprawling structures.  Catacombs would be the most fun, as death is the only assured part of a dwarf's life, and thus a stable population of 50 will always use 50 bedrooms, but may consume 2 extra tombs every year, making the burial into the most area-extensive portion.

In theory, building a megaproject should be easy for a program. Have it automate construction based on a blueprint, and oversee the production and gathering of raw materials. So if I handed the AI a blueprint of a spaceship or megacastle, it would be no trouble at all. The question is, left to it's own devices, should the AI build a megaproject? People generally start megaprojects after they get bored with the fortress, or before they begin one, making it a goal for the entire map. The AI won't start out with a goal, and it will never experience boredom (unless I program boredom in... which realistically is a sign that one of the higher self-actualization needs of Maslow's hierarchy of needs isn't being met).

But on it's own, with no guidance, the program would have to choose a megaproject, design it, and begin construction. Which is very, very difficult. But if you find a way, please, by all means, help me out.

Therapist can tell the difference between children and adults, I assume this could be applied to the AI.  Furthermore, it could not care.  It could just keep a list/array of dwarves, and then when it finds a new one it adds them to the list with some notes.  Thus, it ignores children and only focuses on adults.  Or it could be made to read relationships (if this is possible) to place mothers in training or archery squads and handle married couples and children differently.

Now that is interesting. Perhaps in the future when I begin writing up code for military and advanced labor choosing, relationships and preferences could do a lot. I certainly don't want to go in and read all that, but my AI wouldn't mind.
« Last Edit: May 12, 2011, 04:51:43 pm by KojaK »
Logged
Quote from: Airpi
A normal ballista does damage by piercing with overlarge arrows, a dwarven ballista does damage by crushing with entire trees.

They will run, naked, into the caverns and roll around in whatever nearby filth is available.  Watch for gory explosions.
Pages: [1] 2 3