From 74a74c281c98f26633a3d25bc74e49cb0b33d52c Mon Sep 17 00:00:00 2001 From: "Haoran S. Diao" <0@hairydiode.xyz> Date: Tue, 2 Apr 2019 09:15:07 -0400 Subject: made card form of the code --- .gitignore | 1 + Makefile | 3 +++ card.c | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 card.c diff --git a/.gitignore b/.gitignore index fe3d975..47e15f1 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ conway +card diff --git a/Makefile b/Makefile index b41e815..1aeb714 100644 --- a/Makefile +++ b/Makefile @@ -1,2 +1,5 @@ +main: card conway conway: conway.c gcc conway.c -o conway +card: card.c + gcc card.c -o card diff --git a/card.c b/card.c new file mode 100644 index 0000000..f831603 --- /dev/null +++ b/card.c @@ -0,0 +1,36 @@ +/* + * # + * # + * ### + */ +/*34567890123456789|1234567890123456789|1234567890123456789|*/ + #include + #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 */ -- cgit v1.1