// online, the reference is not stored since we call only once the same maze with the same algorithm // this method works like the Visitor design pattern but dedicated for only IMazeSolvingAlgorithms public void Solve(IMazeSolvingAlgorithm mazeSolvingAlgorithm) { if (mazeSolvingAlgorithm != null) { mazeSolvingAlgorithm.Solve(this); } }
// it's a kind of template method because the steps of how I want to run the mazeapp are fixed private static void RunSolvingMazeProcess(Maze maze, IMazeSolvingAlgorithm algorithm, IMyWriter writer) { // mazewriter object is used to store/display the maze maze.Writer = writer; // write/print-out the plain maze without a solution maze.Write(false); // Solve the maze by using the injected algorithm maze.Solve(algorithm); // write/print-out the matrix with its last solution maze.Write(true); }
private void algorithmsComboBox_SelectedIndexChanged(object sender, EventArgs e) { switch (solvingAlgorithmsComboBox.SelectedIndex) { case 0: solving = new DepthSolvingAlgorithm(); break; case 1: solving = new BreadthSolvingAlgorithm(); break; case 2: solving = new WallRunnerSolvingAlgorithm(); break; case 3: solving = new AStarSolvingAlgorithm(); break; } }
public Game(IMazeRunnerService mazeRunnerService, IMazeSolvingAlgorithm mazeSolvingAlgorithm = null) { this.MazeRunnerService = mazeRunnerService; this.MazeSolvingAlgorithm = mazeSolvingAlgorithm; }