Christopherx
Well-known member
- Joined
- Jul 4, 2010
- Messages
- 58
- Programming Experience
- Beginner
VB.NET:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim x, y As Integer
For y = 1 To DataGridView1.Rows.Count - 2
For x = 1 To DataGridView1.Columns.Count - 2
changed = True
count = 0
If DataGridView1.Rows(y - 1).Cells(x).Style.BackColor = Color.Green Then
count = count + 1
End If
If DataGridView1.Rows(y + 1).Cells(x).Style.BackColor = Color.Green Then
count = count + 1
End If
If DataGridView1.Rows(y).Cells(x - 1).Style.BackColor = Color.Green Then
count = count + 1
End If
If DataGridView1.Rows(y).Cells(x + 1).Style.BackColor = Color.Green Then
count = count + 1
End If
If DataGridView1.Rows(y - 1).Cells(x - 1).Style.BackColor = Color.Green Then
count = count + 1
End If
If DataGridView1.Rows(y + 1).Cells(x + 1).Style.BackColor = Color.Green Then
count = count + 1
End If
If DataGridView1.Rows(y - 1).Cells(x + 1).Style.BackColor = Color.Green Then
count = count + 1
End If
If DataGridView1.Rows(y + 1).Cells(x - 1).Style.BackColor = Color.Green Then
count = count + 1
End If
If count < 2 Then
DataGridView1.Rows(y).Cells(x).Style.BackColor = Color.White
End If
If count = 2 Or count = 3 And DataGridView1.Rows(y).Cells(x).Style.BackColor = Color.Green Then
DataGridView1.Rows(y).Cells(x).Style.BackColor = Color.Green
End If
If count > 3 Then
DataGridView1.Rows(y).Cells(x).Style.BackColor = Color.White
End If
If count = 3 And DataGridView1.Rows(y).Cells(x).Style.BackColor = Color.White Then
DataGridView1.Rows(y).Cells(x).Style.BackColor = Color.Green
End If
Next
Next
gen = gen + 1
Me.Text = "Generation:" & gen
population = 0
End Sub
So basically i've tried to simulate life using Conway's method, and i've decided that using a datagridview would be easy. The idea is I click the cells at the beginning to set the "seed" and then I click this button, and this code is ran. However, objects called still lives are exploding into crazy patterns, and that shouldn't happen, meaning my code is wrong somewhere. Can anyone help me find the problem? thankyou
edit: White represents "dead cells", green represents live.
Last edited: