connect Grid
Connects all nodes in the grid with their neighbors, using a user-defined function to determine the neighbors.
This function iterates through all nodes in the grid and connects each node to its neighbors as determined by the getNeighbours function. The connections can be either unidirectional or bidirectional, based on the bidirectional parameter.
Example usage:
val grid = Grid(100,100, true)
grid.connectGrid { t ->
grid.getStraightNeighbours(t) + grid.getDiagonalNeighbours(t)
}
grid.bfs(Tile(50,50))
grid.visualizeGrid()Content copied to clipboard
Parameters
bidirectional
If true, connections between nodes are bidirectional. If false, connections are unidirectional. Defaults to false because many connection pattens are inherently unidirectional, and we want to avoid duplicate edges.
get Neighbours
A function that takes a Tile as input and returns a list of neighboring Tile objects to connect to.