take all valid steps from any # elements in array
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=1), | intent(inout), | dimension(:,:), allocatable | :: | array |
recursive subroutine step(array) !! take all valid steps from any # elements in array character(len=1),dimension(:,:),intent(inout),allocatable :: array integer :: i,j logical :: steped character(len=1),dimension(:,:),allocatable :: tmp tmp = array do i = 1, nrows do j = 1, ncols if (array(i,j)=='O') then steped = .false. ! try a step in each direction: if (array(i-1,j)=='.') then tmp(i-1,j)='O'; steped = .true. end if if (array(i+1,j)=='.') then tmp(i+1,j)='O'; steped = .true. end if if (array(i,j-1)=='.') then tmp(i,j-1)='O'; steped = .true. end if if (array(i,j+1)=='.') then tmp(i,j+1)='O'; steped = .true. end if if (steped) tmp(i,j) = '.' end if end do end do call move_alloc(tmp,array) end subroutine step