Jump to content


Photo

Imperfect A.i.


  • Please log in to reply
128 replies to this topic

#101 link3000

link3000

    Link3000

  • GMC Member
  • 1129 posts
  • Version:GM8

Posted 20 November 2009 - 02:13 AM

Yeah, I over viewed that a little a while ago, how using some random numbers at the beginning can make a pseudo-personality for the AI. But the question now is HOW?
  • 0

#102 gmx0

gmx0

    The Messenger

  • GMC Member
  • 1182 posts
  • Version:GM6

Posted 06 January 2010 - 04:39 PM

Programming an RTS AI, even a perfect one, is hard. Sometimes you cant help it but let the CPU be able to look under the Fog of War. An interesting idea though, give the AI human limitations. If the human can only see this view, then the AI has a view. If the human cannot see stealthed units, why should the AI?
  • 0

#103 griffi

griffi

    GMC Member

  • New Member
  • 243 posts

Posted 08 January 2010 - 07:35 PM

On the front of choice, an object or NPC could take into account several variables and sort choices into order of importance of each factor, and cross-reference them all into a choice.

For example, if an enemy NPC had 3 choices of target, based on what it could see, it would have to look at its' target, and attempt to judge the health, speed perpendicular to itself (cross-referenced with its' own accuracy), etc. and add them up according to how valuable each piece of data is, so speed would be fairly important, as it governs wether or not the target is physically hittable. After adding up the values, it would need to compare the data with that of the other two targets; whichever target had the highest score would be the most logical to fire at.
  • 0

#104 sylvan

sylvan

    GMC Member

  • New Member
  • 99 posts

Posted 10 January 2010 - 12:06 AM

I just put in a random number before each major "decision" that an AI needs to do.

For example before shooting you'd pick a random number, if the random number is less than the difficulty level, the AI will shoot. This also provides levels of difficulty. The AI would be programmed with a "perfect game", and the difficulty would determine how close they play to the perfect game.

A difficulty of 0.1 means the AI would almost never perform a perfect choice, but a difficulty of 0.9 would mean it almost always performs the perfect choice.

In a turn based game (say, chess) the difficulty level could be a choice between using perfect chess AI, or moving a random piece to a random location.

