Skip to content
This repository has been archived by the owner on May 17, 2024. It is now read-only.

Commit

Permalink
Show only solution in grid
Browse files Browse the repository at this point in the history
  • Loading branch information
Feelzor committed Jan 23, 2019
1 parent 20c48b1 commit 93d3574
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 23 deletions.
86 changes: 77 additions & 9 deletions gauditext.adb
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,55 @@ procedure gauditext is
return resultat;
end getUserBool;

procedure getAction(resultat: out character; nb: out integer) is
entree: string(1..7);
taille: integer range 1..7;
correct: boolean := false;
begin
nb := 0;
while not correct loop
put_line("Que voulez-vous faire ?");
put_line(" + : Solution suivante");
put_line(" - : Solution précédente");
put_line(" Entrez un nombre pour aller à la solution correspondante");
put_line(" q : Quitter");
get_line(entree, taille);
if taille = 7 then skip_line; end if;
if To_Lower(entree(1..taille)) in "+" | "suiv" | "suivant" | "next" then
resultat := '+';
correct := true;
elsif To_Lower(entree(1..taille)) in "-" | "prec" | "pred" | "précédent" | "precedent" then
resultat := '-';
correct := true;
elsif To_Lower(entree(1..taille)) in "q" | "quit" | "quitter" then
resultat := 'q';
correct := true;
else
begin
nb := Integer'value(entree(1..taille));
resultat := 'n';
correct := true;
exception
when others =>
put_line("Cette valeur est incorrecte, réessayez.");
end;
end if;
end loop;
end getAction;

f: p_cases_io.file_type;
V: TV_Gaudi(1..16);
nbelem: integer range 3..7 := 3;
fout, foutcont: text_io.file_type;
fout: text_io.file_type;

continue, contigu : boolean;

nbSol, currSol: integer;
action: character;
newSol: integer;
begin
fichiersInit(V);
open(f, IN_FILE, "CarreGaudi");
open(fout, IN_FILE, "fout.txt");
open(foutcont, IN_FILE,"foutcont.txt");

loop
loop
begin
Expand All @@ -53,20 +90,51 @@ begin
put("Voulez-vous n'afficher que les solutions contigües ? (o/n) ");
contigu := getUserBool;

afficheGrille(V);
if contigu then
afficheSolution(nbelem, foutcont);
open(fout, IN_FILE, "foutcont.txt");
else
afficheSolution(nbelem, fout);
open(fout, IN_FILE, "fout.txt");
end if;

afficheGrille(V, "");
nbSol := nbCombi(fout, nbelem);
reset(fout, IN_FILE);
currSol := 1;

loop
put("Solution "); put(currSol, 1); put("/"); put(nbSol, 1); new_line;
afficheGrille(V, combi(fout, nbelem, currSol));
reset(fout, IN_FILE);

-- Récupération de l'action
getAction(action, newSol);
case action is
when '+' =>
currSol := currSol + 1;
if currSol > nbSol then currSol := nbSol;
end if;
when '-' =>
currSol := currSol - 1;
if currSol < 1 then currSol := 1;
end if;
when 'n' =>
currSol := newSol;
if currSol > nbSol then currSol := nbSol;
elsif currSol < 1 then currSol := 1;
end if;
when others => null;
end case;
exit when action = 'q';
end loop;

afficheSolution(nbelem, fout);

new_line;
put("Voulez-vous continuer ? (o/n) ");
continue := getUserBool;
close(fout);
exit when not continue;
end loop;

close(foutcont);
close(fout);
close(f);
end gauditext;
2 changes: 1 addition & 1 deletion p_vue_graph.adb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use p_fenbase, Forms, p_combinaisons, Ada.Strings, Ada.Strings.Fixed, text_io,

package body p_vue_graph is



function GetElement (
Pliste : TA_Element;
Expand Down
53 changes: 41 additions & 12 deletions p_vue_text.adb
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,47 @@ package body p_vue_text is
nbchar : integer := 0;
begin
put(COLONNE);
for i in 1..TAILLE/2 loop
put(' ');
nbchar := nbchar + 1;
end loop;
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);
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;
while nbchar < TAILLE loop
put(' ');
nbchar := nbchar + 1;
end loop;
end if;
end afficheValeur;

procedure afficheGrille(V : TV_Gaudi) is
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
Expand All @@ -57,7 +82,11 @@ package body p_vue_text is

put(i, 1);
for j in 0..3 loop -- Affichage ligne avec valeurs
afficheValeur(V, j * 4 + i);
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;

Expand Down
2 changes: 1 addition & 1 deletion p_vue_text.ads
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ package p_vue_text is
procedure afficheValeur(V : in TV_Gaudi; ind : in integer);
-- {} => {La valeur à l'indice ind a été affichée avec sa bordure gauche}

procedure afficheGrille(V : TV_Gaudi);
procedure afficheGrille(V : TV_Gaudi; S: String);
-- {V'length = 16} => {La grille est affichée dans la console}

procedure afficheSolution(nb : in integer; fsol : in out text_io.file_type);
Expand Down

0 comments on commit 93d3574

Please sign in to comment.