Author Topic: New approach to AI. Need suggestion and help.  (Read 11379 times)

pangaea

  • Newcomer
  • Posts: 6
  • Karma: +0/-0
    • View Profile
    • Email
New approach to AI. Need suggestion and help.
« on: March 22, 2014, 03:33:32 PM »
So I'm trying to make a game that is like DF and URR, however I first want to start with the AI instead of procedural generation of terrain, which would be easier.

I'm having a bit of a problem with mobs. In particular I'm spending the next two months on just one thing in AI, that is mob memory.

Now I've figured out what the basic information I need to store in the AI, that is map of the world that the AI currently knows, information about other mobs and if they are alive or dead, relationship information, information on items and stats of other mobs.

The problem is some information I want the mob to remember I have to take from other mobs, which I haven't figure out how to handle. Let say a mob has died, another mob comes into contact with that mob, he now needs to update his knowledge of the mob and in particular it is dead is the most important.

I've been told that I should use observer pattern I.e. if the mob who is dead has a method called isDead() that tells other mobs in it fov that it is dead. However, that would mean for every other piece of information I want to get I would have to do a similar method. So I would have to make say isStrong method to broadcast that the mob has 200 attack, or say if a mob loves another mob do I make an isLove method to broadcast this. So it becomes a mess.

So now I'm currently stuck as I have no good way of getting information from one mob to another. Observer pattern turned out to be a mess and I can't expand it.

I was wondering how could I solve this problem?

Zireael

  • Rogueliker
  • ***
  • Posts: 604
  • Karma: +0/-0
    • View Profile
Re: New approach to AI. Need suggestion and help.
« Reply #1 on: March 22, 2014, 05:27:59 PM »
I don't know what language you're using, but in Lua, I'd do something like:

important_mob_stuff = {}
for every mob in range/level do
important_mob_stuff[mob.name] = mob.love..mob.dead..mob.whatever

which you can then access by calling important_mob_stuff[target].love or important_mob_stuff[target].dead

Not 100% foolproof, but I'm using a similar method to store kills and monsters seen and it works.

Actually, you might have to do two tables, one for important_mob stuff, and then store love[mob.name] = mob.love in it?

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: New approach to AI. Need suggestion and help.
« Reply #2 on: March 22, 2014, 05:50:28 PM »
If you think the problem of actual mob objects as handles/pointers then it could be better to "remember" the ID of the mob and evaluate it always when mobs are visible to find the right target. Or when you need to travel to that mob (that is not visible) you could also remember the last location.

Simpler or at least faster way is keep a list of targetters for any object (the object knows which mobs are targetting it). When it's destroyed the targetters then get a notification about it and can remove the object from their target list.

mushroom patch

  • Rogueliker
  • ***
  • Posts: 554
  • Karma: +0/-0
    • View Profile
Re: New approach to AI. Need suggestion and help.
« Reply #3 on: March 22, 2014, 09:28:13 PM »
You don't need to write a separate method for every possible piece/type of information you may want to broadcast to listening objects.

Hope that helps.

ekolis

  • 7DRL Reviewer
  • Rogueliker
  • *
  • Posts: 186
  • Karma: +0/-0
  • get ye dennis
    • View Profile
    • Ed's home page
    • Email
Re: New approach to AI. Need suggestion and help.
« Reply #4 on: March 22, 2014, 10:22:35 PM »
A brute-force solution would be to make a complete copy of the mob being observed, then take out any parts the observer shouldn't know about given his sensory capabilities, and store it in a memory collection on the observer, with an ID corresponding to the observed mob's ID for cross-referencing should the same mob be observed twice. This may be rather inefficient, however; it really depends on the scope of your game whether this sort of thing will be practical.
The Ed draws near! What dost thou deaux?

>EAT SANDVICH

pangaea

  • Newcomer
  • Posts: 6
  • Karma: +0/-0
    • View Profile
    • Email
Re: New approach to AI. Need suggestion and help.
« Reply #5 on: March 22, 2014, 10:58:35 PM »
Okay so I've taken the advice and I've made an Observer class, that includes the id, position, sex, race, strength, health, intelligence and if it contains other actors I.e. items. So I just broadcast this to every mob that is in the fov of the mob like Zireal said.

I was thinking about what has been said in this thread. I'm nearly done doing this simple class to exchange simple information and making it work. Through, I suppose the next big problem is communication, like how would I transfer from one person that say x hates y. In real life this is done by conversation, so I think I need some sort of conversation class where I can exchange information with mobs. But, then this wouldn't really be about memory storage and I would on to personality of mobs, which I shouldn't be. I suppose I need a way to store relationship information between mobs and then a way to transfer it into another mob.

ekolis I think it better to have a class of information I want to be given out from the mob since then I could probably apply some logic like if mob x is more intelligent than mob y, then mob y cannot see the intelligence level of mob x. I see myself doing this a lot, especially for example if the mob is invisible you don't want to broadcast to a mob that can't see you I.e.  no ring of see invisible.

Zireal I'm doing what you said now. Through it C++ instead of lua, but that doesn't really matter.
« Last Edit: March 22, 2014, 11:02:10 PM by pangaea »

mushroom patch

  • Rogueliker
  • ***
  • Posts: 554
  • Karma: +0/-0
    • View Profile
