Basics of AI?
3 16 Sep 2016 17:16 by u/FrankyG170
Hello fellows.
Since the gamedev sub is relatively inactive I figured I would post on here. I am looking for some basics on AI in gaming.
What I am specifically looking for is how different difficulties are programmed into the AI and how to make it "not perfect" at playing the game. I've searched but there isn't much concise literature I can find that puts everything together.
Any help is appreciated!
If it helps the languages I am experienced with are C#(intermediate) and Java(beginner/inter).
7 comments
5 u/rwbj 16 Sep 2016 17:49
This is a very complex question that is heavily dependent upon the game you're talking about. It also depends upon the system you're using for AI. If I were to try to give a general answer it would be to intentionally cripple your heuristic evaluator. So for instance imagine we have a game where your AI's decision tree is based on a min-max algorithm and your heuristic system evaluates each position from a 1 (losing) to 10 (winning). A simple way to cripple this heuristic system would be to change your heuristic evaluator's final value to be at most 7. So now a 7 move and a 10 move become effectively identical to the heuristic and consequently instead of always playing the best move the AI will play anything with a 7+ evaluation with an equal probability.
2 u/diodine 16 Sep 2016 18:40
Keep in mind that all living things are very simple:
Make your guy listen for events - such as a hook thats called whenever a sound is played or when something enters LoS. When you simplify it like such, making him react to these stimuli is easy.
As for making your AI intentionally dumb, that's also easy. If hes shooting a gun, just make his aim-angles bob around with something like
sin(time()) x (1-difficulty_pct). For path finding, make him take intentionally long paths, or even better make him only know about certain nodes by visiting them (or having a buddy who has a radio on his model visit the area). If you have a bunch of guys in an area who need to go somewhere, make their willingness to take a certain path with their buddies random (to simulate them doubting their buddies) or make them split up (such as marking 2 bots as being "leaders" and each inferior bot having a high-willingness to follow them)You should generally try to follow the whole "willingness" thing. Like, for example, certain bots might be 60% willing to run away from a fight, 20% willing to run right in, and 20% willing to stay where they are. Make certain stimuli effect these percentages - such as if he sees 3 opponents his willingness to run away goes up 10% and his willingness to stay or push go down based on what equipment he thinks his enemies have. Make it so if he hears or sees a grenade hit the ground his willingness to run away goes to 75%, his willingness to stay goes to 0%, and his willingness to push ahead goes to 25%. The chosen skill level might change how these percentages scale.
That's all I have to say. I'm not in this field so I can't say any of this is the best way to do it.
1 u/scorinth 16 Sep 2016 18:18
I've been poking at AI off and on for a few years, but to be clear, I'm not really a programmer...
If you understand the basics of how different types of AI work, like finite state machines or goal oriented action planning, you know that these are basically about making decisions with math. So to alter the difficulty, you find the numbers that control the decision-making and you play with them.
Like, in a finite state machine where guard characters have an "alert" state, an easier guard might only enter the alert state if the player character gets very close, and stay in the alert state for a much shorter time, relative to a guard set to a higher difficulty. If it's a more complicated system like GOAP, the AI does a quick calculation involving "costs" of different possible actions. You can artificially increase the costs of actions that would be more beneficial to the AI character, and thus make the AI make worse decisions.
This is aside from "cheating" methods, like just pushing around an AI's aim to make them worse shots, giving them less health, or spawning less of them in each squad, but somehow I doubt that's what you're asking about.
EDIT: If what you're looking for is step-by-step tutorials or code you can crib from, you really aren't going to find it easily. The theory is easy to find, but you'll probably be on your own as far as implementation. I'm not sure if this barrier to entry is intentional or if it's just that everybody who knows how to implement AI code like this just doesn't have the time and energy to explain it in detail.
1 u/Datawych 16 Sep 2016 21:44
First, you need to identify what kind of game AI it is. In my experience, there are 3 types.
Little Miss Perfect: This type of AI is challenging because its computer brain can do things that the player's human brain cannot. Its reflexes are better than a person's, its aim is better than a person's, and it can think further ahead than a person. Think Deep Blue - it beat Kasparov because it built enormous what-if trees for every possible move, then just picked the best choice every time. Little Miss Perfects don't fuck up inputs or get distracted.
Mr. Cheating Bastard: This type of AI is challenging because it doesn't have to play by the same rules as the player. It has access to information that the player doesn't and is given a handicap. Civilization is notorious for this type of AI - upgrading the difficulty doesn't make the AI better, it just makes them cheat more. Mr. Cheating Bastard wallhacks and maphacks, and always seems to have more health/ammo/money/etc than you do.
The Improviser: This type of AI is challenging because it figures out your favorite tactics, then refuses to let you use them. In Metal Gear Solid V, once the enemy knows your playstyle, it will begin to equip soldiers with gear that punishes that playstyle.
Each type is made more/less difficult in a different way. Have some type of setDifficulty method that determines how often Little Miss Perfects make mistakes, how much Mr. Cheating Bastards are allowed to break the rules, and how frequently an Improviser is allowed to adapt.
0 u/roznak 16 Sep 2016 17:47
I doubt that you will get a good answer:
I think you will have to go the hard way, discovering it yourself and maybe find better ways.
0 u/tame 17 Sep 2016 12:28
What kind of game are you making? Game AI is almost always tightly coupled with the specific game, and doesn't bear much similarity to "real" AI. So for a chess AI you'd vary its difficulty by changing how many ply it looks ahead, whereas for a FPS bot you'd change its reaction time and aiming accuracy (or if you want to get really cheesy, just bump up its hitpoints and damage). An RTS bot or a Tetris game would just throttle its actions per minute.
Take a read through the gamedev.net AI forum - there's tons of good info on there iirc. Also there are regularly good articles on Gamasutra from commercial game devs about all sorts of things, including AI.
0 u/badkangaroo 22 Sep 2016 08:52
http://ai4g.com/ id suggest this book as well as http://aiwisdom.com/ having gone through these there are some good lessons here. basically; smart ai that knows everything is not fun, predictable sort of dumb ai is more fun, to a limited extent.