You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Animation.vb, surrounding() and grow() have duplicate code. How about loops?
The code below could be further simplified by just storing 0 and 1 in the grid. However, I have not yet figured out why you store different integers in there.
Private Function surrounding(r As Integer, c As Integer) As Integer
Dim count As Integer = 0
If _cellValues(r)(c) > 0 Then
count = -1 ' Do not consider the cell itself
End If
For dr As Integer = -1 To 1 ' surrounding rows
For dc As Integer = -1 To 1 ' surrounding columns
If r + dr > 0 And r + dr < 99 Then ' bounds check rows
If c + dc > 0 And c + dc < 99 Then ' bounds check column
If _cellValues(r + dr)(c + dc) > 0 then
count += 1
End If
End If
End If
Next
Next
Return count
End Function
Issue metadata
Issue type: sample-update
The text was updated successfully, but these errors were encountered:
Conway's game of life: remove duplicate code
Animation.vb, surrounding() and grow() have duplicate code. How about loops?
The code below could be further simplified by just storing 0 and 1 in the grid. However, I have not yet figured out why you store different integers in there.
Issue metadata
The text was updated successfully, but these errors were encountered: