/// <summary> /// Returns an enumerator that marks the maze as checked from given walker cell until a junction is met /// </summary> /// <param name="walker"></param> /// <param name="service"></param> /// <returns></returns> private IEnumerator CheckUntilJunctionRoutine(MazeCell walker, MazeSolvingService service) { walker.MarkAsChecked(); yield return(null); //loop until a junction is found and is borken out of the loop while (true) { //get the next cell in the current path List <MazeCell> cellsNextInPath = service.GetNextCellsInPath(walker); if (cellsNextInPath.Count == 1) { //save it is a junction MazeCell nextCellInPath = cellsNextInPath[0]; bool isJunction = nextCellInPath.IsJunction; //mark the walls as checked walker.MarkWallAsChecked(nextCellInPath); nextCellInPath.MarkWallAsChecked(walker); if (isJunction) { //if the cell was a junction, break out of the loop break; } else { //if the cell wasn't a junction, mark the cell as checked and continue from it nextCellInPath.MarkAsChecked(); walker = nextCellInPath; } } else { throw new System.InvalidOperationException($"Filling in until junktion failed :: there should be one next cell in {walker}'s path each time"); } yield return(null); } }