. , - .
, , . . : - , , - , .
. - , , . ( - - ) () (). , - , , . , , (.. , ), . , , , , , . , .
- , , , , . , , . , .
- - . , - - . , , .
, , . - , , .
. 7.48.
n +1 0 n, . 7.48. , .
(i, j) 8 . , , , .
. (i, j) , ( ). , ( ). , . [0. ., 0. . ], 0, , 1, . (i,j) :
|
|
S:= A[I-1, J-1] + A[I-1, J] + A[I-1, J+1] + A[I+1, J-1]
+ [I+1, J] + A[I+1, J+l] + A[I, J+l] + [1, J-1];
If (A[I, J] = 1) And ((S > 3) Or (S < 2); Then B(I, J]:= 0;
If (A[I, J] = 0) And (S = 3) Then B[I, J]:= 1;
[0. ., 0. . ] . i = 1 n - 1 j = 1 n - 1 . , ,
For I:= 1 N-l DO For J:= 1 To N-l Do A[I, J]:= B[I, J];
, . . .
For I:= 1 Do
Begin Kl:= Random(N-l); K2:= Random(N-l)+1; A[K1, K2]:= 1 End;
, , . .
150. .
Program PlayLife;
Uses Crt, Graph; Const R = 41;
Var P; 0..1; , : Array[0..R, 0..R] Of 0..1;
I, J, N, Kl, K2, Ss, X, Y, Gm, Gd: Integer; : Char;
Begin DetectGraph(I, J); InitGraph(I, J, ");
{ -- --)
For I:= 0 To 5 Do
Begin
SetFillStyle (1, I+2); Bar(180+1*10, 100+1*10, 430-1*10, 270-1*10);
End;
OutTextXY(260, 180, ' ""'); Repeat Until KeyPressed;
{ - - }
RestoreCrtMode;
For I:= 0 To R Do
For J:= 0 To R Do
Begin A[I, J]:= 0; [I, J]:= 0 End;
CIrScr;
Write(' (0/1)?'); ReadLn(P);
If P = 0 Then Begin
Write(' 2 < n < 200: ');
ReadLn(N); Gm:= VgaHi; SetGraphMode(Gm);
For I:= 1 To N Do
Begin
Kl:= Random(R - 1) + 1; K2:= Random(R - 1) + 1;
A{K1, K2]:= 1; B[K1, K2]:= 1;
End;
SetLineStyle(0, 0, 1); SetColor(4);
For I:= 0 To R - 1 Do
Begin
Line(10 + I * 10, 10, 10 + I * 10, R * 10);
Line(10, 10 + I * 10, R * 10, 10 + I * 10);
End;
For I:= 1 To R - 1 Do
For J:= 1 To R - 1 Do
If A[I, J] = 1 Then
FloodFill(5 + I * 10, 5 + J * 10, 4);
Repeat Until KeyPressed;
End
Else
Begin
Gm:= VgaHi; SetGraphMode(Gm); SetLineStyle(0, 0, 1); SetColor(4);
For I:= 0 To R - 1 Do
Begin
Line(10 + I * 10, 10, 10 + I * 10, R * 10);
Line(10, 10 + I * 10, R * 10, 10 + I * 10);
End;
X:= 15; Y:= 15;
Repeat
:= ReadKey; If = #0 Then := ReadKey;
Case C Of
#72: Begin
SetColor(O); Circle(X, Y, 2); Y:= Y - 10; SetColor(15);
Circle(X, Y, 2)
End;
#80: Begin
SetColor(O); Circle(X, Y, 2); Y:= + 10; SecColor(15);
|
|
Circle(X, Y, 2)
End;
#75: Begin
SetColor(O); Circle(X, Y, 2); X:= X - 10; SetColor(15);
Circle(X, Y, 2)
End;
#77: Begin
SetColor(0); Circle(X, Y, 2); X ^ X + 10; SetColor(15);
Circle(X, Y, 2)
End;
#13: Begin
FloodFill(X, Y, 4); A[(X-5) Div 10, (Y-5) Div 10]:= 1;
B[(X - 5) Div 10, (Y - 5) Div 10]:= 1
End;
#32: Begin
SetFillStyled, 0); Bar(X - 4, Y - 4, X + 4, Y + 4);
A[(X - 5) Div 10, (Y - 5) Div 10]:= 0:
B[(X - 5) Div 10, (Y - 5) Div 10]:= 0;
SetFillStyle(1, 15);
End;
End {case};
Until = #27;
SetColor(0); Circle(X, Y, 2);
End;
SetColor(15); Repeat Until Key Pressed;
OutTextXY(GetMaxX - 400, GetMaxY - 5, ' , - s');
{- -- }
Repeat
For I:= 1 R - 1 Do
For J:= 1 To R - 1 Do
Begin
Ss: = A[I - 1, J - 1] + A[I - 1, J] + A[I - 1, J + 1];
Ss:= Ss + A(I + 1, J - 1] + A[I + 1, J] + A[I +1, J + 1];
Ss:= Ss + A[I. J + 1] + A[I, J - 1];
If (A[I, J] = 1) And (Ss > 3) Then
Begin
SetFillStyled, 0); Bar(l + I * 10, 1 + J * 10, 9 + I * 10, 9 + J * 10);
B(I, J]:= 0; SetFillStyled, 15)
End;
If (A[I, J] == 1) And (Ss < 2) Then
Begin
SetFillStyled, 0); Bar(l + I * 10, 1 + J * 10, 9 + I * 10, 9 + J * 10);
B[I, J]:= 0; SetFillStyled, 15)
End;
If (A[I, J] = 0) And (Ss = 3) Then
Begin
FloodFill(5 + I * 10, 5 + J * 10, 4); B[I, J]:= 1
End; Delay(20)
End;
For I:= 1 To R - 1 Do
For J:= 1 To R - 1 Do A[I, J] = B[I, J];
:= ReadKey
Until = 's'; CloseGraph
End.
. : ? ? , ? . (. 7.49-7.50).
. 7.49. ,
, 1, 2, ..., , - n (. . 7.50).
. 7.50. - 2
- , , , , .
. . . , .
( ). , 0,1, 2, 3,4, 5, 0,1,0,0,0,0 0, 1,1, 1,0,0.
X(N) - . X(i) = 0, i- , X(i) = 1, ('- .
Y(N) - , , , - S = 1, Y(i) = 1, Y(i) = 0.
7.6. .
Program Lifel;
Uses Crt, Graph; Const N = 60;
Var J, : Integer; X, Y: Array(O..N] Of 0..1; I, S, Yg: Integer;
P: Real; : Chart;
Begin
For I:= 0 To N Do Begin X[I]:= 0; Y[I]:= 0 End;
( )
X[N Div 2]:= 1; DetectGraph(J, ); InitGraph(J, , "); Yg:= 20;
For I:= 0 To N Do If X(I] = 1 Then Circled * 10 + 10, Yg, 2);
Repeat := ReadKey; Yg:= Yg + 10;
For I:= 2 To N - 2 Do
Begin
S;= X[I - 2] + X[I - 1] + X[I] + X[I + 1] + X[I + 2];
If S In [1..3] Then Y[I1:= 1
End;
For I:= 0 To N Do
Begin
If Y[I] = 1 Then Circle(I * 10 + 10, Yg, 2); X[I]:= Y[I];
Y[I]:= 0
End
Until = #27; CloseGraph;
End.
1. ?
2. ?
3. ?
|
|
4. ?
5. ?
6. ? ? ? , ?
7. ? , ?
8. ?
9. , (7.63).
10. , (7.63).
11. ? ? ?
12. ?
13. ?
14. -?
15. -?
16. ? ?
17. , -, .
18. . .
19. - , .
20. . ( ). . , . . .