Qbasicnews.com

Full Version: Shortest Path Algorithm in (Turbo)Pascal?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I am using Borland TurboPascal 7.0 (not that it really makes any difference), and, being extrememly poor at maths, have no idea how to write a shortest-path algorithm for a 2D tiley-type game. Does anyone have a good tutorial or function or procedure (prefferably one I can just pump a few numbers into and have it spit some out) to do this? It *shudders*... it... needs trigonometry, doesn't it?
Damn those ancient Greeks.... DAMN THEM ALL TO HELL![/i]
http://forum.qbasicnews.com/viewtopic.php?t=2872

No math. Smile

It isn't perfect, though. (if the target constantly changes, it's better just to move once and not calculate the whole move)

If you want, I can upload the gif I made for this..
... :o That smiley does not accurately express my exhasperation at the weirdness and futility of me attempting to understand that article.
just read through it, slowly..

seriously.

or, if you're online, I'll attempt to communicate.
Thanks loads

EDIT: I have just realised a fundamental flaw in my question; I am looking for a straight line algorithm, not a shortest-path one.
well, what exactly are you trying to solve?

a straight line's length can be determined by 2 points x1-x2 and y1-y2... So if you have something that wants to go straight, have it alternate in x and y. first, it goes in x direction, then in y, and so on... until it went enough in both directions.
OK, restating:
I want to be able to determine one (1), a single, one-and-only, non-curving, shortest-path-between-2-points LINE.[/code]
yeah, but are you trying to draw the line? or what?
I have ye olde text mode 80*25 ASCII thingy, and want to be able to determine a straight line between two points, say, I have the player: "@", and a rat, "r".

Code:
........r.
..........
..........
...@......
..........

Now, if the player shoots an arrow at the rat, I want to be able to determine how it gets there...[/code]
Here:

All vars with P=Player, R=Rat

Code:
cls
screen 13


dx!=rx-px
dy!=ry-py

Leng!=(Dx!*dx!)+(dy!*dy!)
Leng!=Sqr(Leng!)

dx!=dx!/Leng!
dy!=dy!/Leng!

sx!=px
sy!=py
For I=0 to Leng!
        
      sx!=sx!+dx!
      sy!=sy!+dy!
      Pset(sx!,sy!),15

Next I
Pages: 1 2