views:

69

answers:

1

Problem

I want ot write a simple 1D RTS game and have the following path finding problem: There are many one-dimensional lines and everywhere are teleporters which can be used to travel between the lines but also to travel inside the current line. The teleporters are the only way to travle between lines. What algorithm or pseudo code can used to determine the shortest path between position po1 on line li1 to po2 on li2? We have a set of teleporters T (each has a po and li) which are connected with each other with a cost of zero.

Why not A* or Dijkstra-algorithm

It's because I think these would be an overkill in 1D.

Clarification

  • It's maybe sounds a bit two dimensional but it isn't because you can only travel left or right on one line.
  • There are costs to travel to a teleporter but teleporting from one to another has no cost. See this ascii art:
    ...0....s..0
    ......0.x...

Here, the shortest is way from start s to target x is

  • to go to the right teleporter
  • teleport one line down (only in this graphic; really planes are unordered)
  • and go right to the target (final cost = 5)
+1  A: 

You can go from any teleporter from any other? In that case, there are only two possible ways: right and left from your starting position. Once you reach a teleporter, go the teleporter closest to the destination. Done. Ok, if you don't know which teleporter is closest to the destination, you might try them all on the same plane, but still.

calmh
I know, but a normal path (ie no teleporting) could be shorter than one with teleporting or there could be objects you can't pass in your way. In my opinion the latter is problematic.
Mafi
Objects in the way? You are redefining the problem... Otherwise, if the source and destination are on the same plane, you have the two options "straight line between them" and "straight line between them using a teleporter if there are at least two between source and destination."
calmh
After some thinking you're totally correct. Ignore my last post and 'object'. Anyways, shame on me...
Mafi
This solution is basically the brute-force, am I correct?
Justin L.
@Justin Pretty much, but the number of paths to check is extremely limited so it's about O(1) anyway.
calmh