Package model

Class MazeGraph

java.lang.Object
model.MazeGraph

public class MazeGraph extends Object
A graph representing a game's maze, connecting the "path" tiles of a tile grid.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static 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

    Fields
    Modifier and Type
    Field
    Description
    private final int
    The height of the tile grid defining this maze.
    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
    Constructor
    Description
    Construct the maze graph corresponding to the tile grid `map`.
  • Method Summary

    Modifier and Type
    Method
    Description
    closestTo(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.
    Return the full collection of vertices in this graph.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • vertices

      private final HashMap<MazeGraph.IPair,MazeGraph.MazeVertex> vertices
      The vertices of this graph, each associated with the location of its corresponding path tile in the tile grid.
    • width

      private final int width
      The width of the tile grid defining this maze.
    • height

      private final int height
      The height of the tile grid defining this maze.
  • Constructor Details

    • MazeGraph

      public MazeGraph(GameMap map)
      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

      public MazeGraph.MazeVertex closestTo(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). 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

      public Iterable<MazeGraph.MazeVertex> vertices()
      Return the full collection of vertices in this graph.
    • pacMannStartingEdge

      public MazeGraph.MazeEdge pacMannStartingEdge()
      Return the first edge that PacMann will traverse at the start of a game.
    • ghostStartingEdge

      public MazeGraph.MazeEdge ghostStartingEdge()
      Return the first edge that a ghost will traverse upon transitioning from the WAIT to the CHASE state.