Jump to content
Sign in to follow this  
Rydygier

Sneaky Hunter AI algorithm

Recommended Posts

SNEAKY HUNTER AI

1. Introduction

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.

2. Description

SH 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.

SH 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).

3. Usage

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
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.

Enjoy

Project was created "by player for players", source scripts you can freely modify, copy, "cannibalize", to use in your projects. It is released under APL-SA license. I'll be grateful for notification about each such usage.

Edited by Rydygier

Share this post


Link to post
Share on other sites

Nice Rydygier..

Sounds like fun, why am I thinking Namalsk and the Charons predator mod :D

Will take her for a ride next opportunity!

Share this post


Link to post
Share on other sites

:)

Note however, that Charon's predator if I'm not mistaken, is controlled by own FSM, that probably will conflict with SH, so that FSM(s) should be disabled/removed somehow first. Also in current form SH is designed for melee atacking hunters, like animals and such.

Share this post


Link to post
Share on other sites

And how do you exactly imagine such game mode?

Share this post


Link to post
Share on other sites
Guest

Release frontpaged on the Armaholic homepage.

================================================

We have also "connected" these pages to your account on Armaholic.

This means in the future you will be able to maintain these pages yourself if you wish to do so. Once this new feature is ready we will contact you about it and explain how things work and what options you have.

When you have any questions already feel free to PM or email me!

PS:

I think IceBreakr does not allow the usage of his islands in Arma 3 so your example mission actually brakes his license. Better replace the example mission on another island maybe?

If I am wrong and/or you have permission just ignore this part.

Argggh, I was completely lost I think. This is an A2 release......sorry.

Also Armaholic pages moved to the proper section!

Edited by Guest

Share this post


Link to post
Share on other sites

Cool, now for Arma3!!!

Question, could this work for like multiple groups hunting a player, or 2 players, so for example you are trying to escape an enemy occupied area after killing an enemy officer, and theres a hunting party after you, could you have like a infantry squad or more hunting the player if you put the code in the squad leaders init line?

Or is this more specific to one AI hunting the player as indicated?

Share this post


Link to post
Share on other sites

This simulates rather animal (predator) hunting behavior (lurking when on sight, attacking, when behind, smelling the trail and following it, keeping own silhuette out of prey's LOS... that sort of things). Not so well for human hunters, unless very strange humans. :) I even requested custom quick and agile animal predator model responding on scripts like regular unit, not A2 vanilla animals, suitable for this script, but so far no one answered. We have Predator, aliens, zombies and such, but all with own FSMs, and no real animal (except crocodile) like panther or something like that.

There may be several preys (AI or player, no matter), but hunter should be one. Perhaps technically we could set up several hunters, each with own set of loops, but this would be heavy and may occur intereferences due to some fancy tricks used.

However, not a problem, I can think about round-up chasing/hunt performed by troops. Just list your wishes of perfect hunt, no matter, how ambitious... I also remeber, there are some FSMs/scripts handling that sort of things already. One should be in the Rube's pack. Probably there is more such scripts.

Edited by Rydygier

Share this post


Link to post
Share on other sites

I finally tried this quickly last night, on Namalsk with a mutant as Hunter and me as prey, a bit nerve racking as the mutant would do quick hit and run attacks then move away and disappear, but i could hear him continually trying to flank me.

Also its nice to know you are able to escape the hunter.

In terms of some type of game play

  • Instead of loiter if hunter loses scent could he move in the last known direction of prey, maybe at full speed in an attempt to pick up the scent again and if not then goes into loiter.
  • could there be multiple hunters chasing the same prey, possibly working together.
  • Weapons - I was thinking that there might be some sort of nice sniper v sniper against AI maybe incorporating that sniper position script i think you had made.

EDIT: It took all morning to complete this post and i see most has been answered in the meantime.

Share this post


Link to post
Share on other sites
Instead of loiter if hunter loses scent could he move in the last known direction of prey, maybe at full speed in an attempt to pick up the scent again and if not then goes into loiter.

Good idea. Let's assume animal is smart enough for that.

could there be multiple hunters chasing the same prey, possibly working together.

Hard to achieve and rather do not happen with this code, especially working together part. It is script for classical horror situation, where we have one beast somewhere killing alone prey, or preys one by one.

Weapons - I was thinking that there might be some sort of nice sniper v sniper against AI maybe incorporating that sniper position script i think you had made.

Nice idea, but for another project. I'm nearly constantly looking for such inspirations, so who knows? :)

Namalsk hunter fits perfectly, only concern is, it probably is controlled by own FSM, so final effect could be rather chaotic and not exactly, as intended. Of course, if it is audible from a distance, it is easier to avoid/defeat. Best effect is, when hunter stays silent.

Edited by Rydygier

Share this post


Link to post
Share on other sites

Ok as you mention, we need a hunter and some real prey like deer.

Im going to play around with Charons predator mod, as that seems to be the perfect candidate with their wrist blades, ill see if hunter can use the hunter FSMs after applying hunter disableAI "FSM"; in its init, or something like that :P

Other than that i can only think of the dogs available in arma, maybe having the ability to group human units to the dog like some type of tracking team, i noticed it didnt work when grouping anyone to the hunter but should be able to have units follow with doFollow

Or possibly have the dog as hunter under players control until dog picks up scent of prey... rabbit hunting maybe :)