I used this kind of approach in my last competition game (which I never really finished, but it's certainly playable) http://www.yoyogames...es/66112-zeta-1
  • 0

#105 griffi

griffi

    GMC Member

  • New Member
  • 243 posts

Posted 10 January 2010 - 11:35 AM

I just put in a random number before each major "decision" that an AI needs to do.

For example before shooting you'd pick a random number, if the random number is less than the difficulty level, the AI will shoot. This also provides levels of difficulty. The AI would be programmed with a "perfect game", and the difficulty would determine how close they play to the perfect game.

A difficulty of 0.1 means the AI would almost never perform a perfect choice, but a difficulty of 0.9 would mean it almost always performs the perfect choice.

In a turn based game (say, chess) the difficulty level could be a choice between using perfect chess AI, or moving a random piece to a random location.

I used this kind of approach in my last competition game (which I never really finished, but it's certainly playable) http://www.yoyogames...es/66112-zeta-1


If what I believe you're trying to say is correct, then an AI might do illogical things, like targetting a footsoldier with an RPG rather than a tank - in real life, a person wanted to fight a group of people, they might think:

"Right; who should I hit first?"
"That guy looks pretty big; I think I should take him first."
"But wait, that other guy is pretty badly injured. That'll give me an advantage, and he looks pretty easy to take out."
"Damn, that other guy has a knife. I'll have to stay clear of him."
  • 0

#106 Yal

Yal

    Gun Princess

  • Global Moderators
  • 5837 posts
  • Version:GM8.1

Posted 28 January 2010 - 08:40 AM

In a turn based game (say, chess) the difficulty level could be a choice between using perfect chess AI, or moving a random piece to a random location.

I want to object to this statement. Using this might work, but it clearly takes the illusion away, the AI won't feel realistic if it does random things - there's some mistakes NOBODY would do, and allowing anything possible to be done by the computer would allow it to make them. You know, things that makes you stare at the screen (or, sometimes, your IRL opponent) and laugh at the memory years after. What a real chess program does is that it looks a certain number of turns forward, judges all the possible outcomes from all of them (or more precisely, some of them, I guess the ones that is more valuable), and selects the move that leads to the best. On lower levels it judges a smaller distance into time, perhaps just one turn forward, compared to perhaps ten turns forwards on the highest level.

Just gazing one turn forward, as many amateur players do, makes the computer more prone to miss plans with e.g. a tower offering, and thus more prone to trick into traps. The way of judging more and more situations ahead of time makes the computer (i mean AI, sorry) act more realistic, it seems like it's better at discovering plans before they are brought to action. Of course, pulling very unexpected moves, or moves that doesn't directly improve your "score" (which is also determined of where your units are standing) would disrupt the AI's plan, and it would try to find the best way out of the newly arisen situation instead of it's original plan. That's what happened during the famous chess matches against Deep Blue, I've heard.
  • 0

#107 tsa05

tsa05

    GMC Member

  • New Member
  • 713 posts
  • Version:GM:Studio

Posted 28 January 2010 - 05:31 PM

And so the discussion returns to Gaussian Random Numbers :(
Remember folks, it is possible to select numbers completely at random, and yet still avoid getting results that are illogical. Perhaps it's overkill to bring the subject up again, but since it seems we're still stuck on the point, maybe I'd better...

Consider the following 2 examples of number-generation:
1) You wish to determine how well the player scores in a competition. The player's score is determined by performance, on a scale of 1-10. But, what does the computer opponent score? Surely, not a random number from 1-10. That would be far too inconsistent, and it would be impossible to add levels of difficulty to your game, since any opponent could, at any time, score a 1...or score a 10...or anything in between.

2) You wish to create a shooting game in which the computer opponent attempts to hit you. You realize that it's too hard if the AI simply calculates the exact optimal firing angle and hits you every time, so you add randomness to it. But, you can't just aim in a random direction, or even in a specific direction +-90 degrees. That would look terrible, because your opponent would be randomly shooting all over the place, not even appearing to be trying to hit you.

The solution, in both cases, is to choose a random number that has a calculated average value. So, for example, you could choose a score from one to ten, with an average of 8. Now, every number chosen will be totally random...but on the whole of things, the average of all of the randomly chosen numbers will be 8. Furthermore, almost all numbers chosen will fall relatively near 8. The numbers are still chosen randomly, but it is extremely improbable that low numbers would occur. It's just like in an actual sporting competition--it's technically possible for an athlete to get a low score, but since the athletes are all very skilled, it's unlikely that the scores will be low.

And of course, with aiming a gun, same thing. You could choose a random number for the angle to shoot, that averages the exact angle to the target. That way, it's usually not exactly on-target, but is almost always pretty close to it.

I'd posted about this at one point, long, long ago :)
http://gmc.yoyogames...&...t&p=1457194
  • 0

#108 sylvan

sylvan

    GMC Member

  • New Member
  • 99 posts

Posted 28 January 2010 - 11:43 PM

I want to object to this statement. Using this might work, but it clearly takes the illusion away, the AI won't feel realistic if it does random things - there's some mistakes NOBODY would do, and allowing anything possible to be done by the computer would allow it to make them. You know, things that makes you stare at the screen (or, sometimes, your IRL opponent) and laugh at the memory years after. What a real chess program does is that it looks a certain number of turns forward, judges all the possible outcomes from all of them (or more precisely, some of them, I guess the ones that is more valuable), and selects the move that leads to the best. On lower levels it judges a smaller distance into time, perhaps just one turn forward, compared to perhaps ten turns forwards on the highest level.


The problem here, is that you could end up with perfectly flawed AI. Imagine, say Chess that only looks ahead 3 spaces. Once the player works this out, they can simply plan 4 turns ahead, and would be able to defeat the AI every time. Repeat games against the AI would be no challenge. You still want the AI to be able to pick strong moves on low difficulty so that the player learns from them.

Yes, you do have to take some care in not making obviously stupid moves, for example, say you were making a fighting game. You don't want the AI to block when nobody is attacking. However, when the player attacks the AI, that's when the random number would kick in. A higher difficulty would almost always block, a lower difficulty would block less. In the chess example, I guess you could, move a piece the recommended 1 look ahead or 10 moves ahead depending on the random number. But the point is, you'd be picking between optimal, and stupid AI. This means the AI, even on lower difficulty settings, can still prove a challenge.
  • 0

#109 tomster1996

tomster1996

    GMC Member

  • New Member
  • 312 posts

Posted 30 January 2010 - 07:46 AM

Yes, you do have to take some care in not making obviously stupid moves, for example, say you were making a fighting game. You don't want the AI to block when nobody is attacking. However, when the player attacks the AI, that's when the random number would kick in. A higher difficulty would almost always block, a lower difficulty would block less.


You could put a short delay on when the AI realises it needs to block. This would change the concerntration level of the AI.
  • 0

#110 Yal

Yal

    Gun Princess

  • Global Moderators
  • 5837 posts
  • Version:GM8.1

Posted 01 February 2010 - 08:12 AM

Oh, Gaussian random numbers... sorry, forgot about them. I actually read most of the discussion concerning them a few days ago, but I didn't remember them while I wrote my previous post.

The problem here, is that you could end up with perfectly flawed AI. Imagine, say Chess that only looks ahead 3 spaces. Once the player works this out, they can simply plan 4 turns ahead, and would be able to defeat the AI every time. Repeat games against the AI would be no challenge. You still want the AI to be able to pick strong moves on low difficulty so that the player learns from them.

I don't think there's a single human being that could evaluate all possible (or rather, all plausible) moves in chess for 4 turns forward, it's simply so complex. You might devise a plan for the next four turns, which efficently makes the computer one step behind, but you've still got the potential to oversee things, like move a bishop to get a good position to launch a two-piece assault, then the computer notices that your queen is suddenly possible to knock out after D4 is turned empty.

The AI will not oversee things like that, since it evaluates a lot of possible positions for these 3 turns.

OK, we're discussing flawed AI, and and AI that cannot overlook things might not be the best suited. But, how about, giving the [turn-based game] AI orders to overlook a certain number of plausible moves, chosen randomly, each turn, before selecting the move to take? The easier level it has, the more moves it overlooks, and it will only overlook moves when no move really sticks out (each possible position on the board is ranked depending on the available units of each player, their position, and a few things like that, and by not "sticking out", I mean that no position has a score that's a lot higher than the others, like for instance the position after destroying the opponent's queen would have). So, if there's a very good move, the AI won't miss it, but it might select things that's not really the best thing to do when there's a few possible moves that's near equivalent.

Of course, chess is relatively easy to make AIs for playing, since the outcome in chess matches are in most cases decided on what player has the most units left in his troop, and the "heavy ones" like the Rook is more useful than the "light ones" that can, for instance, go just one step forward (pawn). A game like go is far more complex, and I think most "video game specific" turn based board games (tactics RPG) would require more complex AI (of course, most TRPGs doesn't have 16+16=32 units to keep track on).

Hmm... as for picking between optimal and stupid AI, the hard thing is really to balance where too less "optimality" makes the AI too stupid. I think that kind of AI, having an ultimate, but strained AI, is so common because you don't really need to pour much effort into it. After all there's multiplayer modes in most games, and people tend to prefer that one (it will, compared to the story, never really run dry), and of course: game developpers usually have very sharp deadlines, for instance 25th december, making easy solutions the common choice.

-------------
Hope this furthered the discussion, I consider myself an "intermediate".

  • 0

#111 BinaryGuardian

BinaryGuardian

    GMC Member

  • New Member
  • 6 posts

Posted 24 February 2010 - 03:11 PM

I have also pondered about creating realistically flawed AI myself, and I will admit that one way I have accomplished it in the past was by using random() to introduce a chance for error. However, the more I contemplate this method the less pleased I become with it. So after thinking about it for a while I started to try and figure out why humans make mistakes, what is the process our brains take that inevitably leads to making mistakes. In the end, one simplistic reason for mistakes could be a lack of focus. If a football player is running backwards to catch a long throw, his focus is set on catching the ball and less on the line backer about to charge him from the side. So this has leaded me to try and conceive a way of incorporating a focus variable into the equation of AI decisions. Depending on which decision the focus is higher, the greater the chance the action will be performed successfully. I’m going to try and incorporate this into my current project and then I will come back to you and explain the setup.
  • 0

#112 CalixJumi

CalixJumi

    GMC Member

  • New Member
  • 181 posts

Posted 19 March 2010 - 01:13 AM

I like the way of thinking of FireWire, giving characteristics to the AI player. But as you have seen, each one has his own way of thinking, why not making diferent AI? not all people think in the same way.

For example i hade a 2D sidescroll shooter using the mouse.
You see all the monsters, so you move the mouse to their position and start clicking like hell. But then appears the surprise that you get damaged by a nearby enemy behind you, "thats more critical" you should think, then kill inmediatly that guy, i think that way in shooters so i tried to make my allies like that

My allies each one had an extra object "aim", so at their aim position they shoot. They "see" whats arround each one aim, so if theres an enemy near that position instantly aims there and hit, but when theres no enemy, aim just move vaguely in front of the direction they are heading... and when damaged than inmediatly re analyze positions of enemies to avoid touching them.



Also you can think in Fuzzy Logics, the formal form.
For example, you dont reach an enemy with your sword more than 32 pixels.
The enemy is constantly moving.
Where should you atack?

In a 1 variable (input) 2 range (output) Fuzzy Logic System, you could arrange for example
Variable: Position
Output: Not atack, atack
From 32 to 0 of distance you could think "yeah, surely atack"
From (example) 64 to inf you should think "why?"
But in the middle of 64 to 32 theres a chance of the enemy to get closer, or a way to hit him later.

So define:
Output:
1-Not atack    from   32 to Inf
2- Atack        from    0  to  64

So theres both, atack and not atack, between 32 and 64.
treat them as 0 to 1, and at 0.7 make this desition:
if random(1)>0.7 { atack }

And there you have randomness and failure probability, for example... atacking at 60 of distance, to away from the enemy... it has a chance of 1/16 to be performed.

Of course thats a simple example, you should also see the speed of the objective and use it.
For example, instead of looking at distance to objective, compare a variable with both compounds:
compare_var=point_distance(x,y,objective.x,objecti
ve.y)+objective.hspeed*atack_delay
(atack_delay should be aprox the time to perform the sword atack, so the enemy will be in the right place at the right moment)
  • 0

#113 4th_dimention

4th_dimention

    GMC Member

  • New Member
  • 32 posts

Posted 19 March 2010 - 01:54 AM

I had an interesting idea on how to make an AI. I am not sure if its practical but the big idea is to let evolution (yes as in biology) take care of it. The idea is once you have established a very basic ground AI give the AI a string say: "0000" and based on this string the AI changes its behavior in slight ways. The string can get longer or shorter. And 1s and 0s could be swapped (or any character I suppose more characters would be easier to program I think). So in a sense this string is like a short and sweet strand of DNA.

Part 2 some brave soul plays this AI. The AI ranks his performance. Then makes a small mutation and you play again. If he performs better, he marks the mutation as good, keeps it and makes a new one. If he performs not as good, he undoes it and does a different mutation. After many plays the AI is getting better and better.

If this were possible it could be used to make an AI get better at fighting the players style so the game would get harder on its own and force you to look for new styles. Or it might be use as a tool for a builder to find good strings for certain situations.

Assuming its all plausible it might make a pretty cool AI.
  • 0

#114 Yal

Yal

    Gun Princess

  • Global Moderators
  • 5837 posts
  • Version:GM8.1

Posted 19 March 2010 - 07:29 AM

The thing is, with the DNA and the "scrap bad mutations" algorithm described above, the AI will become better and better. To have an AI with flaws, what would one do? Not let the AI mutate above a certain level of skill? Perform some random mutations on each AI as gameplay begins (and hope these makes the AI a little bit less skillful)?
  • 0

#115 4th_dimention

4th_dimention

    GMC Member

  • New Member
  • 32 posts

Posted 19 March 2010 - 07:32 PM

Its not so much about making a flawed AI in this case. But making each AI seem human by making each a little different. Which is the point of the flawed AI. Plus it could be done like this instead:

When it rates it's performance if it goes over some number it still doesn't keep it, in order to keep the AI from getting to good too fast (which I don't think it could)
  • 0

#116 CalixJumi

CalixJumi

    GMC Member

  • New Member
  • 181 posts

Posted 21 March 2010 - 06:36 PM

Thats something like making evaluations.
You make an action with N number of variables. The result will be stored with those N variables, in a table for example.
Each new experience will be stored.
When a desicion is going to be done, the AI will use those information to evaluate.
The force of a previous experience on a new one will depend on the "distance" between both.

For example with just x and y
You go to 50,50 and you get hurt. This could be archived like  50-50-(-10) <-bad
So you go to 100,240 and you get healed.  so... 100-240-(+5) <-good

So in a new experience, in x,y you need to evaluate (this is a basic form)

sum of ( 1/Distance(x,y  to  array_x[i],array_y[i])*array_val[i]   )

So if you were going to 55,55(near hurt). In the evaluation you get: 1/(-70.71)+1/(982.34)=-0.014+.001=  -.013 (x1000 = 130neg -> bad idea)
(well, try with diferent ways so avoid pretty small numbers)

If you are going to 200,200(far) you got: 1/(-2121)+1/(538) = (-0.47+1.858)/1000 = 0.000811 (x1000= 0.811-> non significant)
going to 80,250(near heal) you got: 1/(-2022)+1/(22.36) = (-0.49+44.7)/1000 -> 44.21-> good idea

Also need to consider time value, i mean... for example that "heal" could be food, but maybe it was just an apple, the second time there will not be an apple. So also multiply for a factor to count this, like forgoting... depending on number of experiences, or devaluating depending on time of that experience)
Posted Image

Edited by CalixJumi, 25 March 2010 - 05:13 AM.

  • 0

#117 varuks

varuks

    GMC Member

  • New Member
  • 982 posts
  • Version:Unknown

Posted 23 March 2010 - 11:33 AM

A screen out of atleast one of you would be nice!
  • 0

#118 smash ball

smash ball

    Volcanic Light

  • GMC Member
  • 1126 posts
  • Version:GM7

Posted 13 July 2010 - 11:45 PM

If the AI in the above example was given a map, and that map had enemies showing on it, it would have to also input calculate how fast the enemies COULD be moving, WHERE they may be moving, and deciding upon where to go, the enemies of course, would have the maps too, and would try to calculate out the same exact stuff.
  • 0

#119 holomanga

holomanga

    GMC Member

  • GMC Member
  • 146 posts

Posted 23 July 2010 - 06:43 PM

I decided to make some 'groups' of AI. They decide on it's realism and intellegence. I will also though-test them against a certain scenario: The Food scenario.

The AI is presented with a good and a bad food. It will choose which food to eat based on it's AI type.

Type 0

These are 'conventional' AI. They can see everything, and make flawless calculations every time. Exactly what we don't want.

With the food scenario, this AI would eat the good food. It would always eat the good food.


Type I

These AI are exactly the same as type 0, just their behaviour is determined using random factors.

With the food scenario, this AI would eat the good or the bad food, based upon an abritary random variable.


Type II

These AI are learning AI. They seem curious about the world around them , and make decisions based on the fates of others and themselves

With the food scenario, this AI would see if it recognised the food, and make the decision based on the previous knowledge.


Type III

This AI is inottave (how do you spell it) and comes up with solutions to problems based on the fates of others and themselves.

With the food scenario, this AI would find a way to test the food before eating it.

Edited by holomanga, 23 July 2010 - 06:50 PM.

  • 0

#120 serverplatform

serverplatform

    GML on Fire

  • GMC Member
  • 72 posts

Posted 21 August 2010 - 06:28 AM

This is a good read.

but there could be another type.

Type 0

These are 'conventional' AI. They can see everything, and make flawless calculations every time. Exactly what we don't want.

With the food scenario, this AI would eat the good food. It would always eat the good food.


Type I

These AI are exactly the same as type 0, just their behaviour is determined using random factors.

With the food scenario, this AI would eat the good or the bad food, based upon an abritary random variable.

Type II
These AI are learning AI. They seem curious about the world around them , and make decisions based on the fates of others and themselves

With the food scenario, this AI would see if it recognised the food, and make the decision based on the previous knowledge.


Type III

This AI is inottave (how do you spell it) and comes up with solutions to problems based on the fates of others and themselves.

With the food scenario, this AI would find a way to test the food before eating it.


Type IV

This one is interestingly enough, a bit like a teenager. if all of the other AI are eating the bad food, then peer pressure comes into play, and our new AI would only eat bad food, regardless of its own fate. this one is simply a follower of the AI around it. once the other AI start to eat the good food, our type IV would continue to eat the bad food for a while, until it realises that everyone is eating good food. :wacko: i know it is confusing, but put simply, it is just a follower.

another is Type V

like type IV, except it would rate which AI seems smarter and follow that one. e.g. if there was a Type 0 and a Type I AI, the Type V AI would follow Type 0, because they were eating more good food on average.

maybe this could work.

Edited by serverplatform, 21 August 2010 - 06:29 AM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users