dimanche 21 juin 2020

AI : Squad Unit

AI Squad demo

On a shooting game, player frequently face a multiple enemy which sometime act like a squad (team).
F.E.A.R (First Encounter Assault Recon) is a fps which have a "revolutionary" ai system. On this mini project,I try to integrate a ai system similar to the game

Analysis

Thing that I undestand from the paper "Three State and a plan : The AI from FEAR" by Jeff Orkin,it's that a AI can be summary 2 states  moving entities and perform animation (because I'am just using basic shape like triangle and quad, they will not have animations). So the idea is to make the transition less as possible. One other thing is to separat between goal , action , and reaction, that way designer and programmer have a maximum of modularity to create different action and goal

Sensor, Goal , and Action

To create a maximum goals, actions and reactions . I create each action and reaction (call "sensor") separately.

By example sensor , I create sensor call "View player" (player enter in ai sight) , " search ally" (ai can detect if he got allies around him)

By example actions, i create by example , "looking at position" (ai goes to inspect strange location), "attacking player" (shoots at player position) "go to cover" etc etc

An I create goals, goals is form by actions create previously, that way goal is create by juste combining different to create specific goal.

Squad Behaviors

AI agent work as a squad entity (thant mean it's form by multiples soldiers). AI Entity have role like soldier which follow order of a captain, a catpain which give orders to soldier.

Each goals is selected with a Behavior Tree (and black board) to select the best actions on each situations

Each AI entities need to gather all the information on the world to select actions.. if an agent detect by himself an information, it's update his blackboard but he also needs to share this informations with his colleagues. Worldstate is an instance share by all ai entities , each time a entity wants to say something to other ea, he put a message on this WorldState. His colleague just need to get the message to update theirs status.

By example, supose that the commando hear a fire shoot from the player, he wants to send soldiers to inspect the zone. He send an order on the world state (Call "FACT") , soldier can pull the order from the worldstate, if the order is more important than he current action, he will follow the new order from his boss. He then update the worldstate to tell his boss that he gots the informations.

The modularity by separating action and goal play a role in this example, because commando can give order goal to soldier but only soldiers with the goal can answer
the order.


Soldiers patrols

Soldiers inspect suspect location
soldiers attach the players


Direct X12 Game Engine

I start a game engine which are using OpenGL/ DirectX12 graphic api

All the IA on article below are using my game engine on OpenGL

Here is some pictures of CG graphics using Direct X 12. Theirs demo is from the book "3D game programming with Direct X12 " whici I implementend in my game engine

Basic shape



Textures shapes


Billboard with geometry shader

skining without texture for now
skybox

lundi 25 mai 2020

Beat them all (UE 4)

Presentation

On this project use with unreal Engine 4 , the idea is to reproduce a beat them all game like Devil May Cry (DMC).

Note this project is not finished, and I have no intention to make a real game. It's just a demo

Actions 

- Attack enemy, base on the timing of the input, theirs is different combo. On this project if the player input : attack, attack, wait the end of animation, then attack
.Player actor will perfom 2 more attack (like in DMC)
- Locking target and move around. Player can change target lock
- Player can fire projectile (UE 4 Logo) if a enemy is lock , projectile go direclty on target
- If the play walk during an certains amount of time, it's will run (Like in DMC 5)
- Player can jump and attack
- Charge attack (DMC) :  if the player input front + attack , player actor rush to the target if lock and attack
- Launch Attack (DMC) : if the player press back + attack, player will perform that launch enemy upward
- If the player does'nt touch anything , the player actor will perform a relax animation

Lock Action

Relax Action

Attack action

Run Action

Behavious Tree (BT) with Finite State Machine (FSM)

We can combine Behavious Tree and Finite State Machine. Each Leafs of the Behavious Tree are Finite State Machine system. That way we can get all advantages of this 2 AI techniques.

I use this paper A Character Decision-Making System for FINAL FANTASY XV by Combining Behavior Trees and State Machines by  Youichiro Miyake, Youji Shirakami, Kazuya Shimokawa,
Kousuke Namiki, Tomoki Komatsu, Joudan Tatsuhiro,Prasert Prasertvithyakarn, and Takanori Yokoyama(http://www.gameaipro.com/GameAIPro3/GameAIPro3_Chapter11_A_Character_Decision-Making_System_for_FINAL_FANTASY_XV_by_Combining_Behavior_Trees_and_State_Machines.pdf)use in Final Fantasy 15 , I didn't implement the tool but get the idea

Behavior Tree is an classical one and the FSM is based on this paper A Reusable, Light-Weight
Finite-State Machine by David Grez Graham (http://www.gameaipro.com/GameAIPro3/GameAIPro3_Chapter12_A_Reusable_Light-Weight_Finite-State_Machine.pdf) use on this game Drawn to Life: The Next Chapter.

On this sample project, Actor lives in a house and 3 neend : sleep, eat, wash (and play video game if he have nothing to do), it's like the Sims game.
Every time a leaft of the BT is selected, we goes in a FSM to accomplish actions by instance eat means take a meal, put it on oven and eat or for sleeping it's means switch of the light , sleep n and switch on the light when the actor sleeps enough



Score Behavious Tree (Goal Oriented Behaviors Score)

Behavious Tree actions are selected depend some conditions.One of the weakness is player can anticipate the action if he knows how to trigger this behavious
and on the developpement we need to add more and more condition when we are checking condtions

On this paper : Simulating Behavior Tree, A Behavior Tree/ Planner Hybrid Approach by Daniel Hilburn(http://www.gameaipro.com/GameAIPro/GameAIPro_Chapter08_Simulating_Behavior_Trees.pdf)Use the in Jedi Academy Kinect.The idea is to make "simulation" of each action possible and select the best one. On my side, I add a score system to know which are the best actions

On this example, it's a shooter game. The AI Actor have to select the best actions depend on data:

Data are :

- Weapon : Handgun, Shotgun, Sniper . Weapon are more or less effective depend on the distance (Sniper is good for far target, where shotgun is good for close combat)
- Health
- Cover
- Health pack distance

Actions :

- Attach the player
- Go Cover or take health pack
- Go near or far the target to use more effectively weapons

With this method, user can add/remove conditions and can tweak more easier than a "classic" BT

Bot attack player with a sniper

Bot go near the player to use shotgun

Finite State Machine (FSM) & Behavior Tree (BT)

Presentation

In video games, two of the most AI algorithm use are Finite State Machine (FSM)
and Behavious Tree (BT). They are easy to implement and can have good result

FSM

FSM is the easier AI algorithm to create. Each behavious are state so it's easy
to create new behavious. A lot of document is already made on this subject
and it's use on commercial engine like Unreal Engine (Animation use state machine)

On this example project. Actor moves to eat or sleep depend of this state,
if its ok for eat or sleep . He goes to work



Behavious Tree

Behavious tree is the 2nd AI Algorithm, as the name suggests, it's a tree algorithm.
It's go on each branch and see if the condition is met, depend on the node (selector or sequence)
behavious leaf is selected

On this example. The Actor patrol on the waypoint path, random gold are spawn on the map,
so actor can pick gold.. If the actor see the player, he will pursuit him to catch the player

With selector, BT can give priorities on actor actions, on this example
the most importants actions are : Chase the player, Pick gold then patrol



Space Invaders (C++/OpenGL)

Presentation

Here is Space invaders in C++/OpenGL. The main objective is of course to have a working game but more important the goal of this project is to develops somes features use in modern video game

Smart Pointers

A lot of object like aliens or player rockets are dynamically allocated , so on the heap. The difficulity of variable allocate on the heap is to manage the lifetime on the variable : When to allocate or when to delete, a small forgot of deallocation can mean a memory leak that will become bigger with time

With C++ 11, the language got smart pointers. Smart pointer are wrapper of a pointer variables which automatically manager lifetime of a pointer.
This project use unique_ptr (uniquer ownership) and shared_ptr( multiple ownership for an entity) 

Event System

Entity objects have to communicate between them . A player rocket touch an alien entity or alien collides with player by example. To avoid that player class  use enemy data, an event manager is useful to simulate interaction between objects.

Like an observer design pattern, player and alien subscribe as a listener on an event manager. When an "event" (rocket collision) is trigger, an event is create and add to the event manager which can after contact listener (in this case alien and rocket classes) to manager the event.

Pool Memory

Allocate object on the heap during runtime it's a bad thing due time to get memory adressy ,this can have negative performance of the game.
One solution is to allocated a finite number of rockets and aliens but this will limit the numbers of each entity

The pool memory is one of the solution. We can allocate a big chunk of memory and then divide this big chunk with defined block of memory. 
When a rocket entity is need, we pull block memory from the memory chunk, and when the rocket is destroy we give back this block of memory to the memory pool.
Because each blocks of memory of the memory pool have the same size and we use 2 pointer to know where are "free" or "use" memory , their is no "hole" of memory during
allocation and deallocation of memory.

With a pool memory, we can use dynamic memory but without the overhead of calling the memory manager. We allocate only one time the memory : at the beginning of the game

Dynamic Game Loop

Gameloop is the core of the game. Each Entity (input,player,physics,enemy) is call in a defined order. But sometime we need an dynamic ordering instead of a static
order, by example we don't need to call some entity or we wish to change the order of the gameloop

On this project, I create a linkedlist of entity that way we can add or remove entities need for the gameloop

Images