🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: rec.games.programmer
Article #858

Re: Shortest Path Algorithm

#858
From: Brian Scearce
Date: Wed, 26 Aug 1992 01:53
32 lines
1367 bytes
I forget the official name of this algorithm, but:

struct path_element {
  Cell *indicator;
  int cost;
  Cell *previous;
};

Set struct path_element Reached;

if (start_cell == target_cell) return; /* already there */
create path_element start;
start.indicator = &start_cell;
start.cost = 0;
start.previous = NULL;
Reached = start;
for (;;) {
  for each cell in Reached {
    find cheapest cell reachable from it that isn't already in Reached;
  }
  if (cheapest == target_cell) return; /* found it */
  add cheapest to Reached;
}


And that's it.  Details of implementation left as an exercise for the reader.


---
Brian Scearce                               bls@sector7g.eng.sun.com
        The above does not necessarily represent Sun policy.
          It's easier to get forgiveness than permission.
Technical Details
Message-ID: <l9lp1eINNmf1@exodus.Eng.Sun.COM>
Path: arc1-ca.pugleaf.net!sparky!uunet!cs.utexas.edu!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!ames!sun-barr!news2me.ebay.sun.com!exodus.Eng.Sun.COM!sector7g!bls
References: <1992Aug20.152143.1953@afit.af.mil>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!cs.utexas.edu!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!ames!sun-barr!news2me.ebay.sun.com!exodus.Eng.Sun.COM!sector7g!bls
From: bls@sector7g.Eng.Sun.COM (Brian Scearce)
Newsgroups: rec.games.programmer
Subject: Re: Shortest Path Algorithm
Message-ID: <l9lp1eINNmf1@exodus.Eng.Sun.COM>
Date: 26 Aug 92 01:53:50 GMT
References: <1992Aug20.152143.1953@afit.af.mil>
Reply-To: bls@sector7g.Eng.Sun.COM
Distribution: world
Organization: Sun Microsystems
Lines: 32
NNTP-Posting-Host: sector7g