Jump to content


Photo

Messing with the Enemy (A.I.)


  • Please log in to reply
10 replies to this topic

#1 ghero4

ghero4

    GMC Member

  • GMC Member
  • 43 posts

Posted 18 June 2010 - 01:40 AM

To introduce myself I'm ghero4 and have been toying with game maker long enough to grasp a good decent knowledge of GML. Although I don't post games I love doing engines and demos to play with ideas, which brings me to my question. I'll try to put it simple and give as little headache as possible.

I went through the Finite State Machines post and found tidbits about making human A.I. I'm going to add these in with this complex case. I was toying with a game idea that would push GML's A.I. limits called Make The Kill. In this game you get points based on how you kill the enemies (no s**t right?). By kill I don't mean HEADSHOT +10, I mean psychological warfare, meaning f**king with their minds until they kill themselves or are easier to kill. This would mean making an A.I. with relations (variable), personality (variable), emotions (variable), knowledge/memories (queues?), and actions (states) performed and effected by these stats.

Here's a scenario for the AI (Gunner):

Gunner is a hardened soldier (personality) patrolling his route. He notices that his friend Dan, whose route goes through, his hasn't shown up (knowledge/memory). On his route he finds a bag. Upon opening it he finds the head of Dan. He becomes angered (emotion) at the sight and reports it to his superior (knowledge/memory). He now knows there is an enemy on the base (knowledge/memory) and becomes more driven (emotion) while searching (state) and will be more aggressive (emotion) when facing said enemy to avenge his friend. All this causes him to be more anxious (stress value goes up).

When looking at the personality variable (persona) for different personalities you can put something like:
persona = 1
//1 = hardened
//2 = generous
//3 = cowardice
//etc

You can do the same for emotion (emote), and actions (state):
emote = 2
//1 = neutral
//2 = angered
//3 = saddened
//4 = happy
//etc

state = 1
//1 = search
//etc

The complications will start when relations (relate) are added. First Gunner will have to see if Dan is dead (Dan.state) and check his relationship with Dan (relate) and perform an action (state) based on his personality (persona) and emotions (emote). To top it off, these events will be added to his memory/knowledge and. Although complicated, this is basic since I'm not accounting for how other soldiers can change his emotions or how the enemy can keep knowledge from him (never letting him find the head) and how his stress level can build and change his emotions and cause him to do things he normally wouldn't.

The thing I want to ask is, how you would put this in the most basic, workable form in GML? And if this was managed how can the other variables be slowly added?
  • 0

#2 rwilson

rwilson

    GMC Member

  • New Member
  • 122 posts

Posted 18 June 2010 - 04:33 AM

I like the idea, but I feel like this is a "Here's my idea, now give me the code." discussion.
The first step in mpo is to create the scripts for movement and actions based on the states. Those are the building blocks
that you need to have established before you create the 'brain'.
For example:
Search; have a hard coded script that accounts for certain atributes (persona + emote)
-coward searches slower (cautiously)
-hardened does not search thoroughly if angered
I also suggest a combat and get reinforcements("report to superiors") script following in this format.
Then all the actions take emote + persona into account.
I suggest a decision tree for the state changes that also takes persona + emote into account.
You can go far with this and make a good engine, but make it yours.
Does that help? and what are other good options?
  • 0

#3 ghero4

ghero4

    GMC Member

  • GMC Member
  • 43 posts

Posted 18 June 2010 - 07:58 PM

Yes it does, but this really isn't a "give me the code" post, I'm sorry If I made it seem that way. I just like hearing other people's perspectives on how something like this could work in Game Maker. This is just an idea, and a tough one at that. I don't think I'll ever be able to put it into an actual engine. Just looking for others opinions, input, and insights. And thank you for yours, rwilson!
  • 0

#4 Shadow Link

Shadow Link

    GMC Member

  • GMC Member
  • 1578 posts

Posted 19 June 2010 - 06:48 AM

If I were to devise a system like this, I'd make a hybrid system of state machines and just code. While states can be desirable for simple things, the more complex you get, the more complications that will come up. This is usually the case for AIs that need to adjust to conditions or be more dynamic. I'll illustrate a basic concept for each of your categories:

