Lets Discuss some serious AI (Artificial Intelligence for enemies)...

3itg3itg Member, PRO Posts: 382
edited July 2012 in Working with GS (Mac)
After pushing through the final parts of my first game salad project, I have started on a much more ambitious project.
Warning: Wall-of-Text incoming.

I built my universe, player character spawn, save and load system using tables to track complex character attributes across play sessions.
I have begun work on my mission system, commodities and balancing the economy.

BUT I cannot seem to discern the best method to place some "organic feeling" AI in my universe.
I am not so much looking for instructions on how to do this, as I am looking for outsiders thoughts on how to create an organic feeling AI with the hope that it will help others in the future.
For my example, I will use some made-up town in some kinda RPG, but feel free to use any example you want in your replies.

Example:
I have a hub where missions can be accepted, goods can be purchased and helpers (Friendly AI) can be hired to help advance the game.
In each area of the game there is a Hub.
Also in each area of the game, I would like to have AI "going about there business", whatever it may be. The goal here is to make them seem like entities with the same potential objectives in life as the player.
I want these Hubs to act like points of interest to the AI, for limited times, before going back to their existence of trying to seem organic.
For the sake of this example lets say this HUB is a sign, with a wanted poster on it for a bounty the player could collect, the sign is next to store that sells items. Both of these items are a couple feet off of the path through town.

Now lets say we want 3 types of towns folk... the AI.

AI1: Lets say one is a merchant, and has never fought a day in his life. He ignores the sign. walks to the shop, enters, after 5/10 seconds he leaves and continues down the path. Carrying on his life as a merchant.

AI2: This one is a towns guard. He generally patrols the area if there is activity in the area, otherwise, he may continue down the path or return to his post.

AI3: A Fellow Warrior, sees the sign as he is walking down the path, rushes over, stands there for a second or two (like he is reading it), then pulls out his sword and runs off down the path to try to collect the bounty.

Now, I could make actors that do exactly what I just described, but what if I return to the village, successful in my quest and now would like to collect my bounty. It won't "feel" quite right if the same merchant strolls past, the guard does exactly what he always does and the warrior still gets excited and runs off waving his sword around.
better yet... I turned in my quest and now the sign is gone... Now their behavior would just seem weird.

My thoughts on this could be achieved:

Make/Program each actor:
I could make each actor, animate them, and call certain actions based on whether or not attributes are true/false. (i.e.: signpresent =true). Then only have actors who would interact with said object check that attribute. could even use magnitude to have them act different only when near the sign
This method seems relatively easy, but has a less-than-desirable outcome of preprogrammed behavior. Not very organic feeling.

Make Many Actors / Call Based on Conditions:
I could make 15 (5 of each type) actors, and use small deviations in their programming to make them act slightly different based on whats going on in the scene / storyline / game attributes and call the appropriate version based on those variables.
Still not quite what Im looking for, but probably could be useful in many circumstances.
This is definitely closer to an organic feel. But if a player entered and exited the scene, and the variables remained the same, their behavior wouldn't change. So it would seem exactly the same as a minute ago when you walked through town.

Make Many Actors / Call Randomly / Random Timing:
Again, make a bunch of actors, program them to act different and then when you call an actor into the scene, have it select a preprogrammed actor randomly. Sometimes it takes 1 minute for a warrior to walk down the path, and when he does... if the sign is there, he will read it and run off. Sometimes, after 30 seconds, the warrior appears.
It also could be the merchant that appears... a 20% chance that it could be the same merchant twice in a row. Maybe 5 seconds apart, and they do the same exact thing...
Random Calls seem close, Random Timing is also good... but as I just explained, this could have less-than-desirable outcomes as well.

