0
$\begingroup$

I'm using Python and the BGE to build a cellular automata "game". I have a world that Automata wander through. If they get within a certain distance of each other, I'd like them to decide to greet or ignore the other. I'm looking for the right pattern for that.

Each automata has its logic controlled by Automata.py with a class within it. The world has spawners in World.py. What is the best way to iterate over all possible pairs within distance d of each other. My initial model is to have a set automata = [] with everyone in it, then do a double loop.

for me in automata:
  for you in automata[me:]:
    if distance(me, you) < d:
       if me.decide_to_greet():
         me.greet()

Is it better to make this a routine in world or done per automata? Are there accepted, efficient patterns?

thanks!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.