- Home /
Need algorithm for selecting/choosing from victems by several enemies
Hello
I want a number of wolves attack a flock of sheep
I wanna make/use an algorithm that makes each wolf select/choose a different sheep to attack than his mates maybe
or let's say I wanna make something near to real life
any recommendations for this type of AI ? the place will be almost empty place with little obstacles I am currently assigning a navMeshAgent on the wolf but I am asking about the process of choosing the destination victem
thanks a a lot
Answer by Briksins · Dec 17, 2013 at 05:01 PM
Hi there, im not going to write actual code, but will explain logic
assume you have some amount of wolves and seeps
Get in array list all your wolves
Get in array list all your shipps
choose randomly any sheep from sheep array
assign it to any random wolf in wolf array
remove that sheep from sheep array
remove that wolf from sheep array
repeat the loop until wolfs or sheeps array size is zero
you can make it even more complex by choosing not a random sheep for a random would, but closing the closest sheep for the closest wolf, so you will have to iterate trough whole array anch check the distance and find the closest one and then, assign that sheep as a target for a wolf and remove them both from the lists as they are already processed itmes