Class MazeViewModel

java.lang.Object
mazealgo.viewmodel.MazeViewModel

public class MazeViewModel extends Object
Bridge between MazeModel and the JavaFX View. Holds the full UI-observable state (2D and 3D maze, current solution, player row / column, victory flag, nodes-evaluated counter, visited states, dimension mode, algorithm choice) and exposes commands (generate, move, solve, visualize) that the controller calls in response to user input.

Two dimensions:

  • 2D mode — full gameplay; player navigates with WASD / arrows; Generate / Solution Hint can go through the embedded server when Best-First is selected (preserves the Phase 2 cache demo).
  • 3D mode — visualization only (no player movement); the 3D displayer renders every layer side-by-side. Generate / Solve / Watch run in-process via SearchableMaze3D (the server protocol is 2D only).

Three algorithm choices:

  • ALGO_BEST_FIRST (default) — A*-like with admissible heuristics; returns optimal path.
  • ALGO_BFS — uninformed but optimal in number of edges.
  • ALGO_DFS — finds some path, not the shortest.
  • Property Details

    • mode

      public javafx.beans.property.ObjectProperty<MazeViewModel.Mode> modeProperty
    • maze

      public javafx.beans.property.ObjectProperty<Maze> mazeProperty
    • maze3D

      public javafx.beans.property.ObjectProperty<Maze3D> maze3DProperty
    • solution

      public javafx.beans.property.ObjectProperty<Solution> solutionProperty
    • playerRow

      public javafx.beans.property.IntegerProperty playerRowProperty
    • playerColumn

      public javafx.beans.property.IntegerProperty playerColumnProperty
    • solved

      public javafx.beans.property.BooleanProperty solvedProperty
    • victory

      public javafx.beans.property.ReadOnlyBooleanProperty victoryProperty
    • nodesEvaluated

      public javafx.beans.property.ReadOnlyIntegerProperty nodesEvaluatedProperty
    • visualizing

      public javafx.beans.property.ReadOnlyBooleanProperty visualizingProperty
    • algorithmChoice

      public javafx.beans.property.ObjectProperty<String> algorithmChoiceProperty
  • Field Details

  • Constructor Details

    • MazeViewModel

      public MazeViewModel(MazeModel model)
  • Method Details

    • generate

      public void generate(int rows, int columns)
    • movePlayer

      public void movePlayer(MovementDirection dir)
      Attempts to move the player one cell in the given direction. No-op if the target cell is out of bounds, a wall, or — for diagonals — if both adjacent orthogonal cells around the corner are walls (the same pinhole rule SearchableMaze enforces).

      3D mode is visualization-only; movePlayer is a no-op there.

    • generate3D

      public void generate3D(int depth, int rows, int columns)
    • solveCurrent

      public void solveCurrent()
      Solves synchronously and shows the path. Used by the Solution Hint button.

      In 2D with Best-First, routes through MazeModel.solve(Maze) — which in the running app means a socket roundtrip through the embedded SolveMazeStrategy + SHA-256 cache. Other algorithm choices and all 3D solves run in-process (the server protocol is 2D + Best-First only).

    • visualizeSearchAsync

      public void visualizeSearchAsync()
      Runs the selected algorithm on a daemon thread and feeds each visited state into visitedStates on the JavaFX thread, with an adaptive per-cell delay so the animation always fits a bounded budget regardless of maze size.
    • modeProperty

      public javafx.beans.property.ObjectProperty<MazeViewModel.Mode> modeProperty()
    • mazeProperty

      public javafx.beans.property.ObjectProperty<Maze> mazeProperty()
    • maze3DProperty

      public javafx.beans.property.ObjectProperty<Maze3D> maze3DProperty()
    • solutionProperty

      public javafx.beans.property.ObjectProperty<Solution> solutionProperty()
    • playerRowProperty

      public javafx.beans.property.IntegerProperty playerRowProperty()
    • playerColumnProperty

      public javafx.beans.property.IntegerProperty playerColumnProperty()
    • solvedProperty

      public javafx.beans.property.BooleanProperty solvedProperty()
    • victoryProperty

      public javafx.beans.property.ReadOnlyBooleanProperty victoryProperty()
    • nodesEvaluatedProperty

      public javafx.beans.property.ReadOnlyIntegerProperty nodesEvaluatedProperty()
    • visualizingProperty

      public javafx.beans.property.ReadOnlyBooleanProperty visualizingProperty()
    • getVisitedStates

      public javafx.collections.ObservableSet<AState> getVisitedStates()
    • algorithmChoiceProperty

      public javafx.beans.property.ObjectProperty<String> algorithmChoiceProperty()