summaryrefslogtreecommitdiff
path: root/card.c
blob: f83160343c42daf762f13ab6a5eadc980c3eef9e (plain)
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
/*
 *   #
 *    #
 *  ###
 */
/*34567890123456789|1234567890123456789|1234567890123456789|*/
                    #include   <stdio.h>
                    #define LOOP(cl,ln)\
                    for(int j=0;j<40;  \
		    j++){for(int i=0;i<\
		    80;i++){cl}ln      }
		    char grid[80][40]={{
		    0,0,2},{2,0,2},{0,2,
		    2},0};int neighbor 
		    (int x,int y){int ct
		    =0;for(int j=-1;j<=1
                                        ;j++){for(int i=-1;i
					<=1;i++){if(!((i==0) 
					&&(j==0))){if(grid[(
					x+i+80)%80][(y+j+40)
					%40]&0x02){ct++;}}}}
					switch (ct){case 2 :
					if(grid[x][y]&0x02){
					return 1;}else     {
					return 0;}case 3   :
					return 1           ;
default:return 0;}}int main(int argc,char*argv[]){int r=0;do
{r = fgetc(stdin);LOOP(if(grid[i][j]&0x02){printf("X");}else
{printf(",");},printf("\n"););LOOP(grid[i][j]=neighbor(i,j)|
(grid[i][j]&0x02);,);LOOP(grid[i][j]=grid[i][j]<<1;,);}while
(r!='q');}/*   Conway's Game of Life on a 80x40 Looping Grid
* Press [Enter] to start;   Keep pressing [Enter] to iterate
* To quit, press [q] then [Enter]. The game grid starts with
* a Glider on the top left corner. Changing the initial grid
* state is an excercise left to the reader. (Haoran S. Diao)
Email: 0@hairydiode.xyz, Website: https://hairydiode.xyz  */