Advertisement
Guest User

Untitled

a guest
Jan 24th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.37 KB | None | 0 0
  1. package body p_twistb is
  2.  
  3. procedure InitGrille(G : out TV_Grille) is
  4. begin
  5. for j in T_lig'range loop
  6. for i in T_Col'range loop
  7. G(j,i).piece := T_NumPiece(T_NumPiece'first);
  8. G(j,i).fiche := T_Coul(T_Coul'first);
  9. end loop;
  10. end loop;
  11. end InitGrille;
  12.  
  13. procedure InitJeu(f : in out text_io.file_type; numdefi : in positive; G : out TV_Grille) is
  14. c1,skip: character;
  15. c2: integer;
  16. coul : T_Coul;
  17. numligne : integer := 1;
  18. begin
  19. reset(f,in_file);
  20. InitGrille(G);
  21. while not end_of_file(f) and then numligne /= numdefi loop
  22. skip_line(f);
  23. numligne := numligne + 1;
  24. end loop;
  25. loop
  26. p_coul_io.get(f,coul);
  27. get(f,skip);
  28. get(f,c1);
  29. get(f,c2);
  30. G(c2,c1).fiche := coul;
  31. exit when end_of_line(f);
  32. get(f,skip);
  33. end loop;
  34. end InitJeu;
  35.  
  36. procedure CreeVectPiece (f : in out p_piece_io.file_type; VP : out TV_Piece) is
  37. piece : TR_Piece;
  38. i : integer := 1;
  39. begin
  40. while not end_of_file(f) and then i <= 8 loop
  41. read(f,piece);
  42. VP(i) := piece;
  43. i := i + 1;
  44. end loop;
  45. end CreeVectPiece;
  46.  
  47. procedure init_TV_Mat(Col, Lig : out TV_Mat_pos) is
  48. begin
  49. for i in TV_Mat_pos'range loop
  50. Col(i):=false;
  51. Lig(i):=false;
  52. end loop;
  53. end init_TV_Mat;
  54.  
  55. procedure dimensions(M : in TV_Matrice; nblig, nbcol : out positive) is
  56. colonne, ligne : TV_Mat_pos;
  57. firstc, firstl : boolean;
  58. begin
  59. firstc := false;
  60. firstl := false;
  61. nblig := 1;
  62. nbcol := 1;
  63. init_TV_Mat(colonne,ligne);
  64. for j in 1..4 loop
  65. for i in 1..4 loop
  66. if M(j,i) /= vide then
  67. colonne(i):=true;
  68. ligne(j):=true;
  69. end if;
  70. end loop;
  71. end loop;
  72. for i in TV_Mat_pos'range loop
  73. if colonne(i) then
  74. if firstc then
  75. nbcol := nbcol + 1;
  76. else
  77. firstc := true;
  78. end if;
  79. end if;
  80. if ligne(i) then
  81. if firstl then
  82. nblig := nblig +1;
  83. else
  84. firstl := true;
  85. end if;
  86. end if;
  87. end loop;
  88. p_esiut.A_la_ligne;
  89. for i in 1..4 loop
  90. if colonne(i) then p_esiut.ecrire("1"); else p_esiut.ecrire("0"); end if;
  91. end loop;
  92. p_esiut.A_la_ligne;
  93. for i in 1..4 loop
  94. if ligne(i) then p_esiut.ecrire("1"); else p_esiut.ecrire("0"); end if;
  95. end loop;
  96. p_esiut.A_la_ligne;
  97. end dimensions;
  98.  
  99. procedure init_mat(M : out TV_Matrice) is
  100. begin
  101. for j in 1..4 loop
  102. for i in 1..4 loop
  103. M(j,i):=vide;
  104. end loop;
  105. end loop;
  106. end init_mat;
  107.  
  108. procedure Trans_H(VP : in out TV_Piece; nump : in T_NumPiece) is
  109. mat : TV_Matrice;
  110. lig,col : positive;
  111. begin
  112. init_mat(mat);
  113. dimensions(VP(nump).mat,lig,col);
  114. for j in 1..lig loop
  115. for i in 1..col loop
  116. mat(j,i):=VP(nump).mat(j,(col+1)-i);
  117. end loop;
  118. end loop;
  119. VP(nump).mat := mat;
  120. end Trans_H;
  121.  
  122. procedure Rot_D(VP : in out TV_Piece; nump : in T_NumPiece) is
  123. mat : TV_Matrice;
  124. lig,col : positive;
  125. res : natural;
  126. begin
  127. init_mat(mat);
  128. dimensions(VP(nump).mat,lig,col);
  129. for j in 1..lig loop
  130. for i in 1..col loop
  131. res := lig - j;
  132. mat(i,res+1):=VP(nump).mat(j,i);
  133. end loop;
  134. end loop;
  135. VP(nump).mat := mat;
  136. end Rot_D;
  137.  
  138. procedure Rot_G(VP : in out TV_Piece; nump : in T_NumPiece) is
  139. begin
  140. for i in 1..3 loop
  141. Rot_D(VP,nump);
  142. end loop;
  143. end Rot_G;
  144.  
  145. procedure Trans_V(VP : in out TV_Piece; nump : in T_NumPiece) is
  146. begin
  147. Rot_D(VP,nump);
  148. Trans_H(VP,nump);
  149. Rot_G(VP,nump);
  150. end Trans_V;
  151.  
  152. procedure AppliquerTransfo(VP : in out TV_Piece; nump : in T_NumPiece; tr : in T_Transfo) is
  153. begin
  154. if tr = rotd then
  155. Rot_D(VP,nump);
  156. elsif tr = rotg then
  157. Rot_G(VP,nump);
  158. elsif tr = reth then
  159. Trans_H(VP,nump);
  160. elsif tr = retv then
  161. Trans_V(VP,nump);
  162. end if;
  163. end AppliquerTransfo;
  164.  
  165. function Addchar(char : in T_Col; int : in integer) return character is
  166. begin
  167. return character'val(character'pos(char)+int);
  168. end Addchar;
  169.  
  170.  
  171. procedure Placer (G : in out TV_Grille; VP : in out TV_Piece; nump : in T_NumPiece;
  172. lg : in T_Lig; col : in T_Col; possible : out boolean) is
  173. colonne, ligne : TV_Mat_pos;
  174. nope : boolean := false;
  175. begin
  176. possible:=true;
  177. init_TV_Mat(colonne,ligne);
  178. for j in 1..4 loop
  179. for i in 1..4 loop
  180. if VP(nump).mat(j,i)/=vide and not nope then
  181. if Addchar(col,i-1) <= 'H' and lg + j-1 <= T_Lig(T_Lig'last) then
  182. if G(lg + j-1,Addchar(col,i-1)).fiche = noir then
  183. colonne(j):=true;
  184. ligne(i):=true;
  185. elsif G(lg + j-1,Addchar(col,i-1)).fiche = VP(nump).coul
  186. and VP(nump).mat(j,i)=troue and
  187. G(lg + j-1,Addchar(col,i-1)).piece = 0 then
  188. colonne(j):=true;
  189. ligne(i):=true;
  190. elsif G(lg + j-1,Addchar(col,i-1)).fiche = noir
  191. and G(lg + j-1,Addchar(col,i-1)).piece = 0 then
  192. colonne(j):=true;
  193. ligne(i):=true;
  194. else
  195. colonne(j):=false;
  196. ligne(i):=false;
  197. end if;
  198. else
  199. colonne(j):=false;
  200. ligne(i):=false;
  201. nope := true;
  202. end if;
  203. elsif not nope then
  204. colonne(j):=true;
  205. ligne(i):=true;
  206. end if;
  207. end loop;
  208. end loop;
  209.  
  210. for i in 1..4 loop --estce possible ?
  211. if not colonne(i) or not ligne(i)then
  212. possible := false;
  213. end if;
  214. end loop;
  215.  
  216. if possible then
  217. for j in 1..4 loop
  218. for i in 1..4 loop
  219. if VP(nump).mat(j,i)/=vide then
  220. G(lg + j-1,Addchar(col,i-1)).piece:=nump;
  221. end if;
  222. end loop;
  223. end loop;
  224. VP(nump).place := true;
  225. end if;
  226. end Placer;
  227.  
  228. procedure Retirer(G : in out TV_Grille; VP : in out TV_Piece; nump : in T_NumPiece) is
  229.  
  230. begin
  231. if VP(nump).place = true then
  232. for j in T_Lig'range loop
  233. for i in T_Col'range loop
  234. if G(j,i).piece = nump then
  235. G(j,i).piece:= 0;
  236. end if;
  237. end loop;
  238. end loop;
  239. VP(nump).place := false;
  240. end if;
  241. end Retirer;
  242.  
  243.  
  244. function PartieGagne (VP : in TV_Piece) return boolean is
  245. i : integer := 1;
  246. begin
  247. while i <= 8 and then VP(i).place loop
  248. i := i + 1;
  249. end loop;
  250. return i = 8;
  251. end PartieGagne;
  252.  
  253. procedure Saisir_Piece(nump : out T_NumPiece) is
  254. begin
  255. loop
  256. begin
  257. p_esiut.A_la_ligne;
  258. p_esiut.ecrire("Saisir numéro de la piece :");p_esiut.lire(nump);
  259. if nump > 0 then
  260. exit;
  261. else
  262. p_esiut.ecrire_ligne("Valeur incorrecte");
  263. end if;
  264. exception
  265. when constraint_error => p_esiut.ecrire_ligne("Valeur incorrecte");
  266. end;
  267. end loop;
  268. end Saisir_Piece;
  269.  
  270.  
  271. end p_twistb;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement