This repository has been archived by the owner on May 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp_vue_text.adb
133 lines (118 loc) · 3.46 KB
/
p_vue_text.adb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
with text_io, p_combinaisons;
use text_io, p_combinaisons, p_combinaisons.p_int_io;
package body p_vue_text is
procedure afficheLigne(carAngle,carLigne: in character) is
-- {} => {Une nouvelle ligne de la grille est affichée}
begin
put(' ');
for i in 1..4 loop
put(carAngle);
for i in 1..taille loop
put(carLigne);
end loop;
end loop;
put(carAngle);
new_line;
end afficheLigne;
procedure afficheValeur(V : in TV_Gaudi; ind : in integer) is
-- {} => {La valeur à l'indice ind a été affichée avec sa bordure gauche}
nbchar : integer := 0;
begin
put(COLONNE);
if ind not in V'range then
for i in 1..TAILLE loop
put(' ');
end loop;
else
for i in 1..TAILLE/2 loop
put(' ');
nbchar := nbchar + 1;
end loop;
put(V(ind).valeur, 1);
nbchar := nbchar + (if V(ind).valeur >= 10 then 2 else 1);
while nbchar < TAILLE loop
put(' ');
nbchar := nbchar + 1;
end loop;
end if;
end afficheValeur;
procedure afficheGrille(V : TV_Gaudi; S: String) is
-- {V'length = 16} => {La grille est affichée dans la console}
function valeurCorrecte(i,j: integer) return boolean is
currCase : string(1..2);
ind : integer := 1;
begin
if S'length = 0 then return true; end if;
case j is
when 1 => currCase(1) := 'A';
when 2 => currCase(1) := 'B';
when 3 => currCase(1) := 'C';
when 4 => currCase(1) := 'D';
when others => null;
end case;
currCase(2) := Integer'image(i)(2);
while ind <= S'length/2 and then S(ind*2-1..ind*2) /= currCase loop
ind := ind + 1;
end loop;
return ind <= S'length / 2;
end valeurCorrecte;
begin
put(' ');
for c in character range 'A'..'D' loop
for i in 1..3 loop
put(' ');
end loop;
put(c);
for i in 1..2 loop
put(' ');
end loop;
end loop;
new_line;
for i in 1..4 loop
afficheLigne(ANGLE, LIGNE);
afficheLigne(COLONNE, ' '); afficheLigne(COLONNE, ' ');
put(i, 1);
for j in 0..3 loop -- Affichage ligne avec valeurs
if valeurCorrecte(i,j+1) then
afficheValeur(V, j * 4 + i);
else
afficheValeur(V, V'first-1);
end if;
end loop;
put(COLONNE); new_line;
afficheLigne(COLONNE, ' '); afficheLigne(COLONNE, ' ');
end loop;
afficheLigne(ANGLE, LIGNE);
end afficheGrille;
procedure afficheSolution (nb : in integer; fsol : in out text_io.file_type) is
--{fsol ouvert } => {Les solution de fsol à nb elements sont affichées}
Nbchar,nbsol : integer;
tmp : string(1..15);
Categorie : boolean := true;
i : integer := 0;
begin
reset(fsol, IN_FILE);
nbsol := (nbCombi(fsol,nb));
put(" * "); put(nbsol,1); put(" solutions en" & integer'image(nb)& " cases");
new_line;
put("--------------------------");
new_line;
skip_line(fsol);
while not end_of_file(fsol) and Categorie loop
get_line(fsol,tmp,Nbchar);
if tmp(1) in T_col'range then
i := i + 1;
put("solution" & integer'image(i) & '/' & integer'image(nbsol) & " : ");
for j in 1..Nbchar/2 loop
put(tmp(j*2-1)&tmp(j*2));
if j*2 /= Nbchar then
put(',');
end if;
end loop;
new_line;
else
Categorie := false;
end if;
end loop;
end afficheSolution;
end p_vue_text;