Is this an acceptable algorithm for pedestrian motion that searches and mingles with "buddies" on its path to the goal?

102 Views Asked by At

I'll put my pseudocode here first, please advise regarding its validity according to real-world pedestrian motion, and how I can improve it.

Premise: A turtle walk from its spawn point to the goal. On the way, it meets other turtles. Turtles of the same color will be treated as a "buddy" and will go near it, simulating a "friends-walking-down-the-street" scenario. Turtles of the same color with nearer distance has higher priority, e.g. friend A is nearer than friend B so I will approach friend A first.

Upon approaching the goal, the turtle goes back to its spawn point.

Pseudocode:

determine if i am already in the goal
if yes,
    determine if there are patches I can walk on
    set eyes on nearest patch I can walk on (for the goal path)
    if there is a friend nearby, approach friend
    if there is no friend nearby, continue walking the goal path
    if im already in the goal, respawn.

Advise for improvement please?

1

There are 1 best solutions below

0
Oliver On

The premise doesn't say anything about how returning to spawn point occurs so I will assume it is a one step action (ie you are not interested in those details). I see something more along the lines of

spawn loop: 
  spawn
  goal loop: 
    determine if turtle already reached goal
    if no,
      determine if there are patches I can walk on
      set eyes on nearest patch I can walk on (for the goal path)
      if there is a friend nearby, approach friend
      if there is no friend nearby, continue walking the goal path
    if yes, 
      setup so can respawn (return to spawn loc, etc)
      goal loop ends