Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package body p_twistb is
- procedure InitGrille(G : out TV_Grille) is
- begin
- for j in T_lig'range loop
- for i in T_Col'range loop
- G(j,i).piece := T_NumPiece(T_NumPiece'first);
- G(j,i).fiche := T_Coul(T_Coul'first);
- end loop;
- end loop;
- end InitGrille;
- procedure InitJeu(f : in out text_io.file_type; numdefi : in positive; G : out TV_Grille) is
- c1,skip: character;
- c2: integer;
- coul : T_Coul;
- numligne : integer := 1;
- begin
- reset(f,in_file);
- InitGrille(G);
- while not end_of_file(f) and then numligne /= numdefi loop
- skip_line(f);
- numligne := numligne + 1;
- end loop;
- loop
- p_coul_io.get(f,coul);
- get(f,skip);
- get(f,c1);
- get(f,c2);
- G(c2,c1).fiche := coul;
- exit when end_of_line(f);
- get(f,skip);
- end loop;
- end InitJeu;
- procedure CreeVectPiece (f : in out p_piece_io.file_type; VP : out TV_Piece) is
- piece : TR_Piece;
- i : integer := 1;
- begin
- while not end_of_file(f) and then i <= 8 loop
- read(f,piece);
- VP(i) := piece;
- i := i + 1;
- end loop;
- end CreeVectPiece;
- procedure init_TV_Mat(Col, Lig : out TV_Mat_pos) is
- begin
- for i in TV_Mat_pos'range loop
- Col(i):=false;
- Lig(i):=false;
- end loop;
- end init_TV_Mat;
- procedure dimensions(M : in TV_Matrice; nblig, nbcol : out positive) is
- colonne, ligne : TV_Mat_pos;
- firstc, firstl : boolean;
- begin
- firstc := false;
- firstl := false;
- nblig := 1;
- nbcol := 1;
- init_TV_Mat(colonne,ligne);
- for j in 1..4 loop
- for i in 1..4 loop
- if M(j,i) /= vide then
- colonne(i):=true;
- ligne(j):=true;
- end if;
- end loop;
- end loop;
- for i in TV_Mat_pos'range loop
- if colonne(i) then
- if firstc then
- nbcol := nbcol + 1;
- else
- firstc := true;
- end if;
- end if;
- if ligne(i) then
- if firstl then
- nblig := nblig +1;
- else
- firstl := true;
- end if;
- end if;
- end loop;
- p_esiut.A_la_ligne;
- for i in 1..4 loop
- if colonne(i) then p_esiut.ecrire("1"); else p_esiut.ecrire("0"); end if;
- end loop;
- p_esiut.A_la_ligne;
- for i in 1..4 loop
- if ligne(i) then p_esiut.ecrire("1"); else p_esiut.ecrire("0"); end if;
- end loop;
- p_esiut.A_la_ligne;
- end dimensions;
- procedure init_mat(M : out TV_Matrice) is
- begin
- for j in 1..4 loop
- for i in 1..4 loop
- M(j,i):=vide;
- end loop;
- end loop;
- end init_mat;
- procedure Trans_H(VP : in out TV_Piece; nump : in T_NumPiece) is
- mat : TV_Matrice;
- lig,col : positive;
- begin
- init_mat(mat);
- dimensions(VP(nump).mat,lig,col);
- for j in 1..lig loop
- for i in 1..col loop
- mat(j,i):=VP(nump).mat(j,(col+1)-i);
- end loop;
- end loop;
- VP(nump).mat := mat;
- end Trans_H;
- procedure Rot_D(VP : in out TV_Piece; nump : in T_NumPiece) is
- mat : TV_Matrice;
- lig,col : positive;
- res : natural;
- begin
- init_mat(mat);
- dimensions(VP(nump).mat,lig,col);
- for j in 1..lig loop
- for i in 1..col loop
- res := lig - j;
- mat(i,res+1):=VP(nump).mat(j,i);
- end loop;
- end loop;
- VP(nump).mat := mat;
- end Rot_D;
- procedure Rot_G(VP : in out TV_Piece; nump : in T_NumPiece) is
- begin
- for i in 1..3 loop
- Rot_D(VP,nump);
- end loop;
- end Rot_G;
- procedure Trans_V(VP : in out TV_Piece; nump : in T_NumPiece) is
- begin
- Rot_D(VP,nump);
- Trans_H(VP,nump);
- Rot_G(VP,nump);
- end Trans_V;
- procedure AppliquerTransfo(VP : in out TV_Piece; nump : in T_NumPiece; tr : in T_Transfo) is
- begin
- if tr = rotd then
- Rot_D(VP,nump);
- elsif tr = rotg then
- Rot_G(VP,nump);
- elsif tr = reth then
- Trans_H(VP,nump);
- elsif tr = retv then
- Trans_V(VP,nump);
- end if;
- end AppliquerTransfo;
- function Addchar(char : in T_Col; int : in integer) return character is
- begin
- return character'val(character'pos(char)+int);
- end Addchar;
- procedure Placer (G : in out TV_Grille; VP : in out TV_Piece; nump : in T_NumPiece;
- lg : in T_Lig; col : in T_Col; possible : out boolean) is
- colonne, ligne : TV_Mat_pos;
- nope : boolean := false;
- begin
- possible:=true;
- init_TV_Mat(colonne,ligne);
- for j in 1..4 loop
- for i in 1..4 loop
- if VP(nump).mat(j,i)/=vide and not nope then
- if Addchar(col,i-1) <= 'H' and lg + j-1 <= T_Lig(T_Lig'last) then
- if G(lg + j-1,Addchar(col,i-1)).fiche = noir then
- colonne(j):=true;
- ligne(i):=true;
- elsif G(lg + j-1,Addchar(col,i-1)).fiche = VP(nump).coul
- and VP(nump).mat(j,i)=troue and
- G(lg + j-1,Addchar(col,i-1)).piece = 0 then
- colonne(j):=true;
- ligne(i):=true;
- elsif G(lg + j-1,Addchar(col,i-1)).fiche = noir
- and G(lg + j-1,Addchar(col,i-1)).piece = 0 then
- colonne(j):=true;
- ligne(i):=true;
- else
- colonne(j):=false;
- ligne(i):=false;
- end if;
- else
- colonne(j):=false;
- ligne(i):=false;
- nope := true;
- end if;
- elsif not nope then
- colonne(j):=true;
- ligne(i):=true;
- end if;
- end loop;
- end loop;
- for i in 1..4 loop --estce possible ?
- if not colonne(i) or not ligne(i)then
- possible := false;
- end if;
- end loop;
- if possible then
- for j in 1..4 loop
- for i in 1..4 loop
- if VP(nump).mat(j,i)/=vide then
- G(lg + j-1,Addchar(col,i-1)).piece:=nump;
- end if;
- end loop;
- end loop;
- VP(nump).place := true;
- end if;
- end Placer;
- procedure Retirer(G : in out TV_Grille; VP : in out TV_Piece; nump : in T_NumPiece) is
- begin
- if VP(nump).place = true then
- for j in T_Lig'range loop
- for i in T_Col'range loop
- if G(j,i).piece = nump then
- G(j,i).piece:= 0;
- end if;
- end loop;
- end loop;
- VP(nump).place := false;
- end if;
- end Retirer;
- function PartieGagne (VP : in TV_Piece) return boolean is
- i : integer := 1;
- begin
- while i <= 8 and then VP(i).place loop
- i := i + 1;
- end loop;
- return i = 8;
- end PartieGagne;
- procedure Saisir_Piece(nump : out T_NumPiece) is
- begin
- loop
- begin
- p_esiut.A_la_ligne;
- p_esiut.ecrire("Saisir numéro de la piece :");p_esiut.lire(nump);
- if nump > 0 then
- exit;
- else
- p_esiut.ecrire_ligne("Valeur incorrecte");
- end if;
- exception
- when constraint_error => p_esiut.ecrire_ligne("Valeur incorrecte");
- end;
- end loop;
- end Saisir_Piece;
- end p_twistb;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement