with KakoRobot, Gada.Text_IO ;
procedure Mission4a is
package K renames KakoRobot ;
package Txt renames Gada.Text_IO ;
function Distance (Num : Integer) return Float is
Sum2 : Integer ;
begin
Sum2 :=
(K.Loc_Robot(Num).X - K.Loc_Cible.X)**2 +
(K.Loc_Robot(Num).Y - K.Loc_Cible.Y)**2 ;
return K.SQRT(Float(Sum2)) ;
end Distance ;
procedure Tester_Distance is
begin
for I in 1..K.Nombre_Robots loop
Txt.Put_Line ("Distance du robot " & Integer'Image(I) &
" à la cible : " & Float'Image(Distance(I))) ;
end loop ;
end Tester_Distance ;
function Tous_Arrives return Boolean is
Tous_Ok : Boolean := True ;
begin
for I in 1..K.Nombre_Robots loop
if K.Etat(I) /= 2 then Tous_OK := false ;
end if ;
end loop ;
return Tous_OK ;
end Tous_Arrives ;
function Plus_Loin return Integer is
Dist_Max : Float := 0.0 ;
Num_Max : Integer := 1 ;
begin
for I in 1..K.Nombre_Robots loop
if Distance(I) > Dist_Max and K.Etat(I) /= 2 then
Num_Max := I ;
Dist_Max := Distance(I) ;
end if ;
end loop ;
return Num_Max ;
end Plus_Loin ;
procedure Bouger_Vers_Cible (Num : Integer) is
begin
if K.Loc_Robot(Num).Y = 0 then
if K.Loc_Robot(Num).X < K.Loc_Cible.X then
K.Deplacer(Num, K.Est) ;
else
K.Deplacer(Num, K.Ouest) ;
end if ;
else
K.Deplacer(Num, K.Nord) ;
end if ;
end Bouger_Vers_Cible ;
begin
Tester_Distance ;
while not Tous_Arrives loop
Bouger_Vers_Cible(Plus_Loin) ;
end loop ;
end Mission4a ;