File-By-File
Grid

Grid

A Grid is essentially a two-dimensional array of Node objects, used primarily in path generation. It provides methods to manage and access these nodes, including finding nodes by coordinates and generating a grid structure.

Methods

Grid(int width, int height)

Constructs a new Grid with the specified width and height. Initially, the nodes within the grid are not fully initialized (neighbors are not calculated).

Grid(int width, int height, List<Node> nodes)

Constructs a new Grid with the specified width, height, and an initial list of Node objects. This constructor also populates an internal map for efficient node lookup.

generateGrid(int width, int height)

Static factory method that generates a complete Grid with the specified width and height. This method not only creates the nodes but also calculates their neighbors, making the grid ready for pathfinding algorithms.

getWidth()

Returns the width of the grid.

getHeight()

Returns the height of the grid.

findNode(Coord coord)

Finds and returns the Node at the given Coord (integer X, Y coordinates).

findNode(int x, int y)

Finds and returns the Node at the given integer X and Y coordinates.

getNodes()

Returns the list of all Node objects within the grid.

setNodes(List<Node> nodes)

Sets the list of Node objects for the grid. This method also populates an internal map for faster node lookups.

toString()

Returns a string representation of the grid, where valid nodes are represented by "." and invalid nodes by "#". Each row is also labeled with its row number.