1 /* ======================================================================= */
3 /* ======================================================================= */
12 #define max(x,y) ((x > y) ? x : y)
13 #define min(x,y) ((x > y) ? y : x)
15 const int num_rows
= min(50, NUM_ROWS
);
16 const int num_columns
= 40;
18 class site
*field_of_play
[num_rows
][num_columns
];
20 int site::total_surrounding(void)
22 int i
, j
, imin
, imax
, jmin
, jmax
, total
;
26 imax
= min(num_rows
- 1, x
+ 1);
28 jmax
= min(num_columns
- 1, y
+ 1);
30 for (i
= imin
; i
<= imax
; i
++)
31 for (j
= jmin
; j
<= jmax
; j
++)
32 if (field_of_play
[i
][j
]->read()) total
++;
41 for (i
= 0; i
< num_rows
; i
++)
42 for (j
= 0; j
< num_columns
; j
++)
44 if (field_of_play
[i
][j
]->read()) write_xyc(2*j
, i
, 'X');
45 else write_xyc(2*j
, i
, '.');
50 void glider(int x
, int y
)
52 field_of_play
[x
- 1][y
+ 0]->set();
53 field_of_play
[x
- 1][y
+ 1]->set();
54 field_of_play
[x
+ 0][y
- 1]->set();
55 field_of_play
[x
+ 0][y
+ 0]->set();
56 field_of_play
[x
+ 1][y
+ 1]->set();
59 void traffic_light(int x
, int y
)
61 field_of_play
[x
- 1][y
]->set();
62 field_of_play
[x
+ 0][y
]->set();
63 field_of_play
[x
+ 1][y
]->set();
73 for (i
= 0; i
< num_rows
; i
++)
74 for (j
= 0; j
< num_columns
; j
++)
75 field_of_play
[i
][j
] = new site(i
, j
);
78 traffic_light(num_rows
/2 - 8, num_columns
/2 - 8);
79 glider(num_rows
/2 + 8, num_columns
/2 + 8);
85 if ((c
= getch()) == 'q') { clear_screen(); return; }
88 for (i
= 0; i
< num_rows
; i
++)
89 for (j
= 0; j
< num_columns
; j
++)
90 field_of_play
[i
][j
]->clear();