Implement strategy pattern

This commit is contained in:
Stone_Red
2023-05-31 09:24:32 +02:00
parent 1b1b568bb0
commit 1775929ced
10 changed files with 80 additions and 43 deletions
+8 -8
View File
@@ -3,17 +3,17 @@ using Maze.Utlis;
namespace Maze.Solvers;
internal class BreadthFirstSearchMazeSolver : IMazeSolver<BfsNode>
internal class BreadthFirstSearchMazeSolver : IMazeSolver
{
public List<BfsNode> Solve(BfsNode node, BfsNode[,] maze, GraphicsMode graphicsMode = GraphicsMode.None)
public List<MazeNode> Solve(MazeNode node, MazeNode[,] maze, GraphicsMode graphicsMode = GraphicsMode.None)
{
if (!node.Start)
{
throw new MazeException("Node is not a start node.");
}
BfsNode currentNode;
Queue<BfsNode> queue = new Queue<BfsNode>();
MazeNode currentNode;
Queue<MazeNode> queue = new Queue<MazeNode>();
queue.Enqueue(node);
@@ -28,8 +28,8 @@ internal class BreadthFirstSearchMazeSolver : IMazeSolver<BfsNode>
if (currentNode.Goal)
{
List<BfsNode> path = new List<BfsNode>();
BfsNode? pathNode = currentNode;
List<MazeNode> path = new List<MazeNode>();
MazeNode? pathNode = currentNode;
while (pathNode is not null && !pathNode.Start)
{
@@ -41,7 +41,7 @@ internal class BreadthFirstSearchMazeSolver : IMazeSolver<BfsNode>
return path;
}
foreach (BfsNode child in currentNode.Neighbors.Where(n => !n.Visited && !n.Wall))
foreach (MazeNode child in currentNode.Neighbors.Where(n => !n.Visited && !n.Wall))
{
child.Parent = currentNode;
child.Visited = true;
@@ -65,6 +65,6 @@ internal class BreadthFirstSearchMazeSolver : IMazeSolver<BfsNode>
}
}
return new List<BfsNode>();
return new List<MazeNode>();
}
}