Path

interface Path : Comparable<Path> (source)

A path is a list of cells that are connected to each other and walkable entirely. An object always consists of at least one cell.

Since

1.0.0

Inheritors

Types

Link copied to clipboard
object Empty : Path

A path that is empty. This path has no cells and is not finished. Forking this path will always return this path; it is not possible to lengthen this path.

Properties

Link copied to clipboard
abstract val currentCost: Double

The current cost of this path.

Link copied to clipboard
abstract val end: Cell?

The end cell of the path. This may be null if this path only consists of one cell or does not yet have an set end. For example, if this path gets discarded as it is not the most cost-efficient path, there never will be and end cell.

Link copied to clipboard
abstract var finished: Boolean

Whether this path is finished or not. A path is finished if the end cell is reached.

Link copied to clipboard
abstract val start: Cell

The start cell of the path.

Functions

Link copied to clipboard
open operator override fun compareTo(other: Path): Int

Compares this path to the other path. The comparison is based on the currentCost of both paths.

Link copied to clipboard
abstract fun forkTo(cell: Cell, at: Int = -1, cost: CellTravelCostSupplier = CellTravelCostSupplier.None): Path

Forks the path at the given position and returns a new path that starts at the same start as this path and includes this path's last cell before at at the second last index and at the last index, the given cell. If a new cell is added onto this path, it will not appear in the forked path's cell listing.

Link copied to clipboard
abstract fun getCells(): List<Cell>

A list of all cells currently enlisted under this path. This list will always be ordered so that index 0 will be equal to start and all following cells will be connected to its predecessor. The last element will, if there are more than 1 cells, be equal to end. Modifying this list will have no effect.

Link copied to clipboard
abstract fun getLast(): Cell
Link copied to clipboard
abstract fun getLength(): Int

Returns the length of this path, which is the amount of cells enlisted under this path. This will yield the exact same result as getCells().size.

Link copied to clipboard
open operator fun plus(cell: Cell): Path

Pursues this path to the given cell. This will add the given cell to the end of this path without increasing the cost of this path. If the given cell is not a neighbor of the last cell of this path, an exception will be thrown.

Link copied to clipboard
abstract fun pursueTo(cell: Cell)

Pursues this path to the given cell. This will add the given cell to the end of this path without increasing the cost of this path. If the given cell is not a neighbor of the last cell of this path, an exception will be thrown.

Link copied to clipboard
open fun subPath(from: Int): Path

Creates a new sub path that includes all cells from this path starting at from (inclusive) to the last cell (inclusive).

abstract fun subPath(from: Int, to: Int): Path

Creates a new sub path that includes all cells from this path starting at from (inclusive) to to (inclusive).

Link copied to clipboard
open fun subPathUntil(to: Int): Path

Creates a new sub path that includes all cells from this path starting at the first cell (inclusive) to to (inclusive).