Maze generation: Difference between revisions

→‎{{header|Ada}}: Simplified way of detecting unvisited neighbours.
(Undo revision 305527 by Spie812 (talk) undid massive changes to the whole Rosetta Code task entries.)
(→‎{{header|Ada}}: Simplified way of detecting unvisited neighbours.)
Line 65:
Row : Height_Type;
Column : Width_Type);
 
function Has_Unvisited_Neighbours
(Maze : Maze_Grid;
Row : Height_Type;
Column : Width_Type)
return Boolean;
 
procedure Move
Line 101 ⟶ 95:
Next_Direction : Directions;
Valid_Direction : Boolean;
Tested_Wall : array (Directions) of Boolean := (others => False);
returnAll_Tested : Boolean;
begin
-- mark as visited
Maze (Row, Column).Visited := True;
-- continue as long as there are unvisited neighbours left
end loop;
while Has_Unvisited_Neighbours (Maze, Row, Column) loop
All_Tested return:= True;
for DirD in Directions loop
All_Tested := All_Tested and Tested_Wall (D);
end ifloop;
-- all directions are either visited from here,
-- or previously visited, or invalid.
exit when All_Tested;
-- use random direction
Next_Direction := Random_Direction.Random (Dir_Generator);
Line 121 ⟶ 124:
end if;
end if;
Tested_Wall (Next_Direction) := True;
end loop;
end Depth_First_Algorithm;
 
function Has_Unvisited_Neighbours
(Maze : Maze_Grid;
Row : Height_Type;
Column : Width_Type)
return Boolean
is
Neighbour_Row : Height_Type;
Neighbour_Column : Width_Type;
Is_Valid : Boolean;
begin
for Dir in Directions loop
Neighbour_Row := Row;
Neighbour_Column := Column;
Move
(Row => Neighbour_Row,
Column => Neighbour_Column,
Direction => Dir,
Valid_Move => Is_Valid);
if Is_Valid
and then not Maze (Neighbour_Row, Neighbour_Column).Visited
then
return True;
end if;
end loop;
return False;
end Has_Unvisited_Neighbours;
 
procedure Initialize (Maze : in out Maze_Grid) is
Anonymous user