evolve_board Subroutine

public subroutine evolve_board(current_board, new_board)

Evolve the board into the state of the next iteration

Arguments

Type IntentOptional 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


Called by

proc~~evolve_board~~CalledByGraph proc~evolve_board evolve_board proc~find_steady_state find_steady_state proc~find_steady_state->proc~evolve_board program~main main program~main->proc~find_steady_state

Source Code

    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