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 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
| Program JV;
Uses crt;
type matrice = array[0..19,0..19] of integer;
Var a,b,c,d,i,j: integer;
var t1,t2: matrice;
Procedure remp;
Begin
randomize;
i:=0;
j:=0;
b:=0;
Repeat
Repeat
t1[i][j]:=0;
i:=i+1;
Until(i=20);
i:=0;
j:=j+1;
Until(j=20);
Writeln('Combien de cellules voulez-vous placer?');
Readln(a);
Repeat
i:=random(19);
j:=random(19);
If(t1[i][j]=0)then;
Begin
t1[i][j]:=1;
b:=b+1;
End;
Until (a=b);
End;
Procedure affi;
Begin
textcolor(10);
i:=0;
j:=0;
Repeat
Repeat
If(t1[i][j]=1)then
Begin
Write('*');
End
Else
Begin
Write(' ');
End;
i:=i+1;
until(i=20);
i:=0;
j:=j+1;
writeln('');
until(j=20);
End;
Procedure temp;
Begin
i:=0;
j:=0;
Repeat
Repeat
t2[i][j]:=0;
i:=i+1;
Until(i=20);
i:=0;
j:=j+1;
Until(j=20);
End;
{Nombre de cellules adjacentes}
Procedure ncel;
Begin
c:=0;
If (i<>19)and(t1[i+1][j]=1)then
Begin
c:=c+1;
End;
If (i<>0)and(t1[i-1][j]=1)then
Begin
c:=c+1;
End;
if (j<>19)and(t1[i][j+1]=1)then
Begin
c:=c+1;
End;
if (j<>0)and(t1[i][j-1]=1)then
Begin
c:=c+1;
End;
if ((i<>0) and (j<>0))and(t1[i-1][j-1]=1)then
Begin
c:=c+1;
End;
if ((i<>19) and (j<>19))and(t1[i+1][j+1]=1)then
Begin
c:=c+1;
End;
if ((i<>0) and (j<>19))and(t1[i-1][j+1]=1)then
Begin
c:=c+1;
End;
if ((i<>19)and(j<>0))and(t1[i+1][j-1]=1)then
Begin
c:=c+1;
End;
End;
{vie ou mort des cellules}
Procedure evol;
Begin
If (t1[i][j]=1)then
Begin
If (c=2)or(c=3)then
Begin
t2[i][j]:=1;
End
Else
Begin
t2[i][j]:=0;
End;
End;
If (t1[i][j]=0)then
Begin
If (c=3)then
Begin
t2[i][j]:=1;
End
Else
Begin
t2[i][j]:=0;
End;
End;
End;
{Parcourt les cases}
Procedure parc;
Begin
i:=0;
j:=0;
Repeat
Repeat
ncel;
evol;
i:=i+1;
until (i=20);
i:=0;
j:=j+1;
until (j=20)and(i=20);
End;
Procedure trans;
Begin
i:=0;
j:=0;
Repeat
Repeat
t1[i][j]:=t2[i][j];
i:=i+1;
until(i=20);
i:=0;
j:=j+1;
until (j=20)and(i=20);
end;
BEGIN
d:=0;
clrscr;
remp;
affi;
temp;
readln;
parc;
trans;
affi;
readln;
END. |
Partager