0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

お初とライフゲームと試しに

Last updated at Posted at 2023-05-08

anime.gif
fortranでライフゲーム

program main
  implicit none
  integer,parameter::r=50
  integer::p(r,r),pp(r,r)
  integer::x,y,i,j,count,t
  real*8::c
  character*3::num
  integer::seedsize
  integer,allocatable:: seed(:)
  call random_seed(size=seedsize)  
  allocate(seed(seedsize))         
  call random_seed(get=seed)
  

  open(21,file='count.dat',status='replace')
  do x=1,r
     do y=1,r
        call random_number(c)
        if(c < real(1d0/2)) then
           p(x,y)=1
        else
           p(x,y)=0
        end if
     end do
  end do

  open(11,file="001.dat",status='replace')
  do x=1,r
     do y=1,r
        write(11,'(3i3)')x,y,p(x,y)
     end do
  end do
  close(11)
  
  timeloop:do t=2,500
     do x=1,r
        do y=1,r
           count=0
           write(num,'(i3.3)')t
           if(p(x,y)==0) then
              do j=-1,1
                 do i=-1,1
                    !if(j/=0 .or. i/=0) cycle
                    if(j==0 .and. i==0) cycle
                    if(x+j<=0 .or. x+j>=r+1 .or. y+i<=0 .or. y+i>=r+1) cycle
                    if(p(x+j,y+i)==1) then
                       count=count+1
                    end if
                 end do
              end do
              if(count==3) then
                 pp(x,y)=1
              else
                 pp(x,y)=0
              end if
           end if

           if(p(x,y)==1) then
              do j=-1,1
                 do i=-1,1
                    !if(j/=0 .and. i/=0) cycle
                    if(j==0 .and. i==0) cycle
                    if(x+j<=0 .or. x+j>=r+1 .or. y+i<=0 .or. y+i>=r+1) cycle
                    if(p(x+j,y+i)==1) then
                       count=count+1
                    end if
                 end do
              end do
              if(count==2 .or. count==3) then
                 pp(x,y)=1
              else
                 pp(x,y)=0
              end if
           end if

        end do
     end do

     count=0
     do x=1,r
        do y=1,r
           if(p(x,y)==1)count=count+1
        end do
     end do

     

     write(21,'(2i10)')t-1,count
 

     open(11,file=TRIM(num)//".dat",status='replace')
     do x=1,r
        do y=1,r
           p(x,y)=pp(x,y)
           write(11,'(3i3)')x,y,p(x,y)
        end do
     end do
     close(11)
     
  end do timeloop
end program main
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?