#include <stdio.h>
#include <stdlib.h>
#define FieldSize 20
#define TimeMax 20
/*フィールドの初期化 (ファイルの読み込み)*/
void init_field( int field[ FieldSize] [ FieldSize] , char * fname) {
int i, j;
FILE * fp;
if ( ( fp
= fopen ( fname
, "r" ) ) == NULL
) { printf ( "init_field(): Cannot open \" %s\" \n " , fname
) ; }
for ( i= 0 ; i< FieldSize; i++ ) {
for ( j= 0 ; j< FieldSize; j++ ) {
fscanf ( fp
, "%d " ,& field
[ i
] [ j
] ) ; }
}
}
int count( int I, int J, int field[ FieldSize] [ FieldSize] ) {
int i, j;
int i_tmp, j_tmp;
int sum;
sum= 0 ;
for ( i=- 1 ; i<= 1 ; i++ ) {
for ( j=- 1 ; j<= 1 ; j++ ) {
field[ i] [ j] = getrand( 0 , 1 ) ;
}
}
return sum;
}
void update_field( int field[ FieldSize] [ FieldSize] ) {
int i, j;
int around;
int new_field[ FieldSize] [ FieldSize] ;
for ( i= 0 ; i< FieldSize; i++ ) {
for ( j= 0 ; j< FieldSize; j++ ) {
around= count( i, j, field) ;
if ( ( new_field[ i] [ j] >= 3 ) && ! ( field[ i] [ j] ) ) {
field[ i] [ j] = 1 ;
}
/* ˆÛŽ */
else if ( ( ( new_field[ i] [ j] == 2 ) || ( new_field[ i] [ j] == 3 ) ) && ( field[ i] [ j] ) ) {
field[ i] [ j] = 1 ;
}
/* Ž€–S(‚»‚êˆÈŠO) */
else {
field[ i] [ j] = 0 ;
}
new_field[ i] [ j] = 0 ;
}
}
for ( i = 0 ; i < 20 ; i++ ) {
for ( j = 0 ; j < 20 ; j++ ) {
field[ i] [ j] = new_field[ i] [ j] ;
}
}
for ( i= 0 ; i< 20 ; i++ ) {
for ( j= 0 ; j< 20 ; j++ ) {
field[ i] [ j] = new_field[ i] [ j] ;
if ( field[ i] [ j] == 1 ) {
} else {
}
}
}
}
void display( int field[ FieldSize] [ FieldSize] ) {
int i, j;
for ( i= 0 ; i< 20 ; i++ ) {
for ( j= 0 ; j< 20 ; j++ ) {
if ( field[ i] [ j] == 1 ) {
} else {
}
}
}
}
int main( int argc, char * argv[ ] ) {
int t;
int field[ FieldSize] [ FieldSize] ;
if ( argc!= 2 ) {
printf ( "実行方法 : ./a.out 初期状態のファイル\n " ) ; }
//system("clear");
init_field( field, argv[ 1 ] ) ;
//display(field);
//sleep(1);
//system("clear");
for ( t= 0 ; t< TimeMax; t++ ) {
update_field( field) ;
display( field) ;
//sleep(1);
//system("clear");
}
return 0 ;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KCiNkZWZpbmUgRmllbGRTaXplIDIwCiNkZWZpbmUgVGltZU1heCAyMAoKLyrjg5XjgqPjg7zjg6vjg4njga7liJ3mnJ/ljJYgKOODleOCoeOCpOODq+OBruiqreOBv+i+vOOBvykqLwp2b2lkIGluaXRfZmllbGQoaW50IGZpZWxkW0ZpZWxkU2l6ZV1bRmllbGRTaXplXSwgY2hhciAqZm5hbWUpewogIGludCBpLGo7CiAgRklMRSAqZnA7CgogIGlmKChmcD1mb3BlbihmbmFtZSwiciIpKT09TlVMTCl7CiAgICBwcmludGYoImluaXRfZmllbGQoKTogQ2Fubm90IG9wZW4gXCIlc1wiXG4iLGZuYW1lKTsKICAgIGV4aXQoMSk7CiAgfQoKICBmb3IoaT0wO2k8RmllbGRTaXplO2krKyl7CiAgICBmb3Ioaj0wO2o8RmllbGRTaXplO2orKyl7CiAgICAgIGZzY2FuZihmcCwiJWQgIiwmZmllbGRbaV1bal0pOwogICAgfQogIH0KICBmY2xvc2UoZnApOwp9CgppbnQgY291bnQoaW50IEksIGludCBKLCBpbnQgZmllbGRbRmllbGRTaXplXVtGaWVsZFNpemVdKXsKICBpbnQgaSxqOwogIGludCBpX3RtcCxqX3RtcDsKICBpbnQgc3VtOwogIAogIHN1bT0wOwogIGZvcihpPS0xO2k8PTE7aSsrKXsKICAgIGZvcihqPS0xO2o8PTE7aisrKXsKICAgCglmaWVsZFtpXVtqXT1nZXRyYW5kK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WxkW0ZpZWxkU2l6ZV1bRmllbGRTaXplXSl7CiAgaW50IGksajsKCgpmb3IoaT0wO2k8MjA7aSsrKXsKCWZvcihqPTA7ajwyMDtqKyspewoJCWlmKGZpZWxkW2ldW2pdPT0xKXsKCQkJcHJpbnRmKCLilqAiKTsKCQkJfWVsc2V7CgkJCXByaW50Zigi4pahIik7CgkJCX0JCgkJfQkKCXByaW50ZigiXG4iKTsKfQoKfQoKaW50IG1haW4oaW50IGFyZ2MsIGNoYXIgKmFyZ3ZbXSl7CiAgaW50IHQ7CiAgaW50IGZpZWxkW0ZpZWxkU2l6ZV1bRmllbGRTaXplXTsKICAKICBpZihhcmdjIT0yKXsKICAgIHByaW50Zigi5a6f6KGM5pa55rOVIDogLi9hLm91dCDliJ3mnJ/nirbmhYvjga7jg5XjgqHjgqTjg6tcbiIpOwogIH0KCiAgLy9zeXN0ZW0oImNsZWFyIik7CiAgaW5pdF9maWVsZChmaWVsZCwgYXJndlsxXSk7CiAgLy9kaXNwbGF5KGZpZWxkKTsKICAvL3NsZWVwKDEpOwogIC8vc3lzdGVtKCJjbGVhciIpOwogIGZvcih0PTA7dDxUaW1lTWF4O3QrKyl7CiAgICB1cGRhdGVfZmllbGQoZmllbGQpOwogICAgZGlzcGxheShmaWVsZCk7CiAgICAvL3NsZWVwKDEpOwogICAgLy9zeXN0ZW0oImNsZWFyIik7CiAgfQoKICByZXR1cm4gMDsKfQoKCgoKCgo=
compilation info
prog.c: In function ‘init_field’:
prog.c:19: warning: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result
prog.c: In function ‘count’:
prog.c:34: warning: implicit declaration of function ‘getrand’
prog.c:27: warning: unused variable ‘j_tmp’
prog.c:27: warning: unused variable ‘i_tmp’
prog.c:34: warning: array subscript is below array bounds
/home/ZWNh2T/ccurMBxy.o: In function `count':
prog.c:(.text+0x9b): undefined reference to `getrand'
prog.c:(.text+0xb3): undefined reference to `getrand'
prog.c:(.text+0xcb): undefined reference to `getrand'
collect2: ld returned 1 exit status
stdout