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,
diagramWidthOffset: float,
diagramHeight: int,
diagramHeightOffset: float,
diagramNodeRadius: float,
numDiagramRegions: int,
diagramEdgePercentageToProcess: float,
newConnectionAngleMinQuantile: float,
lonelyConnectionMinLengthQuantile: float,
connectionLengthVertexPadding: float,
connectionLengthNodeBuffer: float,
destinationDistanceUpperQuantile: float,
maxFuelCost: float
)
in TrackGenerator.
Track
@dataclass(frozen=True)
class Track:
nodes: dict[uuid4, Point]
edges: dict[uuid4, EdgeVertexInfo]
startNodeId: uuid4
destinationNodeId: uuid4
nodeInfo: dict[uuid4, NodeInfo]
edgeInfo: dict[uuid4, EdgeInfo]
describes a set of edges, each a connection between two Points. nodes are the Points.
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.
nodeInfo maps nodes to further information about them
@dataclass(frozen=True)
class NodeInfo:
distanceToDestination: float
numNeighbors: int
that the game logic needs.
edgeInfo does the same for edges.
@dataclass(frozen=True)
class EdgeInfo:
fuelCost: float
edgeLengthProportion: float
edgeStopInfo: tuple[StopInfo]
edgeStopsFromVertex0: tuple[uuid4]
edgeStopsFromVertex1: tuple[uuid4]
edgeStopInfo describes what " stops " are on the edge:
@dataclass(frozen=True)
class StopInfo:
stopPoint: Point
stopId: uuid4
fuelAvailable: float
EdgeInfo.fuelCost and StopInfo.fuelAvailable together make gameplay mechanics. When a Walker travels over an edge, its fuel is depleted by fuelCost - but that depletion can be offset by the sum of the fuelAvailable values in EdgeInfo.edgeStopInfo.
RampantTrackGeneration works by..
.. doing the following:
- generating #
numDiagramRegionsVoronoi diagram sites (0 <= x <= diagramWidth,0 <= y <= diagramHeight) - generating the Voronoi diagram
- offsetting the diagram with regards to frontend display constraints (
diagramWidthOffset,diagramHeightOffset,diagramNodeRadius) - using
newConnectionAngleMinQuantileto calculateinitialDiagramMinAcceptableAngle, 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
Trackedges that make awkwardly small angles with other edges
- rejecting any reconnection that does not satisfy that constraint minimizes the probability of getting
- 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
- adjusting all nodes too close to other edges or nodes (length between <
diagramNodeRadius * 2)- Edges: Extending the segments to which the node is connected to intersect with the too-close edge (and deleting any intersection edges where length between <
minEdgeAdjust) - Nodes: Taking each (node, otherNode) pair where one is too close to the other, picking the one with less neighbors, and reconnecting those neighbors to the other node to create longer edges.
- Edges: Extending the segments to which the node is connected to intersect with the too-close edge (and deleting any intersection edges where length between <
- adjusting node positions so that they fall within frontend display constraints
- determining the remaining edges' fuel costs
- the longest edge's cost is
maxFuelCost- the other edges' costs are scaled in proportion to that
- the longest edge's cost is
- placing
Stopson 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
Stopsorganically on an edge, we place them at leastconnectionLengthVertexPadding * 100% of the edge length away from either of points - and make the distance between eachStopat leastconnectionLengthNodeBuffer * 100% of the edge length - each
Stop'sStopInfo.fuelAvailableis calculated so that the sum of those values for a given edge's set of Stops is between 50-75% of the edge'sfuelCost
- to avoid the awkwardness of placing on " too small edges ", we only place on edges whose length is greater than
- calculating
Track.startNodeandTrack.destinationNodePoint.distance(<startNode>, <destinationNode>)must be >=destinationDistanceUpperQuantile * 100% of the distances non-startNodes have tostartNode
- calculating
Track.nodeInfo
The resulting enhancement can be seen in the below illustration of Voronoi diagram -> Track:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rampanttrackgeneration-0.0.1.4.0.tar.gz.
File metadata
- Download URL: rampanttrackgeneration-0.0.1.4.0.tar.gz
- Upload date:
- Size: 6.0 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2901a36f4c7f4b5641d49ff1914c42386a34ae20bc05878778fb39d368d51d45
|
|
| MD5 |
1e7e5c7f8c0787b705f8e87c9dd0cc45
|
|
| BLAKE2b-256 |
7501c33a9358b739881134c69392d1b76b93eb3ef2e7513028f790c4a823bd45
|
File details
Details for the file rampanttrackgeneration-0.0.1.4.0-py3-none-any.whl.
File metadata
- Download URL: rampanttrackgeneration-0.0.1.4.0-py3-none-any.whl
- Upload date:
- Size: 21.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4f0912eabbab75342d1be9e7d4ca721d7cbc26c989c1f431ff9d62ea5461ae51
|
|
| MD5 |
3fd0091fcec7174e7eb922ba5ab4bc2b
|
|
| BLAKE2b-256 |
9f10d61337ca5de12d380e961530d0f1ef1ac0318f8e9d5cf8e864b3ebe03bbf
|