summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHaoran S. Diao <0@hairydiode.xyz>2019-04-02 09:15:07 -0400
committerHaoran S. Diao <0@hairydiode.xyz>2019-04-02 09:15:07 -0400
commit74a74c281c98f26633a3d25bc74e49cb0b33d52c (patch)
tree9d6f9bef469eaf291fd3c38df4dc55d88732a0c1
parent51476244ef31b7c2ec4710c524be4cb1cfff3559 (diff)
made card form of the code
-rw-r--r--.gitignore1
-rw-r--r--Makefile3
-rw-r--r--card.c36
3 files changed, 40 insertions, 0 deletions
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 <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 */