Author: Rydygier
Author Website:

Requirements:

Version: 1.1

Short description: Sneaky Hunter is an AI algorithm that simulates animal-like hunting behaviour of controlled unit (Hunter) against chosen unit(s) (Prey).

Date: 2013-11-21 20:27


Comments: (2)
Rating:



 

Sneaky Hunter AI

by
Rydygier


Description:
Some time ago I thought, it would be fun to have AI, that will hunt down the player or other AI, cunning beyond simple "Where he is? There? Charge! Argh!". More complex, thorough simulation with many factors handled even for the price of extended CPU cost. Sometimes in such situations I just sit down and write the needed script, and have no peace until done. This is such case...
Code is experimental. Any feedback, ideas, opinions etc. highly appreciated.

Sneaky Hunter is an AI algorithm that simulates animal-like hunting behaviour of controlled unit (Hunter) against chosen unit(s) (Prey).
This code does some heavy calculations, was tested for single Hunter, and this is recommended number of controlled units.
Sneaky Hunter AI is designated as opponent for player, but should work well also against AI. Was tested for single prey for now, but designed also for more.
Hunter has to his disposal two customizable senses: sight and smell.
Sight is specified by two parameters: light sensitivity and movement sensitivity. It decides, how easily Hunter will spot the Prey according on daytime, weather, size, speed, background (sky or not, surrounding terrain) and knowledge factor (memory).
Smell helps to follow not visible Prey by its trail. Each Prey will leave "footprints", that Hunter can scent. Old footprints will be erased, also rain gives small chance for removing some parts of the trail. Smell (range) is strongly affected by wind (direction and strength).
If there is no Prey nor trail known, Hunter will loiter randomly.
If Hunter see the Prey, his behaviour depends on situation. His goal is surprise attack, preferably from behind. Will charge anyway if close, but otherwise will approach, fast or stealthy, only when flanking the Prey (out of Prey's FOV). If catched in the FOV, depends on situation can hide low and not move or run out of LOS, then try to outflank keeping out of sight (heaviest calculations here including sector-based LOS analyze and pathfinding).
Is most dangerous at night, in the dense forest when visiblity is poor.
Hunter strikes with bare hands (melee).


Installation / Usage:
The package contains two demo missions, one per code version (pure SQF and FSM&SQF mix, both should give same or nearly same effect, just different implementation), that require Lingor Island map by IceBreakr.
Init.sqf files of these missions provide some details about setup and default parameters along with some simple debug option for testing purposes and better understanding, how hunter behaves. Debug is in form of map markers showing positions of hunter and hunted, knowledge about hunter value and distance.

Code preparing for both versions:
call compile preprocessFile "Predator_fnc.sqf";	
call compile preprocessFile "Predator_aux_fnc.sqf";
Exemplary code launch for SQF:
//Parameters: hunted unit, max trail lifetime in seconds (older "footprints" will be removed)
{[_x,3600] spawn RYD_H_MyTrail} foreach (units (group Hunted1));//trails for hunted units
//Parameters: hunter unit, smell sensitivity, eyes sensitivity [light factor,movement factor],hunted unit(s),loiter radius if no prey nor trail known if 0 - unlimited, force of the hunter's strike multiplier.
[Hunter1,3,[1.5,1.5],(units (group Hunted1)),200,1] spawn RYD_H_Hunter;
Exemplary code launch for FSM version:
//Parameters: hunted unit, max trail lifetime in seconds (older "footprints" will be removed)
{[_x,3600] spawn RYD_H_MyTrail} foreach (units (group Hunted1));//trails for hunted units
//Parameters: hunter unit, smell sensitivity, eyes sensitivity [light factor,movement factor],hunted unit(s),loiter radius if no prey nor trail known if 0 - unlimited, force of the hunter's strike multiplier.
RYD_Hunter_FSM_handle = [hunter1,3,[1.5,1.5],(units (group hunted1)),200,1] execFSM "RYD_Hunter.fsm";

Put these missions where all unpacked missions are stored an preview in editor. You are a prey here, and Hunter's position is randomized each run. Try to survive and defeat him. Often you will sooner hear the Hunter than see.

There is also optional, but recommended tiny addon, that will tweak used in the demos Hunter unit (no danger FSM, no weapons, harder to spot for AI).

SH probably can perform even better for some hipotetical custom animal model if agile and faster than human and not driven by own FSM.


Changelog:
v1.1
- minor code fixes.

v1.0
- first release


Forum topic:
- BI forums




Enable javascript to be able to download from Armaholic please!



Tags: Ai,   Algorithm,   Hunter,   Prey