Package model
Class MazeGraph
java.lang.Object
model.MazeGraph
A graph representing a game's maze, connecting the "path" tiles of a tile grid.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
The direction of a (directed) edge in this graph.static final record
An ordered pair of integers.static final record
Represents a directed edge from `src` to `dst` with weight `weight`, which points in direction `direction` on the tile grid.static class
A vertex in our graph, corresponding to a path tile in the tile grid. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final int
The height of the tile grid defining this maze.private final HashMap
<MazeGraph.IPair, MazeGraph.MazeVertex> The vertices of this graph, each associated with the location of its corresponding path tile in the tile grid.private final int
The width of the tile grid defining this maze. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionclosestTo
(int i, int j) Return a vertex that is close to the tile location `(i, j)` (where `i` is column number and `j` is row number).(package private) static double
edgeWeight
(double srcElev, double dstElev) Return the weight that an edge should have if it connects a vertex with elevation `srcElev` to a vertex with elevation `dstElev`.Return the first edge that a ghost will traverse upon transitioning from the WAIT to the CHASE state.Return the first edge that PacMann will traverse at the start of a game.vertices()
Return the full collection of vertices in this graph.
-
Field Details
-
vertices
The vertices of this graph, each associated with the location of its corresponding path tile in the tile grid. -
width
private final int widthThe width of the tile grid defining this maze. -
height
private final int heightThe height of the tile grid defining this maze.
-
-
Constructor Details
-
MazeGraph
Construct the maze graph corresponding to the tile grid `map`. Requires `map.types()[2][2]` to be a `TileType.PATH` and that all `PATH` tiles belong to the same orthogonally connected component. Requires `map.types()` and `map.elevations()` have the same shape, with the first index corresponding to columns and the second index corresponding to rows.
-
-
Method Details
-
edgeWeight
static double edgeWeight(double srcElev, double dstElev) Return the weight that an edge should have if it connects a vertex with elevation `srcElev` to a vertex with elevation `dstElev`. -
closestTo
Return a vertex that is close to the tile location `(i, j)` (where `i` is column number and `j` is row number). Ghosts are expected to use this to ensure that they are targeting a reachable path tile. (Most of the time, this will be a closest such vertex if "tunnels" are ignored.) -
vertices
Return the full collection of vertices in this graph. -
pacMannStartingEdge
Return the first edge that PacMann will traverse at the start of a game. -
ghostStartingEdge
Return the first edge that a ghost will traverse upon transitioning from the WAIT to the CHASE state.
-