Class TwistedLine

java.lang.Object
com.github.yellowstonegames.path.TwistedLine

public class TwistedLine extends Object
Like DrunkenWalk, this generates orthogonally-connected paths of Coord that meander through an area; unlike DrunkenWalk, this won't ever generate paths that cross themselves.
This generates a fully-connected graph for a given rectangular area, then solves it with DefaultGraph.findShortestPath(Coord, Coord, ObjectDeque, Heuristic).
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
     
    final com.github.tommyettinger.ds.ObjectDeque<com.github.yellowstonegames.grid.Coord>
     
    com.github.tommyettinger.random.EnhancedRandom
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
    TwistedLine(int width, int height)
     
    TwistedLine(int width, int height, com.github.tommyettinger.random.EnhancedRandom rng)
     
    TwistedLine(int width, int height, com.github.tommyettinger.random.EnhancedRandom rng, com.github.yellowstonegames.grid.Coord[] traversable)
     
    TwistedLine(int width, int height, com.github.tommyettinger.random.EnhancedRandom rng, Collection<com.github.yellowstonegames.grid.Coord> traversable)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    int
     
    com.github.tommyettinger.ds.ObjectDeque<com.github.yellowstonegames.grid.Coord>
    Gets the last path this found, which may be empty.
    com.github.tommyettinger.random.EnhancedRandom
     
    int
     
    com.github.tommyettinger.ds.ObjectDeque<com.github.yellowstonegames.grid.Coord>
    line(int startX, int startY, int endX, int endY)
     
    com.github.tommyettinger.ds.ObjectDeque<com.github.yellowstonegames.grid.Coord>
    line(com.github.yellowstonegames.grid.Coord start, com.github.yellowstonegames.grid.Coord end)
     
    void
    Called automatically during construction, this sets up a random maze as a DefaultGraph so a path can be found.
    void
    Called automatically during construction, this sets up a random maze as a DefaultGraph so a path can be found.
    void
    reinitialize(com.github.yellowstonegames.grid.Coord[] traversable)
    This sets up a random maze as a DefaultGraph so a path can be found, using the given array of Coord to represent which cells on a 2D grid can actually be traversed (and so can be used in a random path).
    void
    reinitialize(Collection<com.github.yellowstonegames.grid.Coord> traversable)
    This sets up a random maze as a DefaultGraph so a path can be found, using the given Collection of Coord to represent which cells on a 2D grid can actually be traversed (and so can be used in a random path).
    void
    setRng(com.github.tommyettinger.random.EnhancedRandom rng)
     

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • rng

      public com.github.tommyettinger.random.EnhancedRandom rng
    • graph

      public final DefaultGraph graph
    • lastPath

      public final com.github.tommyettinger.ds.ObjectDeque<com.github.yellowstonegames.grid.Coord> lastPath
  • Constructor Details

    • TwistedLine

      public TwistedLine()
    • TwistedLine

      public TwistedLine(int width, int height)
    • TwistedLine

      public TwistedLine(int width, int height, com.github.tommyettinger.random.EnhancedRandom rng)
    • TwistedLine

      public TwistedLine(int width, int height, com.github.tommyettinger.random.EnhancedRandom rng, Collection<com.github.yellowstonegames.grid.Coord> traversable)
    • TwistedLine

      public TwistedLine(int width, int height, com.github.tommyettinger.random.EnhancedRandom rng, com.github.yellowstonegames.grid.Coord[] traversable)
  • Method Details

    • reinitialize

      public void reinitialize()
      Called automatically during construction, this sets up a random maze as a DefaultGraph so a path can be found. You can call this after construction to change the paths this can find.
    • reinitialize

      public void reinitialize(Collection<com.github.yellowstonegames.grid.Coord> traversable)
      This sets up a random maze as a DefaultGraph so a path can be found, using the given Collection of Coord to represent which cells on a 2D grid can actually be traversed (and so can be used in a random path). The traversable parameter is often a Region. You can call this after construction to change the paths this can find.
    • reinitialize

      public void reinitialize(com.github.yellowstonegames.grid.Coord[] traversable)
      This sets up a random maze as a DefaultGraph so a path can be found, using the given array of Coord to represent which cells on a 2D grid can actually be traversed (and so can be used in a random path). You can call this after construction to change the paths this can find.
    • randomize

      public void randomize()
      Called automatically during construction, this sets up a random maze as a DefaultGraph so a path can be found. You can call this after construction to change the paths this can find.
    • line

      public com.github.tommyettinger.ds.ObjectDeque<com.github.yellowstonegames.grid.Coord> line(int startX, int startY, int endX, int endY)
    • line

      public com.github.tommyettinger.ds.ObjectDeque<com.github.yellowstonegames.grid.Coord> line(com.github.yellowstonegames.grid.Coord start, com.github.yellowstonegames.grid.Coord end)
    • getWidth

      public int getWidth()
    • getHeight

      public int getHeight()
    • getRng

      public com.github.tommyettinger.random.EnhancedRandom getRng()
    • setRng

      public void setRng(com.github.tommyettinger.random.EnhancedRandom rng)
    • getLastPath

      public com.github.tommyettinger.ds.ObjectDeque<com.github.yellowstonegames.grid.Coord> getLastPath()
      Gets the last path this found, which may be empty. This returns the same reference to any path this produces, and the path is cleared when a new twisted line is requested. You probably want to copy the contents of this path into another list if you want to keep its contents.
      Returns:
      the most recent path of Coord, as an ObjectDeque, this found.