vendredi 11 décembre 2020

[DirectX12] Match 3 on my Game Engine

 I made a Match 3 game with my game engine with Direct X12

Gameplay

Like the a lot of game like Candy Crush, the idea is to match 3 identicals candy vertically or horizontally. To make it, player have to pick 2 adjacent candy to swap them. When this occur , the candys are destroy and all the candy above fall, and news candy are create if need

Special candy can be create if more than 3 candy are destroy

- If it'is 4 candys vertically , a new candy is create which will  destroy all the line on the location of the candy
- If it'is 4 candy horizontally, a new candy is create which will destroy all the column on the location of the candy
- If it's 5 or more than , a special candy is create. If the player match with a candy near the special candy. All the candy same that the candy match are destroy

Multi threading

The gameplay algorithm is not very difficult. But I think the matching algorithm can be parralized 

Instead of iterate on each slot of the grid. I use a thread pool, when on each threads I send each lines of the grid.


Joker bonus

Start Grid

Vertical bonus candy


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


lundi 25 mai 2020

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