Home > Game Maker, GMC/YYG, Misc. > Intentionally Imperfect A.I.

Intentionally Imperfect A.I.

NOTE: Comments are locked. I no longer answer questions about the Game Maker tutorials on this blog; I suggest you take any questions to the Game Maker Community. For more info, view the FAQ page.

Skill Level: Advanced user (7)

I’ve decided to write about something a little more advanced than I usually do.  It is now posted in the GMC Experts forum, if you would rather reply there.

Anyways, many of us who create video games can write Artificial Intelligence to instruct the computer to play a game perfectly and unbeatably. This isn’t really a good thing, though, as it essentially ruins the game experience; after all, the player has to be able to win. But if one programs it so, the computer mind can be theoretically perfect; it won’t make spur of the moment mistakes, it won’t misjudge anything, and it won’t have accidents.

Imagine a computer playing pacman. It knows where the ghosts are and (if so programmed) it can likely calculate a perfect plan of escape every time. What if, however, we want the computer to emulate a real person? Most people probably won’t know for sure which direction to go to retain victory every time; they will occasionally make mistakes leading Pacman to his ghostly doom. The human mind doesn’t always work that quickly or that accurately.

Of course, we can’t just tell the computer to seek out a ghost so it will lose. For the best results, the game has to get the computer to look like it was actually trying, but just screwed up. Therefore, to combat the “perfect computer”, we must provide it some way to be realistically overpowered. “Intentional mistakes” must be introduced to the A.I.

A programmer can achieve this, albeit somewhat roughly, using a call to random(). One can also do something more general to the game’s design, such as removing certain abilities from the computer’s character so the player has the overall upper hand (i.e. giving the computer slower movement, letting the player shoot but not the computer, etc.). In addition, a third method might consist of “forgetting” to add parts to the A.I. – leave out checking for floor spikes in a platform enemy, for example.

Disappointingly, I haven’t seen very many examples of realistically flawed A.I. programming, if any at all.

(For those interested in more concepts of A.I., view the wikipedia article here.)

Here’s a basic example of what I’m talking about. Imagine I have a platform game enemy, who follows the player around and can jump over gaps. But I want this enemy to be flawed, so I introduce a call to random() just before he jumps:

//Make sure we're on the ground
if (place_meeting(x,y+1,objBlockParent))
//If we're gonna fall next step
if (!place_meeting(x+hspeed,y+1,objBlockParent))
//only if player is above or on same level as enemy
if (objPlayer.y<=y)
//Jump on random chance.
if (floor(random(2))) vspeed=-jumpspeed;

So I’ve got a 50% chance of jumping, and 50% chance of falling.

Unfortunately, that’s still pretty unrealistic; human’s aren’t so flawed that they would walk off a cliff for no reason. I need something different.

This time I’m going to tell the enemy to always jump when he reaches a cliff, but also give him a random chance of making it to the other side by sometimes reducing the jump height.

//Make sure enemy is on the ground
if (place_meeting(x,y+1,objBlockParent))
//If we're gonna fall next step
if (!place_meeting(x+hspeed,y+1,objBlockParent))
//only if player is above or on same level as enemy
if (objPlayer.y<=y)

//Random chance to have lesser jump strength
if (floor(random(2)))

Now the enemy may or may not make it to the other side. He’ll always jump, but sometimes not far enough.

Another area where this kind of A.I. imperfection might be necessary is inside fighting and strategy games where you can challenge the computer. The computer could be programmed to scan all possible moves and weigh every variable to choose the perfect action every time. Unless, of course, one were to introduce a way for the computer to make an “honest” mistake. Again, not an obvious blunder like moving, in a game of chess, to leave the King wide open (maybe unless the game were on an “easy mode” setting), but an imperfect choice of which the player can take advantage should he or she be skilled enough to do so.

On the contrary to all this, some may argue that even if a computer is programmed “perfectly”, the A.I. is only as smart as its designers. Were this assumed true, then as designers are “flawed” humans, it would follow that this is all a non-issue because then a computer could not ever be completely perfect in the first place.

Speaking of chess above, this subject comes into play with chess during man vs. computer competitions. The computers are programmed by top-rate computer scientists, but have still been beaten by “mere humans”. You can find articles about science’s efforts to determine, using chess, whether man is ultimately smarter than computers, by following these two links:

Link 1
Link 2

I feel I’ve been pretty thorough on this subject. I hope I haven’t introduced too much information.

Anyways, the platform enemy example I gave above isn’t necessarily completely realistic; however it illustrates the concept of imperfect A.I. fairly well and that’s all it was meant to do.

  1. Moonsider
    May 31, 2009 at 6:16 am

    This example really makes sense!
    Advanced computer opponents takes patience to create. But the thing is that good programming skills and math skills isn’t enough for creating this kind of opponents. You need to have something more than that: IMAGINATION.

    My point is: If you want to make good games, don’t just practice the programming language. You also have to play a lot of old games in different genres. And to get CPU acting like a person, you need to understand human behavior as well. So don’t underestimate human interaction. Imagine programming a football simulator without studing real football players or game tactics. That’s what normal researchers do and this is also applicated by the some game producing companies.

  2. September 22, 2008 at 5:30 pm

    I like your article. I’ve thought about that several times, especially as a long-time player of Civilization, where AI makes the game what it is (I was playing long before the multiplayer and online options existed).

    On easy, the AI on civilization are always revolting in the early versions of Civilization, it’s kinda funny.

    I actually need help with Game Maker, if you’re interested in answering some of my questions I’d be grateful. Just send along an e-mail saying “game maker” in the topic.

    http://for-you-only.diaryland.com (my blog, username: read password: me)

  3. Fede-lasse
    September 20, 2008 at 12:02 am

    You also posted this on the GMC. Extremely interesting!

  4. August 15, 2008 at 10:57 am

    Wow.. interesting article but kinda confusing (to me)

  1. August 20, 2009 at 1:44 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: