# Simple bare-bones path-finding routine

I have a 2D grid with a number of cells. I need to find a path from one cell to another. There are no obstacles or opponents, and all cells are identical. What is a SUPER SIMPLE routine to calculate the shortest path? I have read about A* and other routines, but they are waaaaaaaay overkill in my case at this point. (Maybe I will need them later, in the future.) Thanks!

• If there's no obstacles or enemies to avoid, then wouldn't the shortest path simply be the straight line from you to your destination? Do you need help navigating along this line, or is there another complication that demands a different shape of path? – DMGregory Aug 21 '17 at 21:39
• The simplest algorithm is probably to calculate the vector between start and finish, then determine which of your valid directions it's closest to pointing towards. Then repeat until you're there. – BlueRaja - Danny Pflughoeft Aug 21 '17 at 22:02
• If you are locked to a grid, any path is going to touch the same number of cells, assuming you do not go in the opposite direction (if the destination is right of the start, never go left). Just going from corner to corner in a 3x3 grid would give 6 equally short paths. – tyjkenn Aug 21 '17 at 22:18
• Those are all good suggestions. Are there examples of actual code somewhere? – posfan12 Aug 22 '17 at 0:21
• Can your path include diagonals or only cardinal directions? – DMGregory Aug 22 '17 at 2:15

    _|                            |

The easiest to implement would be the latter example. However, if you want the zigzag that approximates the line, you can find x/y. This is how many to move right for every cell you move up. For example, if x / y = 2, then move like this: right, right, up, right, right, up, .... If it is less than one, take the reciprocal, and move that much on y for every movement on x.