Make Townsfolk / Load Personality from a Table:
This option would involve something like setting up an AI spawn point offscreen (or using random positioning, could probably be done using other methods), and having that spawn "roll the dice" a few times.
These dice rolls could give some integer values or select a value randomly from a list. Roll 1 could be how many actors are in the scene initially. Lets say it rolled 6. 6 spawns are placed randomly or at entrance points.
Now it rolls 6 times to decide what type of AI actor it should load for each. These are selected from a list or table randomly.
Hypothetically we got 2 guards, 3 merchants and a warrior.
Since guards have a uniform, guards don't roll for appearance. But the merchants and the warrior would. differences in appearance we will just say is their color for now. Red, blue, green columns in a table.
So we got a red warrior, a merchant of each color and 2 standard guards. They each roll a delay, an entrance point, and a "personality". these could also be values from a table, or just a range.
I think the best way to handle the 'personality" part would be make a table with 100 or so possible personality types and constrain which are available by actor (AI) type. (this maybe should be done in reverse, select random AI attributes, load appropriate actor)
Now how I think this would work in game salad is you make an actor, and this actors behaviors are ALL loaded from a table.
The frequency of actors and behaviors could be controlled by the number of entries in the table. If you want a 1% chance for a crazy warrior to spawn and start killing townsfolk, his attributes appear once in the table. More common AI qualities appear several times.
You could also use multiple tables and call from them at different times or for different reasons. If in one town, you always want at least one guard, but you still want other aspects like where he is, which way he is walking and whether or not he is scared of the crazy warrior to be determined randomly. One table is just variations of guards with different personalities.

This last option seems to be closest to I am looking for, and I have seen lots of questions on the forums about this type of thing.This seems to be, at least, versatile enough to accomplish an "organic feel" if implemented correctly.
But before I go nuts and try to build a Universe filled with AI... I figured I would ask others with more experience in GS what they think about this.
Are there massive performance issues I'm overlooking?
Is there an easier way I didn't think of?
Is this just a stupid, grandiose plan that no noob should ever attempt?

While I am rather new to GS (about a month in) I think I have a good handle on what can be done.
I also have a lot of experience with object oriented programming and scripting. I also have used some more complicated software for similar purposes.

Please elaborate on how you feel an "organic feeling" AI would be best achieved.
Hopefully it not only helps me decide a path, but it helps future GS users with this question figure out the many different ways you could control an AI's behavior and choose what is best for their game.










Best Answer

  • MotherHooseMotherHoose Posts: 2,456
    Accepted Answer
    @3itg
    IMO … you are making this more difficult than need be

    AI … the computer itself is AI
    the computer will implement all the rules/behaviors you add to the actors
    when you tell it to do so

    in your scenario … you must tell the computer:
    what the active scene is
    what currentState of progress is in that scene

    gameAttributes to store the values for those 'whats':
    scene# or name (index type works well … but will work with text type)
    scene1Flow … index type
    scene2Flow … index type
    etc. (flows for each scene)

    the scene#/name can be set with a controlActor at start of scene
    the scene#Flows should have +1 added just prior to the change of scene

    on your actors:
    Rule: when
    Attribute: scene# = 1 (or textName)
    -Rule: when (nested rules)
    -Attribute: scene1Flow = 0 (1st time in that scene)
    --do these behaviors
    -Otherwise: Rule: when
    --Attribute: scene1Flow = 1
    ---do these behaviors
    --Otherwise: Rule: when
    ---Attribute: scene1Flow = 2
    ----do these behaviors
    etc…

    timing can be set with actorAttribute:
    addAttribute: myTime (real type for greater variety)
    1st behavior… change myTime To: random(0.5,3)
    then add this condition in the above mainRule after the scene# = 1 condition
    Attribute: self.Time ≥ myTime
    --nested rules

    when you get things working right … create some tables for storing actorActions

    image MH

