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 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
| Program JV;
Uses crt;
type matrice = array[0..19,0..19] of integer;
Var a,b,c,d,e,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);
if a>400 then
begin
writeln('Tu en as placé trop ! (max: 400)');
end;
Repeat
i:=random(20);
j:=random(20);
If(t1[i][j]=0)then;
Begin
t1[i][j]:=1;
b:=b+1;
End;
Until (a=b);
End;
Procedure affi;
Begin
clrscr;
textcolor(10);
i:=0;
j:=0;
Repeat
Repeat
If(t1[i][j]=1)then
Begin
Write('O');
End
Else
Begin
Write(' ');
End;
i:=i+1;
until(i=20);
i:=0;
j:=j+1;
writeln('');
until(j=20);
writeln('');
writeln('Cycle: ', d,' Cellules vivantes: ', a);
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;
a:=a-1;
End;
End;
If (t1[i][j]=0)then
Begin
If (c=3)then
Begin
t2[i][j]:=1;
a:=a+1;
End
Else
Begin
t2[i][j]:=0;
End;
End;
End;
{Parcourt les cases}
Procedure parc;
Begin
b:=a;
i:=0;
j:=0;
Repeat
Repeat
ncel;
evol;
i:=i+1;
until (i=20);
i:=0;
j:=j+1;
until (j=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);
end;
Procedure final;
Begin
case a of
0 : writeln('Toutes les cellules sont mortes');
1..399 : writeln('Système stabilisé');
400 : writeln('Système saturé');
else writeln('Il y a un probléme...');
end;
readln;
End;
BEGIN
clrscr;
writeln('O Le Jeu de la Vie O');
readln;
d:=0;
e:=0;
remp;
affi;
temp;
readln;
repeat
parc;
trans;
d:=d+1;
affi;
if (a=b)then
begin
e:=e+1;
end
else
begin
e:=0;
end;
readln;
until (a<1)or(a>399)or(e=6);
final;
END. |
Partager