with P_Taquin;
with Text_Io, Ada.Integer_Text_io;use Text_Io, Ada.Integer_Text_io;
with Ada.Numerics.Discrete_Random;
package body P_Mon_Appli_Taquin is
function System(Clear : String) return Integer;
pragma import(C, System, "system" );
Clear_Return : Integer;
subtype T_Image is Natural range 0..(N*M)-1;
package P_Image_Io is new Text_Io.Integer_Io(T_Image);
package P_Mon_Taquin is new P_Taquin(N,M,T_Image,
P_Image_Io.Put);
use P_Mon_Taquin;
Taquin_Init, Taquin_Melange, Taquin_Ordonne : T_Taquin;
procedure Initialiser is
type T_Tab_Image is array (natural range 0..(N*M)-1) of T_Image;
Tab_Image : T_Tab_Image := (others => 0);
procedure Permute(Tab : in out T_Tab_Image;I,J : T_Borne_2) is
Tampon : T_Image := Tab(I);
begin
Tab(I) := Tab(J);
Tab(J) := Tampon;
end Permute;
Package P_T_Borne_2_random is new Ada.Numerics.Discrete_Random(T_Borne_2);
T_Borne_2_Gen : P_T_Borne_2_Random.Generator;
use P_T_Borne_2_Random;
begin
for I in Tab_Image'Range loop
Tab_Image(I) := I;
end loop;
if not S then
for I in 1..Tab_Image'Length/2 loop
Permute(Tab_Image,
Random(T_Borne_2_Gen),
Random(T_Borne_2_Gen));
end loop;
end if;
Put("Taquin initialise" );
New_Line(2);
for I in Tab_Image'Range loop
Init_Suivant(Taquin_Init,Tab_image(I));
Clear_Return := System("clear" & Ascii.Nul);
Afficher(Taquin_Init);
end loop;
New_Line(22-Count(N));
end Initialiser;
procedure Melanger is
Char : Character;
task Get_Char is
end Get_Char;
task body Get_Char is
begin
loop
Get_Immediate(Char);
delay 0.1;
end loop;
end Get_Char;
begin
Taquin_Melange := Taquin_Init;
while Char /= 'q' loop
Clear_Return := System("clear" & Ascii.Nul);
Put("Taquin initialise" );
New_Line(2);
Afficher(Taquin_Init);
Put("Taquin melange" );
New_Line(2);
Afficher(Taquin_melange);
Delay 0.1;
Melange_Deplacer_Un_Jeton(Taquin_Melange);
end loop;
end Melanger;
procedure Ordonner is
begin
Taquin_Ordonne := Taquin_Melange;
while not sont_Egales(Taquin_Melange,
Taquin_Ordonne) loop
Clear_Return := System("clear" & Ascii.Nul);
Put("Taquin initialise" );
New_Line(2);
Afficher(Taquin_Init);
Put("Taquin melange" );
New_Line(2);
Afficher(Taquin_melange);
Put("Taquin ordonne" );
New_Line(2);
Afficher(Taquin_ordonne);
Trie_Deplacer_Un_Jeton(Taquin_Melange,Taquin_Ordonne);
end loop;
Put("Taquin initialise" );
New_Line(2);
Afficher(Taquin_Init);
Put("Taquin melange" );
New_Line(2);
Afficher(Taquin_melange);
Put("Taquin ordonne" );
New_Line(2);
Afficher(Taquin_ordonne);
end Ordonner;
end P_Mon_Appli_Taquin;