Relations
If you mean relations to other characters, you could also link an emotion or stat to that individual quite easily as long as you stick to lists.
(Sort of) Pseudo-code:
people = ["Me", "Dan", "Boss", "New Guy", "Enemy"];
rank = [3, 3, 5, 1, 4];
friend = [100, 100, 100, 100, 0]; //Percentage-based

You can see that now if we look up Dan (index 1), just look for index 1 in the rank list to see how you compare. This could affect feelings such as respect, reputation, or trust. If you look at index 1 in the friend list, you'll be able to compare how much of a friend they are to you ranging from 0% (You will murder on sight) to 100% (You will die for them). These values are more likely to fluctuate depending on the AI's mood towards them, or even have a separate mood list.

Personality
There's two ways you can go about this one - the first being that you can use states like you have, and the second as a slider. The slider is simply two states in one such as Courage 1 to 10 or even 1 to 100. This lets you control everything in between from Courage 0 (Coward) to Courage 10 (or 100, Hero). It also eliminates having two separate variables for opposites. You can incorporate the 7 Deadly Sins as a start.

Emotions
Same as Personality. What I like about the second method is that rather than memorizing numbers of states (or making custom constants), you will always know that Anger 0 = Calm, Anger 50 = Neutral, and Anger 100 = Bloodthirsty. And look, you just eliminated 2 extra variables! Here is a great list of emotions with a neat chart for inspiration. There's also some long lists on Google if you search for "list of emotions". Pick a few that you think are suitable and play with them.

Knowledge/memories
Starting to get harder, memories are largely dependent on what you want your AI to remember - and there's a world of things to remember. Passwords, schedule (route), locations of people/objects, etc. I suggest you keep it simple as this is where your AI engine will turn hybrid. The easier things such as locations can be changed upon being told and stay that way until updated. That way, if someone were to be missing, your character could enter a confused state and solve the problem depending on a personality trait (coward would be scared or ask for help, hero would search everywhere).

Actions
As far as actions go, I would divide simple tasks from more specific ones. Each one would have its own script. Here's an idea:

Simple: Affected by personality, health conditions, and memory
- Go to location, goto(x, y) OR goto(thing) //Thing can be person, place, or object
- Bring object from A to B, fetch(object, Bx, By) //Object contains (Ax,Ay)
- Patrol, patrol(number) //Number of times to patrol

Specific: Affected by personality, health conditions, memory, emotions, and anything else
- Staying alert. Interrupts patrol by incorporating suspicious activity, getting called, etc.
- Seek. When presented with a problem, solve it by seeking information. Example: Not knowing a password to a door.

I couldn't really think of any super-complex, but I'm sure you'll come up with some. Next, because of the nature of state machines, we can give them a sort of to-do list such as:
patrol(5);
goto(bathroom);
goto(post);
survey(2 minutes);
patrol(2);

Obviously, the more tasks you script, the more they can do. Furthermore, other characters such as the Boss can add on to or change the list. He could have a script such as command(person, oldtask, newtask). This would first make him find the person, and then change "patrol(5);" to "fetch(ammo, me.x, me.y);" or even to nothing so they can take a break.

Forgive me if this seems a little bland at the moment. I had more planned, but I'm writing this pretty late so I can't really think straight. Play around with things here and there, and if there's anything that needs clarification I'll be happy to do just that. :)

EDIT: Messed up a tag

Edited by Shadow Link, 19 June 2010 - 11:09 PM.

  • 0

#5 CaptainLepidus

CaptainLepidus

    GMC Member

  • GMC Member
  • 850 posts
  • Version:GM:HTML5

Posted 25 August 2010 - 12:09 AM

This sounds interesting, so I had a go at a very, very simple version. There is an object called obj_dude that could have different states(I know, it's not really and FSM, but it's just demonstrating the concept) and a target. For the example, the state is st_search, and the target is obj_energy. obj_energy move randomly, and the goal for obj_dude is to find obj_energy. obj_dude has an array called x_place and y_place in which it records all the newest locations about all the objects, so that if it its target were ever that object it would know how to find the object. It also has a variable called view_size-in the example it is set to 200 but can be changed in-game by pressing enter.

