A
A
Alexander Rublev2017-08-20 19:14:41
Programming
Alexander Rublev, 2017-08-20 19:14:41

How does AI work in games?

Hello. Maybe I asked the wrong question.
Tell me how AI is implemented in games. For example in the same SIMS or for example CS with bots?
Is each individual character a separate thread or do they calculate their actions sequentially?
I want to try to write a small game for myself with simple AI, but I don’t know how to implement it correctly.
I couldn't find anywhere to read about it.

Answer the question

In order to leave comments, you need to log in

8 answer(s)
D
Daniil Basmanov, 2017-08-21
@BasmanovDaniil

There are many approaches to the development of AI, the specific implementation depends on the specific game, somewhere two rules are enough that react to events, somewhere you need to build behavioral trees. They usually start with finite automata, as the easiest to implement, then behavioral trees and Utility AI go further in terms of complexity, you can read about all three in the article on gamasutra . In addition, you can read pdfs with articles on the Game AI Pro website . If you like to watch presentations more, you can look at the GDC channel .
Whether the code is executed in separate threads or not does not apply to AI development, it's just an optimization that is used according to the situation.

D
DepictWeb, 2017-08-20
@DepictWeb

For a beginner will do:
"game maker"
Google and find a ton of examples
Study, and then create your own games)
Good luck!

G
Griboks, 2017-08-20
@Griboks

On Habré there was an article about AI recently.
Well, seriously, the AI ​​is completely dependent on the game. Next comes the engine. Well, then everything else. For example, there is no AI in poker at all.

A
awdemme, 2017-08-20
@awdemme

AI (AI) is called purely by tradition.
As a rule, it does not smell of any real AI there.
A full-fledged AI in games can only be called https://habrahabr.ru/post/319518/
And usually, certain rules are simply sewn into the program, clearly tied to the logic of the game.
Well, for example, for PacMan (I hope you know the rules of the game) - the monster at each turn simply chooses the shortest path to the hero. The path is built simply by blunt enumeration. Choice of the shortest - too.

A
asd111, 2017-08-21
@asd111

For simple AI, a switch case or a bunch of if then else is enough
https://habrahabr.ru/company/intel/blog/265679/

L
loysob, 2017-10-24
@loysob

The question is rather about "scripted game logic in games." Think about a key example (pseudocode):

monster1.walkTo(level.homepointA); // идет из текущей точки в точку A, длится минуты
monster1.walkTo(level.coverpointD); // идет из точки A в точку D, длится минуты
monster1.fireAt(enemy, 5.0); //  стрелять по врагу 5 минут
monster1.walkTo(level.homepointA); // идти обратно в точку A

Input data:
- Static: Marking the map with invisible objects with names. The script uses them. Objects can have properties (cover height for example)
- Runtime: enemy - reference to the enemy object. Usually, the monster will be notified when a player enters its line of sight. (Think about implementing events and notifications)
Imperative actions, "verbs":
You are right about flows and sequences. I would like the actions to "last" and be performed sequentially and in parallel for different bots. In mainstream languages, this is not possible with standard methods. And therefore there each line will correspond to the state in the state machine. (Read about FSM).
Ideally, to work in a "sequential style", you can use coroutines. These are pseudo-flows just for the described case. Of course, all the actions described above can be supplemented with standard if / else branches, for / while loops, etc.
Here is an example of integrating Lua and C++: https://github.com/loyso/LuaCSP
For a beginner, it is better to implement the 1 bot = 1 state machine approach.

S
Semyon Beloglazov, 2017-08-20
@Batlab

This cannot be called AI, it's just a bot that is controlled by the game engine depending on the situation. It analyzes the information received and, depending on it, takes the action for which it is programmed.

L
Legebocker, 2017-08-20
@EnDeRJaY

Imagine, it just takes and works!
But in fact, this is not AI. These are just sets of decisions for each player’s action. AI is now weak and capable of making only one or several goals of the same character. Make a tic-tac-toe bot and you will stick for a month.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question