with EcoRobot ;
procedure Mission1b is
package E renames EcoRobot ;
procedure Walk(Num : Integer ; Direction : Integer) is
X : Integer := E.Abscisse(Num) ;
Y : Integer := E.Ordonnee(Num) ;
begin
if Direction = E.Nord then
Y := Y - 1 ;
elsif Direction = E.Sud then
Y := Y + 1 ;
elsif Direction = E.Est then
X := X + 1 ;
else
X := X - 1 ;
end if ;
E.Step(Num, X, Y) ;
end Walk ;
procedure Test_Walk is
begin
for Num in 1..E.Nombre_Robots loop
Walk(Num, E.Sud) ;
Walk(Num, E.Ouest) ;
Walk(Num, E.Nord) ;
Walk(Num, E.Est) ;
end loop ;
end Test_Walk ;
function Safe_Walk(Num : Integer ; Direction : Integer) return Boolean is
X : Integer := E.Abscisse(Num) ;
Y : Integer := E.Ordonnee(Num) ;
Result : Boolean := False ;
begin
if Direction = E.Nord then
Y := Y - 1 ;
elsif Direction = E.Sud then
Y := Y + 1 ;
elsif Direction = E.Est then
X := X + 1 ;
else
X := X - 1 ;
end if ;
if E.Scan(X,Y) /= E.Billets and E.Scan(X,Y) /= E.Dehors then
E.Step(Num, X, Y) ;
Result := True ;
end if ;
return Result ;
end Safe_Walk ;
procedure Advance(Num : Integer ; Direction :Integer) is
begin
while Safe_Walk(Num, Direction) loop
null ;
end loop ;
end Advance ;
procedure Test_Advance is
begin
Advance(1, E.Est) ;
Advance(1, E.Sud) ;
Advance(2, E.Nord) ;
Advance(2, E.Ouest) ;
Advance(2, E.Sud) ;
end Test_Advance ;
procedure Sauver_Tous_Les_Robots is
begin
for Num in 1..E.Nombre_Robots loop
while not E.Robot_Content(Num) loop
Advance(Num, E.Sud) ;
Advance(Num, E.Est) ;
end loop ;
end loop ;
end Sauver_Tous_Les_Robots ;
begin
Sauver_Tous_Les_Robots ;
end Mission1b ;