In the step event it updates it's own x_place and y_place for every object and then it executes the states (currently only st_search).

Here's the link: http://www.stophomew...aiprototype.gmk

All this includes is Knowledge/Memory, but it might be slightly helpful. It doesn't look like much but there's more going on behind the scenes then it seems.
  • 0

#6 CaptainLepidus

CaptainLepidus

    GMC Member

  • GMC Member
  • 850 posts
  • Version:GM:HTML5

Posted 25 August 2010 - 12:10 AM

Edit: accidental double post.

Edited by CaptainLepidus, 25 August 2010 - 12:12 AM.

  • 0

#7 CaptainLepidus

CaptainLepidus

    GMC Member

  • GMC Member
  • 850 posts
  • Version:GM:HTML5

Posted 25 August 2010 - 12:11 AM

Edit: accidental triple post.

Edited by CaptainLepidus, 25 August 2010 - 12:12 AM.

  • 0

#8 mikibest2

mikibest2

    GMC Member

  • New Member
  • 125 posts

Posted 27 August 2010 - 08:48 PM

Well, I'm not really a good programer, but I read alot of articles in wikipedia (too many to post) about artificial life, and from what I understand, you won't be able to make something like that in GML...
But, for more simple stuff, I think I have an idea (although not a very allagent one...):
First of all, you need to set to each object a variable for each emotion, state, relation, etc.
Then, in every script, you have to take into account every single one of those variables, thus creating an end position fo each combonation
of states, emotions, etc.
I know it's not a practical solution, but that's the general idea...

Another thing that can be used in a human AI is age.
As time goes by, the objects in the game get older. If it is a shooter, your player will get more and more skillful, until at some point he will
start getting to old, and then he's skill will start decreasin. It will also affect relatioships: when your player is younger, he will get less respect from the people around him, other people will be his friends...
And when your player grows old, he will have a shorter memory span. It also gives you another option to control him: setting an age when he will die.

Sorry if I'm talking to generally :(
  • 0

#9 slayer 64

slayer 64

    GMC Member

  • GMC Member
  • 3300 posts
  • Version:GM8.1

Posted 28 August 2010 - 01:12 AM

And if this was managed how can the other variables be slowly added?


i would make a parent object. i would put all these varibales in the parents create event. when i add s new state, the children will automatically inherit the variables defaults from the parent, this would save me lots of copy/paste work and error messages.

try making everything the soldier thinks about a system that isn't dependent on other systems and only dependent on states.
  • 0

#10 ND4SPD

ND4SPD

    GMC Member

  • GMC Member
  • 2175 posts

Posted 28 August 2010 - 04:13 AM

Not sure how relevant this point is, but: Is it necessary to create such complex AIs? Realistically, you wouldn't be able to run armies of units with a whole lot of personality and a truck load of relationships to handle.

And even if you did, the player wouldn't notice it too much if one guard is a little edgy, whereas his mate is calm and is kicking a rock around. Noticing the difference between AIs would be especially subtle if it's easy to kill enemies, like in COD, when a couple of rounds will take down a bad guy.

I'd understand making different units having permanent 'personalities', however. Such as in Halo, where grunts are cowardly when they're by themselves, brutes are aggressive, jackals hang back a lot, and so on. In another (hypothetical) game, you may have conscripts that are cowardly, special forces soldiers that are emotionless, and mercenaries that are aggressive.

The only time I'd see the point of this is in a strongly story-driven sandbox-style game, and only a couple of your companions and possibly some main antagonists would have such complex personalities.
  • 0

#11 mikibest2

mikibest2

    GMC Member

  • New Member
  • 125 posts

Posted 28 August 2010 - 02:27 PM

But yo can put this to use in a strategy game. Let's say you are a king. in control of an army. If the other king will have a limited AI, after a few games you will always know how to respond. But if he will have a complex AI, which changes according to what you do, each time he will make decisions according to the current state of the game. You can also add this AI to the generals, and, for instance, when they see they are losing, they will offer to join your side.

Also, if you perfect a realistic, human like AI you can sell the codes to other people, or create a best-seller game and make millions :D
  • 1




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users