📜 ⬆️ ⬇️

Insomnia: game artificial intelligence is so artificial (video)

We continue the theme of the process of creating the game Insomnia, begun with the article How we stopped fearing Ogre and began to make a game on it

About idols

To begin with, at the time of the start of the project, we did not plan to introduce AI as such. Several scripted scenes seemed to us to be quite a sufficient complement to the game.
All NPCs were planned to be made absolutely quick-to-shuffle, performing a strictly defined, looped sequence of actions.
It was fun to watch the NPS keep waving a hand at you while you thrust a second clip into it.
A walk through a densely populated location resembled a trip to a garden of stone figures.

About life

But as usual, life corrected our plans a little. Along with the rejection of the venture to do only MMO came the understanding of what intelligence we will have to do.
We decided to abandon the hard planning actions of the characters. Instead, we came up with a system that allows you to set the behavior of almost every character without significant additional effort.
We decided to bring the decision process closer to the human.
')
Subtle mental organization

To begin with the general scheme:



The basis of AI is “consciousness” and “subconsciousness”. This name was given to the blocks because of their way of processing information.

The “subconscious” processes all events from the sensors and, if necessary, sends events to the “consciousness”. By structure, it is more associative memory. An example of such a card:
* go to bed at midnight. Priority is low;
* if your fighting, then watch the process;
* If you beat your own, then protect him. Priority is medium;
* if you beat someone, go up and clear his pockets;
* If music is playing, then dance. Priority is low;
* if someone took the weapon, ask him to hide;
* if you saw the enemy, run to call for help and go to battle;
* if your name is for help, go where your name is;
* if noise is heard, turn around to see what is happening;
* if you see an abandoned grenade, run away from it;
* if you see that throwing a grenade not far from you, run up and throw back;
* if a player appeals to you, offer him something to buy;
* if a player who offended you turns to you, do not answer him;
* if you run away from someone and you hear the sound of footsteps behind you, then run on.
These commands are transmitted to "consciousness." Persian can have several such cards, the priority of these cards will vary depending on their mood / state. For example, a cowardly NPC may run away from you, but when he sees his people, he can gain courage and respond to you.
“Subconscious” may vary depending on the accumulated experience.

“Subconscious” will be not only the NPC, but the hero. For example, an unpatched hero can be quite cowardly and just run away at the crucial moment. There will also be an opportunity for the player to train his character in one way or another.

“Consciousness” is responsible for the logic of the character’s actions, for example:
* to attack anyone,
* shoot anyone or something
* follow the target,
* reload weapons
* go somewhere,
* inspect the chest,
* call for help.
This is a set of scripts that directly control the body. Unlike the subconscious, only one or several compatible ones can be active, for example, “Follow the target” and “Shoot at someone or something”. They can also be nested in each other, for example, “Inspect the chest” can cause “Go somewhere” (to the chest), and “Shoot at someone or something” cause “Reload the weapon”. Also in the case of GG, these scripts accept commands from the user and can act in accordance with these commands.

And the scent is like a dog, and the eye is like an eagle

Sensors.
The visual sensor monitors the surrounding NPC objects, checks their visibility, determines their state.
The noise sensor determines the direction and type of noise, for example, to respond to it. NPC can hear the noise in the corridor and go out to check what is happening there. Or, having crept up behind the NPC, you can impersonate yourself by starting to reload the weapon.
The time sensor is needed to perform some scheduled actions. At 9 to get up, at one o'clock on duty, at 9 pm to the bar, to sleep at midnight. Typically, actions triggered by this sensor have a low priority. If the NPC fights with someone and he needs to go to sleep, he, of course, will continue to fight. And as the case ends, with a clear conscience go to sleep.
A message sensor allows NPCs to exchange messages, report danger to other NPCs and give commands.

Now a small example of the implementation of AI.
A small comment - there are 4 characters in the video. Two soldiers of the committee and 2 marauders.
Soldiers of the committee perform patrols of the territory.
At detection of marauders they enter the battle. The AI ​​soldier is linear enough - he saw the enemy - call his own and start destroying the enemy (Priority “Attack”).
AI marauders are more flexible. When the marauders realize that they have been found, the leader (in expensive armor) sends the helper forward (priorities “Caution”, “Send a sentinel to a suspicious point”). Itself at the same time remains in place (Priority "Caution"). But in this case he was not lucky. One of the soldiers first saw the leader and opened fire on him. The helper engages in battle, but after the death of the leader, the priority of "Fear" exceeds the priority of "Attack" and the assistant decides to surrender. He throws away the weapon and stops resisting. But the last bullet puts an end to his inglorious career.



Thanks to all.
Posted by: Wowa69

Source: https://habr.com/ru/post/229381/


All Articles