Skip to main content

Rampant on the Tracks's Track generation logic, leveraging Voronout and optimized for a web service.

Project description

RampantTrackGeneration is..

.. the Track generation logic for Rampant on the Tracks.

The logic is invoked by calling

@staticmethod
def generateTrack(
    diagramWidth: int,
    diagramHeight: int,
    numDiagramRegions: int,
    diagramEdgePercentageToProcess: float, 
    newConnectionAngleMinQuantile: float, 
    lonelyConnectionMinLengthQuantile: float, 
    connectionLengthVertexPadding: float, 
    connectionLengthNodeBuffer: float,
    destinationDistanceUpperQuantile: float
) -> Track:

in TrackGenerator.

Track

@dataclass(frozen=True)
class Track:
    nodes: dict[uuid4, Point]
    stops: dict[uuid4, tuple[Point]]
    edges: dict[uuid4, EdgeVertexInfo]
    startNode: uuid4
    destinationNode: uuid4,
    nodesDistanceToDestination: dict[uuid4, float]

describes a set of edges, each a connection between two Points. nodes are the Points - stops are intervals on each edge, a gameplay mechanic that'll be elaborated later.

generateTrack derives the Track from a randomly generated Voronoi diagram.

It preserves the organic appeal of the diagram's shape - connectivity of varying lengths between unevenly spaced points - and goes on to enhance that by removing a subset of the smallest edges, replacing them with longer " reconnections ". The reconnections' intersections with other edges are calculated. Intersections that could be removed without newly isolating either of the involved Points are removed - this, and further trimming, increase the variance of the resulting Track's shape and its appeal in both visual and gameplay terms.

It uses Voronout to generate the diagram and networkX to model the diagram's transformation into a Track.

startNode and destinationNode reflect the gameplay - where the Walker the player is responsible for starts from, and where it must end up for the player to win.

nodesDistanceToDestination maps nodes to how far they are from destinationNode, computing information used in determining Walker navigation across nodes.

RampantTrackGeneration works by..

.. doing the following:

  • generating #numDiagramRegions Voronoi diagram sites (0 <= x <= diagramWidth, 0 <= y <= diagramHeight)
  • generating the Voronoi diagram
  • using newConnectionAngleMinQuantile to calculate initialDiagramMinAcceptableAngle, the minimum angle any new reconnection should make with any of the edges at either of its vertices
    • rejecting any reconnection that does not satisfy that constraint minimizes the probability of getting Track edges that make awkwardly small angles with other edges
  • reconnecting diagramEdgePercentageToProcess * 100% of the smallest edges in the diagram
  • removing all intersection edges created by reconnection that can be safely removed
  • removing all " lonely " edges (ones where one vertex is only connected to that edge) with length <= lonelyConnectionMinLengthQuantile * 100% of all edge lengths
  • adjusting all edges with length < minEdgeAdjustLength, either..
    • .. combining them with another collinear edge such that the combination would make the longest edge possible
    • .. deleting the edge, reconnecting all edges involving the vertex with the fewest neighbors to the other vertex
  • placing Stops on the remaining edges
    • to avoid the awkwardness of placing on " too small edges ", we only place on edges whose length is greater than (connectionLengthVertexPadding + connectionLengthNodeBuffer) * 100% of edges
    • to space Stops organically on an edge, we place them at least connectionLengthVertexPadding * 100% of the edge length away from either of points - and make the distance between each Stop at least connectionLengthNodeBuffer * 100% of the edge length
  • calculating Track.startNode and Track.destinationNode
    • Point.distance(<startNode>, <destinationNode>) must be >= destinationDistanceUpperQuantile * 100% of the distances non-startNodes have to startNode
  • calculating Track.nodesDistanceToDestination

The resulting enhancement can be seen in the below illustration of Voronoi diagram -> Track:

GIF visualizing TrackGeneration.generateTrack()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rampanttrackgeneration-0.0.1.2.3.tar.gz (4.1 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rampanttrackgeneration-0.0.1.2.3-py3-none-any.whl (16.7 kB view details)

Uploaded Python 3

File details

Details for the file rampanttrackgeneration-0.0.1.2.3.tar.gz.

File metadata

File hashes

Hashes for rampanttrackgeneration-0.0.1.2.3.tar.gz
Algorithm Hash digest
SHA256 f05e7fc30b8a94d3859c4caddcf887bfc3303f5ebb3547d3b856cba86cc86ff9
MD5 3807da09d182670c57762b1130c74b13
BLAKE2b-256 473be9585a38d5907eb07c55cb4b983e34991646d248e4cb104c7bcca5c5a36e

See more details on using hashes here.

File details

Details for the file rampanttrackgeneration-0.0.1.2.3-py3-none-any.whl.

File metadata

File hashes

Hashes for rampanttrackgeneration-0.0.1.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 8b2dfcc60a2a8c9329df4c60f35005851f91c353fe1ef045a9c76674803f10bc
MD5 bb8decf4c56a5b2c1738f25f44f0bc00
BLAKE2b-256 1e1bdd2c159a9c21bc873abcc01ff2ae52c764e03f64f51f980b1eb48076192e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page