Documentation - Path Algorithm
V.06

NAME:
  Units sincronization

Problem description:
  The units that are moving on a map must avoid collisions between them.

Algorithm:
returns a number in the range [0, MAXSTEP), which represents the position
between the adjacent cells among which the unit is moving

Variables:
 step - position between cells
 crt  - current cell
 next - next cell

Step procedure -
 increases step with at most 1, or initialize it to 0 when the unit reaches
 next cell

| if the state of unit is "stay"
| | step := 0
| | return step

if the state of unit is "wait for moving"
| if next cell is not free
| | step := 0
| | if unit can't wait anymore
| | | save the state of next cell
| | | set the state of next cell to "locked"
| | | repath
| | | restore the state of next cell
| | return step
| set the state of the next cell into "temporary locked"
| set the state of unit to "moving"

step := step+1

if step >=MAXSTEP
| set state of crt to "free"
| crt := next
| set state of crt to "temporary locked"
| if destination is reached
| | set the state of unit to "stay"
| else
| | set the state of unit to "wait for moving"
| step := 0
       
SourceForge.net Logo