Re: New approach to AI. Need suggestion and help.
« Reply #6 on: March 22, 2014, 11:03:32 PM »
Okay, let me expand on the above. The observer pattern simply entails storing a collection of "observing" objects in each object that are to be updated -- i.e. some sort of message is to be passed -- when certain conditions are met, e.g. conditions that might require some action or processing on the part of observing objects.

The message sent to the observing objects can be anything, e.g. a complex data structure representing whatever information you want to broadcast. It is not limited to whatever you can store in a bit vector or a single boolean value. If you want to get anywhere with the kind of system you're talking about, you need to either pare down your ambition to just a few types of information to pass, e.g. via a few fields in a C-style struct, or start thinking about more flexible data structures that can faithfully represent the information you want to pass around.

The first thing to realize is: You probably want the things you pass around this way to be instances of some message class, which should in turn be some composite type built from various other more specialized objects for representing the information you care about.

The second thing to realize is: As the object being observed is doing whatever it's doing, it should be building instances of this message class as it goes and broadcasting them to listeners where appropriate. It might help to have a helper class to build these things with, see e.g. the Factory and Builder patterns, so that your message class constructors don't get out of control.

If it is relevant how the data is being observed in the game world, this can be included as data in your message objects. Your mobs will then have to use the data enclosed in the messages responsibly with the method of transmission in mind -- or you could add another layer of processing between mobs taking environmental factors like line of sight etc. into account.

Again, hope that helps.

pangaea

  • Newcomer
  • Posts: 6
  • Karma: +0/-0
    • View Profile
    • Email
Re: New approach to AI. Need suggestion and help.
« Reply #7 on: March 22, 2014, 11:15:36 PM »
The message sent to the observing objects can be anything, e.g. a complex data structure representing whatever information you want to broadcast. It is not limited to whatever you can store in a bit vector or a single boolean value. If you want to get anywhere with the kind of system you're talking about, you need to either pare down your ambition to just a few types of information to pass, e.g. via a few fields in a C-style struct, or start thinking about more flexible data structures that can faithfully represent the information you want to pass around.

The first thing to realize is: You probably want the things you pass around this way to be instances of some message class, which should in turn be some composite type built from various other more specialized objects for representing the information you care about.

The second thing to realize is: As the object being observed is doing whatever it's doing, it should be building instances of this message class as it goes and broadcasting them to listeners where appropriate. It might help to have a helper class to build these things with, see e.g. the Factory and Builder patterns, so that your message class constructors don't get out of control.

If it is relevant how the data is being observed in the game world, this can be included as data in your message objects. Your mobs will then have to use the data enclosed in the messages responsibly with the method of transmission in mind -- or you could add another layer of processing between mobs taking environmental factors like line of sight etc. into account.

Again, hope that helps.

I sort of do understand what your saying about information being C-style. I'm making sure I only send ints, bools and enums.

Through the problem I have is sending the message is a bit confusing. I just check if the mob that is broadcasting say mob a can see say mob b, if mob a can see mob b I just copy the ints and bools into the memory of mob b or if there is already memory of mob a I update it. This seems a bit strange as how I'm currently doing it, mob a is changing mob b when in real life mob b is changing itself by observing mob a.  So it seems backwards.

I will look into Factory and Builder patterns, but I don't think I will use it.

mushroom patch

  • Rogueliker
  • ***
  • Posts: 554
  • Karma: +0/-0
    • View Profile
Re: New approach to AI. Need suggestion and help.
« Reply #8 on: March 22, 2014, 11:37:40 PM »
The message sent to the observing objects can be anything, e.g. a complex data structure representing whatever information you want to broadcast. It is not limited to whatever you can store in a bit vector or a single boolean value. If you want to get anywhere with the kind of system you're talking about, you need to either pare down your ambition to just a few types of information to pass, e.g. via a few fields in a C-style struct, or start thinking about more flexible data structures that can faithfully represent the information you want to pass around.

The first thing to realize is: You probably want the things you pass around this way to be instances of some message class, which should in turn be some composite type built from various other more specialized objects for representing the information you care about.

The second thing to realize is: As the object being observed is doing whatever it's doing, it should be building instances of this message class as it goes and broadcasting them to listeners where appropriate. It might help to have a helper class to build these things with, see e.g. the Factory and Builder patterns, so that your message class constructors don't get out of control.

If it is relevant how the data is being observed in the game world, this can be included as data in your message objects. Your mobs will then have to use the data enclosed in the messages responsibly with the method of transmission in mind -- or you could add another layer of processing between mobs taking environmental factors like line of sight etc. into account.

Again, hope that helps.

I sort of do understand what your saying about information being C-style. I'm making sure I only send ints, bools and enums.

Through the problem I have is sending the message is a bit confusing. I just check if the mob that is broadcasting say mob a can see say mob b, if mob a can see mob b I just copy the ints and bools into the memory of mob b or if there is already memory of mob a I update it. This seems a bit strange as how I'm currently doing it, mob a is changing mob b when in real life mob b is changing itself by observing mob a.  So it seems backwards.

I will look into Factory and Builder patterns, but I don't think I will use it.

Well alright. Good luck, bro.