Evolve the board into the state of the next iteration
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in), | dimension(:,:), allocatable | :: | current_board |
The current state of the board |
|
| integer, | intent(inout), | dimension(:,:), allocatable | :: | new_board |
The new state of the board |
subroutine evolve_board(current_board, new_board) !> The current state of the board integer, dimension(:,:), allocatable, intent(in) :: current_board !> The new state of the board integer, dimension(:,:), allocatable, intent(inout) :: new_board integer :: row, column, sum, nrow, ncol nrow = size(current_board, 1) ncol = size(current_board, 2) do row=2, nrow-1 do column=2, ncol-1 sum = 0 sum = current_board(row, column-1) & + current_board(row+1, column-1) & + current_board(row+1, column) & + current_board(row+1, column+1) & + current_board(row, column+1) & + current_board(row-1, column+1) & + current_board(row-1, column) & + current_board(row-1, column-1) if(current_board(row, column)==1 .and. sum<=1) then new_board(row, column) = 0 elseif(current_board(row, column)==1 .and. sum<=3) then new_board(row, column) = 1 elseif(current_board(row, column)==1 .and. sum>=4)then new_board(row, column) = 0 elseif(current_board(row, column)==0 .and. sum==3)then new_board(row, column) = 1 endif enddo enddo end subroutine evolve_board