Comments

  • master200012master200012 Member Posts: 372
    Good heavens! What a lengthy post! How long did it take you to do that?

    Secondly, it is not off of...that's bad grammar. Just off is correct.

    Thirdly, in theory, all your examples are possible, but tables are the most efficient, I believe.
    Moreover, look at the app store. There is hardly a game out there like the one you are trying to achieve. (The Zenonia series is one of the few exceptions). In short, the kind of thing you are asking for is rare. Scarce. And very difficult.

    I have no idea how hard you are going to work on this, but this is gonna take some time. A truly long time.

    Thirdly, while it is necessary to have what you call "organic feeling," it can be simplified. How many people will notice a merchant ignoring the sign. Moreover, how many people will care? I don't mean offense in anyway, just saying.

    Good luck!
  • 3itg3itg Member, PRO Posts: 382
    edited July 2012
    #1: I warned it was long in the second sentence of my post.
    My example was just that... an example. I don't plan on having any wandering merchants in my game... I am only trying to explain that different AI would have different "purposes in life" or "interests".
    And how I would like AI constrained by their type.

    On your #2: Thanks for correcting my grammar... Im obviously extremely undereducated and neglected to proof read my post. :P

    #3: I know they are all possible. Im looking for the best path to implement my desired end goal and discuss a little more advanced concepts.

    and #4:


    Secondly, it is not off of...that's bad grammar. Just off is correct.

    Thirdly, in theory, all your...

    Thirdly, while it is necessary...

    You forgot to proof read as well... you said thirdly twice... :P
    Im not trying to cut you down though... just giving you a hard time.

    I genuinely am trying to discuss advanced mechanics within game salad.
    I am trying to open the floor to discuss, not only the examples I listed but other ways of achieving the same end goal.
    There are lots of talking "How to AI, blah,blah" and if just a couple of people who know how to, can explain why a method is good for the purpose we may be able to get some really useful info in one place.

    In my example above, I get into the table method the most, because, as you stated "tables are the most efficient, I believe.".
    I think tables would be most efficient as well, the calls should be smaller/faster than calling an actor with all its own art / attributes / properties, every time in every scene. Also, if done correctly, you should be able to reuse a lot of the same table data, so you can use similar behaviors for different characters / areas and really only change the art / animations.
    But I don't know that... i think that. Without much substance to back what I think except my experience with things that aren't gamesalad.
    So again, not so specific with the how to, but more emphasis on the whys and the best practices.
    Any constructive input is always welcomed and appreciated.
  • jn2002dkjn2002dk Member Posts: 102
    edited July 2012
    Interesting topic

    For townsfolk going about their business i guess i would use a combination of preset behaviours and weighted random but in your example i would keep the look of the townspeople the same each time

    As for returning to the scene, i guess you'll have to decide if you want them to appear as if they've been going about their business while the player was away or if simple freezing them once you leave the scene will suffice

    Obviously the latter option is the easiest by far since you can just save their coordinates and state in a table and load it once the player returns and have them go on from where they were when the player left them

    If you want them to appear to move about while the player is not in the scene then i'd probably try to make several preset behaviours for each villager and then select one at random each time the player enters the scene

    I'd imagine it would require a lot of work though so that's something to consider too. If they player is only at a hub for a relatively short duration is it really necessary to go through all that trouble? Only you can decide that:)

  • 3itg3itg Member, PRO Posts: 382
    edited July 2012
    Yea, I agree with weighted random with presets.
    Im thinking that could be done the same way as my crazy warrior. If most the time, I want him to act one way, make 8 entries with normal behavior. 2 entries different and selecting from the 10 would give an 80% chance to act normal, 20% to act crazy.
    extreme example but it works well.

    Freezing the actors when you leave the scene is what I have set up now. was easy and is not pretty. I actually am using pause in several layers, as a way to navigate through the HUBs menus and each submenu just pauses the game again. When you unpause everything is right where you left it. So I didn't even have to go as far as saving their states.

    I actually wish I was making a roleplaying game like Zenonia, because what I already have would be a great start.

    In my game, time will pass when specific actions take place and the game will autosave attributes.
    Right now it is done upon exiting the Hub, The date advances by one, the game gets saved to its respective save spot, and then everyone in town is where you left them one day ago...

    without the pesky time element I would be in good shape :P

    Has anyone encountered an overhead limit with the number of tables?
    (I know tshirtbooth has a demo where he has something like 40k in one table, so this isn't the size of one table. I mean like 7 tables with thousands of behavior equations per table all in one project, because that is close to what my plan is now.)
    Anyone have thoughts on how a priority system using magnitude could fit into this?
    Currently, I am thinking just use "otherwise" to always give the AI something to do when the player is not close.
    And that "otherwise" could be the behaviors i want the player to see, loaded from a table randomly to seem more organic.

    As for the amount of work. I am currently working with Gamesalad as a full-time job, between 7 and 10 hours a day and loving it. I understand what I am talking about is a lot of work, and that is the exact reason I want to discuss strategies with other GS users before I attempt to do all the work.
    I am a one man team and self employed, and barking up the wrong tree for who knows how long could end up in a tremendous amount of work that needs to be redone and that can be pretty discouraging sometimes. Rather iron out a plan and get feedback before I shoot myself in the foot by being overzealous.



  • jn2002dkjn2002dk Member Posts: 102
    Just a thought but how about having a certain preset set specific dates?

    day 1 - preset 1
    day 2 - preset 2
    day 3 - preset 3
    day 4 - preset 1
    day 5 - preset 3
    day 6 - preset 2
    etc

    It would seem random unless you're staying at the hub a long time or are going through several playthroughs
  • 3itg3itg Member, PRO Posts: 382
    To expand on the preset by day, which is something I hadn't thought of, I could use the same preset cycles and randomize the activity they start with.
    Or in some way just add another level or two of "decision making" and that way some merchants would want to read the sign sometimes, but will ultimately carry on with their business.
    I think that method could use a much smaller data set as well. Leaving more space to make conditional and environmental based decisions as well as selecting random assemblies of presets.
  • jn2002dkjn2002dk Member Posts: 102
    Yes, i think to achieve the organic feel it's a matter of lots of preset behaviours with just enough randoms to make it seem unpredictable but not enough to make it seem just random which would look out of place
  • 3itg3itg Member, PRO Posts: 382

    ...the scene#/name can be set with a controlActor at start of scene
    the scene#Flows should have +1 added just prior to the change of scene

    on your actors:
    Rule: when
    Attribute: scene# = 1 (or textName)
    -Rule: when (nested rules)
    -Attribute: scene1Flow = 0 (1st time in that scene)
    --do these behaviors
    -Otherwise: Rule: when
    --Attribute: scene1Flow = 1
    ---do these behaviors
    --Otherwise: Rule: when
    ---Attribute: scene1Flow = 2
    ----do these behaviors
    etc…

    timing can be set with actorAttribute:
    addAttribute: myTime (real type for greater variety)
    1st behavior… change myTime To: random(0.5,3)
    then add this condition in the above mainRule after the scene# = 1 condition
    Attribute: self.Time ≥ myTime
    --nested rules...
    @MotherHoose: I havent used index yet, but that was a great post. Thanks for taking the time to read and add to the discussion. I think your method of utilizing the "passing time" instead of working around it will add some truly organic feeling. I am accepting yours as the answer.

    I think I may just take the day off from my current project and make some AI test projects using some of methods described in these posts. Who knows, maybe I'll even draw some pretty pictures and make a "townsfolk AI template". Hopefully that would be genuinely helpful that will help others with these types of questions, or who just learn better from examples.

    Please feel free to continue adding responses, as I think methods for these types of advanced functions/rule sets are sorely under-discussed.
  • 3itg3itg Member, PRO Posts: 382
    I just wanted to post an update on this now that I have gotten somewhere and I am pleased with my results.

    I have an actor which is the general focus of each area of the game. The actor is in the center of every scene. It had very few rules and was in every scene, so thats why i chose it as my AI Spawn control.

    First things I made for Advanced AI behavior control was a Rule and an attribute on this main actor. The attribute was called NumberOfAI.
    So I made a Change Attribute "self.NumberOfAI" to "random(0,8)" so now the number of AI that Appears is random. I used this same method to randomly spawn "Waypoints" as well. I made a Table that contains about 40 X&Y coordinates that both of these attributes look to for spawn coordinates.
    Each time an AI appears, it increments a Game Attribute for NumberOfAI +1.
    Then it takes the number of AI number present and assigns it to another self attribute. I called this attrib self.ID
    Then I made 16 coordinate game.attributes (an X & Y for each possible AI.) and called these AI1X, AI1Y, AI2X, AI2Y and so on.
    Then a rule on the AI actor that constrains its self.ID to an AI*X,AI*Y set of AI coordinates.
    I made a series of booleans that has it follow a set of behaviors for different states.

    I also have each AI using Rules that are pulling an AI "Personality" Type, an Actor type (which then in a sub rule loads stats like health and armor, speed, strength and image from another table, based on the Actor Type.), Each time it reaches a way point, it selects a new waypoint randomly. There is also more... Mini-map blips for all of em, a targeting system that loads each actors health/armor into the HUD. Over 60 attributes are being assigned when the actor spawns.
    But I'm not sure if what I have so far is a coherent explanation so I'll stop now.


    So what I have now is scene that populates its self very differently every time, with the same actors used over and over again. They all behave very differently, but if you hit they will fight back... when you are dead, they go back to what they were doing.
    The project has sounds for every actor, each weapon (when they are used), music playing and High Res Images.
    Tested on an iPad2 and an iPad3 and runs extremely smoothly.

    Im off to make it even more complicated than it already is... But I wanted to update this thread with what I've found.

    Ive only been using game salad for 1 month as of today. It is a fantastic tool and I can't wait to see what I can with it over the next year.
    Thanks to @jn2002dk, @MotherHoose for your help in this thread.
  • HymloeHymloe Member Posts: 1,653
    Hi there @3itg,

    It's interesting reading along to see what you're up to.

    Sounds like you've done some interesting stuff.

    I'm just starting on a prototype of an RPG sort of game myself, and I've always wanted to make a little RPG in the style of Phantasie (and old game I used to play around 1985!)...

    Phantasie
    http://en.wikipedia.org/wiki/Phantasie

    I'm using a TABLE for the map, with words in each cell, like...
    grass
    forest
    mountain

    ...and then in my scene, I've got a grid of 8x8 tiles, which take their images from the table.

    I can then move my actor around the map, and scroll the map, and update which part of the table to show, and the images all update.

    Booya. I'm feeling good about that, so far, after one day.


    I'm thinking of using multiple tables, which keep track of different things. Not sure when I'll run into something that just stuffs me up. We'll see.

    I'd be interested to see your project, or even just a little demo video of it running, if you can be bothered. :) All the best.

    Or just an update of where you're at would be interesting. Your last post was July 26th, that was a long time ago. I hope you stuck with it, and got further along!

    - Murray


  • 3itg3itg Member, PRO Posts: 382
    Thanks for your interest.
    I post updates about once a month here:
    http://forums.gamesalad.com/discussion/47160/lets-take-over-the-universe-ltotu-development-thread

    A recent video of gameplay footage is here:


    I am also currently running a short Beta on testflight to get feedback on gameplay elements and general thoughts on the playability or "fun-factor".
    If ya got an iPad, you can sign up here:
    http://tflig.ht/PiMCzh

    When I complete my project, I plan to do some sort of AI template like I discussed above.
  • HymloeHymloe Member Posts: 1,653
    Cheers, I've signed up on Test Flight, keen to check it out.

    You've got plenty going on there!

    - Murray

  • SlickZeroSlickZero Houston, TexasMember, Sous Chef Posts: 2,870
    This looks really good. I love space shooter/sims like this. Looks like you've put in quite a bit of work, too. I look forward to this release.
  • 3itg3itg Member, PRO Posts: 382
    My current efforts are mostly focused on getting this to run smoothly on an iPad2.
    I have rocked out some pretty decent play sessions of an hour or more without crashing on my iPad3 now, although combat can still be a little volatile and cause crashes at times.
    Biggest complaint from testers is load times.
    Im also reworking the mission system and making the escorts characters instead of just "empty" ships that follow you around.
    I recently started working on some art for the mission prompts, but changed my mind about the style part way through (was way too serious in tone). I would like to change the mission prompts into comic book style story telling...
    /sigh
    Comic thing probably won't happen fast enough, so I'll probably be looking to add that in an update.

Sign In or Register to comment.