Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- with entrees_sorties; use entrees_sorties;
- procedure reines is
- SIZE : constant Integer := 8;
- NBTENTMAX : constant Integer := 1;
- type Plateau is array (1..SIZE,1..SIZE) of Character;
- grille : Plateau;
- nbReines : Integer := 0;
- nbTent : Integer := 0;
- procedure dessineGrille(grille : in Plateau) is
- begin
- new_line;
- for i in 1..SIZE loop
- for j in 1..SIZE loop
- put(' '&grille(i,j)&' ');
- end loop;
- new_line;
- end loop;
- new_line;
- end dessineGrille;
- function valAbs(n : Integer) return Integer is
- begin
- if(n < 0) then
- return (-1)*n;
- else
- return n;
- end if;
- end valAbs;
- function reinePlacable(grille : Plateau ; i,j : Integer) return Boolean is
- estPlacable : Boolean := TRUE;
- begin
- for x in 1..SIZE loop
- for y in 1..SIZE loop
- if(i=x OR j=y OR (valAbs(i-x)=valAbs(j-y))) then
- if(grille(x, y)='Q') then
- estPlacable := FALSE;
- end if;
- end if;
- end loop;
- end loop;
- return estPlacable;
- end reinePlacable;
- function finissable(grilleBase : Plateau; a,b, nbInit : Integer) return Boolean is
- grilleLoc : Plateau;
- nbReinesLoc : Integer;
- nbTentLoc : Integer := 0;
- begin
- grilleLoc := grilleBase;
- grilleLoc(a,b) := 'Q';
- --dessineGrille(grilleLoc);
- nbReinesLoc := nbInit+1;
- --put(";{"&Integer'Image(nbReinesLoc)&"}-");
- nbTentLoc := 0;
- while(nbReinesLoc < SIZE AND nbTentLoc < NBTENTMAX) loop
- for i in 1..SIZE loop
- for j in 1..SIZE loop
- if(reinePlacable(grilleLoc, i, j)) then
- if(finissable(grilleLoc, i, j, nbReinesLoc)) then
- grilleLoc(i, j) := 'Q';
- nbReinesLoc := nbReinesLoc + 1;
- --new_line;
- --put("_nbReinesLoc :="&Integer'Image(nbReinesLoc)); --'
- --new_line;
- nbTentLoc := 0;
- end if;
- end if;
- end loop;
- end loop;
- nbTentLoc := nbTentLoc + 1;
- end loop;
- --put("-{"&Integer'Image(nbReinesLoc)&"};");
- if(nbReinesLoc = SIZE) then
- --put("YESSSSSS");
- return TRUE;
- else
- --put("[tentF/"&Integer'Image(nbReinesLoc)&"]");
- return FALSE;
- end if;
- end finissable;
- begin
- for i in 1..SIZE loop
- for j in 1..SIZE loop
- grille(i,j) := '.';
- end loop;
- --new_line;
- end loop;
- nbTent := 0;
- while(nbReines < SIZE AND nbTent < NBTENTMAX) loop
- for i in 1..SIZE loop
- for j in 1..SIZE loop
- if(reinePlacable(grille, i, j)) then
- if(finissable(grille, i, j, nbReines)) then
- grille(i, j) := 'Q';
- nbReines := nbReines + 1;
- --new_line;
- --put("nbReines :="&Integer'Image(nbReines)); --'
- --new_line;
- nbTent := 0;
- end if;
- end if;
- end loop;
- end loop;
- nbTent := nbTent + 1;
- end loop;
- dessineGrille(grille);
- new_line;
- put("nbReines ="&Integer'Image(nbReines)&" / nbTent ="&Integer'Image(nbTent));
- new_line;
- end reines;
Advertisement
Add Comment
Please, Sign In to add comment