Share this post


Link to post
Share on other sites

oK JUST dL THIS I dont have arma 2 maps and I just put this on a atlis map one ai and me and cant get this to work.What is the init script name i put in soldier and what is the file script for mission folder confused thank

Share this post


Link to post
Share on other sites

This never was tested under A3, so not sure, if will work at all. Nothing surprising, you are confused, if you not saw it in editor and not played demo mission. For sure will be problem with debug markers. Perhaps RPT says something? Anyway, if you open demo mission folder, eg SQF demo, then you see, what must be inside mission's folder (Init.sqf, Predator_aux_fnc.sqf and Predator_fnc.sqf in this case). You have nothing to put into any init field. All is initialized in init.sqf, but units must be named same way, as in demo: hunter1 and hunted1, I believe.

Share this post


Link to post
Share on other sites
Im going to play around with Charons predator mod, as that seems to be the perfect candidate with their wrist blades, ill see if hunter can use the hunter FSMs after applying hunter disableAI "FSM"; in its init, or something like that :P

Most efficient way would be to ask Charon for Predator version without default FSM. Config side it is trivial to achieve. Even I know, how. :) Of course we can do simply addon, that will overwrite Predator's config, but of course better is "official" way.

doFollow, I suppose, indeed should make chosen unit follow the hunter, but will not mimic other hunter's behaviors, like go prone to avoid detection, if player is looking that side, and hunter is in sight and too far for strike.

Share this post


Link to post
Share on other sites

Your right, I tried but it didn't work with predator, I shall ask Charon.

Share this post


Link to post
Share on other sites

^^ in the forums it is not. In Armaholic it is, must have been overlooked due to the revival of the thread after some time sleeping. :)

Share this post


Link to post
Share on other sites

Haven't had a chance to play with it yet, but I just d/l'ed and browsed through some of the code. As always, Rydygier, exciting and innovative stuff that undoubtedly has applications in terms of AI scripting beyond just this specific scenario. Really looking forward to playing with it later. :)

Share this post


Link to post
Share on other sites
So if this script isn't for arma 3 why is in the arma 3 category?

That's right question for sure... :) Some mistake occured apparently. Foxhound informed. Hmm. That explains, why this script suddenly became so popular lately... :) Of course now I have no choice but to make A3 version too... Sigh.

exciting and innovative stuff

There are parts in this code, that are working, but I'm not quite sure how and why. Result of half-blind tests... :) I'm takling mostly about determining path, that allows to avoid area covered by prey's LOS. I was looking pretty long for optimal code here, yet final result sometimes can be still erratic. And CPU-heavy of course. All those square locations to create/delete on the fly and LOS checks for all of them...

Edited by Rydygier

Share this post


Link to post
Share on other sites
Guest
That's right question for sure... :) Some mistake occured apparently. Foxhound informed. Hmm. That explains, why this script suddenly became so popular lately... :)

Sorry, I had a brain malfunction I guess.......

pages moved.

Of course now I have no choice but to make A3 version too... Sigh.

Sorry again, I wont do this again to not give you more work!!

;)

Share this post


Link to post
Share on other sites

:D Not a problem. In fact, probably that generated more feedback. More feedback -> better for the script. :)

Share this post


Link to post
Share on other sites

Updated to 1.1 and, basing on newest version, released A3 version:

ARTEMIS

Changelog:

- several minor code fixes.

Share this post


Link to post
Share on other sites

Either way or another @Ryd i took a glance in this script (noticed it in your signature) ..and always believed

it was excellent work//brilliant idea.

Although we still don't have a model of a hunter (animal/sci-fi creature) ..i wish i could have this for ARMA 3..even though as "taking space" in my HDD

:)

*edited some seconds later..*

lol it's done!! Thank you man :D

Share this post


Link to post
Share on other sites
Guest

Thanks for informing us of the update :cool:

Updated version frontpaged on the Armaholic homepage.

================================================

We have also "connected" these pages to your account on Armaholic.

This means in the future you will be able to maintain these pages yourself if you wish to do so. Once this new feature is ready we will contact you about it and explain how things work and what options you have.

When you have any questions already feel free to PM or email me!

** this time all in the proper way ;)

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×