Marcus Boswell
Marcus Boswell

Reputation: 1

How to make agents exchange message based on proximity?

I'm creating a zombie apocalypse simulation. I created this function within the main. The function is supposed to have the zombie and human exchange messages when they get within 1 meter of each other. Eventually this message exchange will cause a state change or change from one entity to the other (human to zombie).

(lowercase zombies or humans is the population, lowercase zombie or human is the individual, and uppercase Zombie or Human is that specific instance in the for loop

Function checkZombieProximity:

for (zombie Zombie : zombies) {  // Assuming zombies is a collection of Zombie agents
    for (human Human : humans) {  // Assuming humans is a collection of Human agents
        if (Zombie.distanceTo(Human) <= 1) {  // Check if any human is within 1 meter
            send("bite", Human);
            send("bash", Zombie);
            return Human;  // Return the human that is within 1 meter
        }
    }
}
return null;  // Return null if no human is found within 1 meter

zombie chart

human chart

main page

function

I'd like that if they got within one meter (zombies move towards humans with movetoNearest(humans) then they would exchange the messages 'bite' and 'bash'. If that is successful then I will put a transition conditioned on a particular message with a guard of some probability.

What is happening now, the zombie moves toward the human, stops, and then doesnt move at all. The humans do not change states at all.

Upvotes: 0

Views: 31

Answers (0)

Related Questions