home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / e / e004 / 1.img / LIFE.MCD < prev    next >
Encoding:
Text File  |  1987-10-24  |  2.5 KB  |  95 lines

  1. .MCD 20000 0
  2. .CMD PLOTFORMAT logs=0,0 subdivs=1,1 size=5,15 type=l
  3. .CMD FORMAT  rd=d ct=10 im=i et=3 zt=15 pr=3 mass length time charge
  4. .CMD SET ORIGIN 0
  5. .CMD SET TOL 0.001000
  6. .CMD MARGIN 0
  7. .CMD LINELENGTH 70
  8. .CMD SET PRNCOLWIDTH 4
  9. .CMD SET PRNPRECISION 1
  10. .CMD FILENAME data1 data1
  11. .CMD FILENAME data2 data2
  12. .CMD FILENAME f start
  13. .CMD FILENAME life life
  14. .TXT 1 0 1 36 
  15. a1,35,33,34
  16. John Horton Conway's game of LIFE
  17. .TXT 2 0 10 32003 
  18. b10,32002,70,600
  19. LIFE begins with a two-dimensional array of ones and zeros. Ones are 
  20. "live" cells; zeroes are "dead" cells. In each step, or generation, 
  21. the array changes based on rules about how many neighbors a cell must 
  22. have to survive, to be born, or to die.
  23. 
  24. INSTRUCTIONS: 1. Type [Esc] DOS COPY START.PRN LIFE.PRN [Enter].
  25.               2. Go to READ equation by typing [Esc] go 30 [Enter].
  26.               3. For each generation, put the cursor on the "READ"     
  27.                  equation on line 30 and press [F9]. MathCAD shows the 
  28.                  results in graphs at the end of the document.     
  29. .EQN 11 1 1 9 
  30. n:10
  31. .TXT 0 11 1 40 
  32. a1,40,38,39
  33. Size of one side of the field of play.
  34. .EQN 2 -11 1 17 
  35. x1:0;n+1
  36. .EQN 0 19 1 12 
  37. x:1;n
  38. .TXT 0 15 3 43 
  39. a3,42,40,124
  40. Range variables for the matrix. (Row and 
  41. column 0 and row and column n+1 are the 
  42. edges. They are set to and remain zero.)
  43. .EQN 1 -34 1 17 
  44. y1:0;n+1
  45. .EQN 0 19 1 12 
  46. y:1;n
  47. .EQN 3 -19 2 13 
  48. F[(x1,y1):0
  49. .EQN 0 16 1 8 
  50. S:F
  51. .TXT 0 18 1 32 
  52. a1,31,53,30
  53. Initialize matricese to zero.
  54. .EQN 3 -34 1 16 
  55. dx:-1,0;1
  56. .TXT 0 16 1 34 
  57. a1,33,31,32
  58. Ranges used to count neighbors.
  59. .EQN 1 -16 1 16 
  60. dy:-1,0;1
  61. .TXT 2 -1 2 75 
  62. a2,74,74,127
  63. Now read the matrix from a data file. To calculate each generation, put 
  64. cursor on the following READ equation and press [F9].
  65. .EQN 3 0 1 20 
  66. F:READPRN(life)
  67. .TXT 0 48 1 18 
  68. a1,17,22,16
  69. ... Read matrix
  70. .EQN 1 -48 1 48 
  71. live(F,S):if(F≈1,(S≥3)*(S≤4),(S≈3))
  72. .TXT 0 48 1 30 
  73. a1,29,29,28
  74. ... Life and death function
  75. .EQN 1 -48 4 30 
  76. S[(x,y):dx$dy$F[(x+dx,y+dy)
  77. .EQN 1 37 2 31 
  78. G[(x1,y1):live(F[(x1,y1),S[(x1,y1))
  79. .EQN 3 -37 1 21 
  80. WRITEPRN(life):G
  81. .TXT 0 49 1 27 
  82. a1,26,28,25
  83. ... Write updated matrix
  84. .TXT 2 -49 3 32003 
  85. b3,32002,70,200
  86. The S array adds up the number of neighbors of elements of the Farray. 
  87. An element stays alive if it has 3 or 4 neighbors, self included. 
  88. Otherwise it dies. It is born if it has exactly 3 neighbors.
  89. .EQN 4 0 9 29 
  90. n+1&.1&F[(x,y)*y{1,1,8,18,o}@n+1&0&x
  91. .EQN 0 35 9 29 
  92. n+1&.1&G[(x,y)*y{1,1,8,18,o}@n+1&0&x
  93. .EQN 12 -35 12 44 
  94. F=?
  95.