Option Explicit
Const ROW_SIZE = 8
Const COL_SIZE = 8
Sub GameOfLife()
Dim rng As Range, arr
Set rng = Sheet1.Cells.Resize(ROW_SIZE, COL_SIZE).Offset(1, 1)
arr = rng.Value
If WorksheetFunction.Sum(arr) = 0 Then Call Init
Dim i, j
For i = 1 To ROW_SIZE
For j = 1 To COL_SIZE
Select Case WorksheetFunction.Sum(Sheet1.Cells(i, j).Resize(3, 3)) - arr(i, j)
Case 2
Case 3
arr(i, j) = 1
Case Else
arr(i, j) = 0
End Select
Next j, i
rng.Value = arr
With rng.Resize(1, 1).Offset(-1, rng.Columns.Count + 1)
.Value = .Value + 1
End With
Application.OnTime Now + TimeValue("00:00:02"), "GameOfLife"
End Sub
Sub Init()
Sheet1.Cells.Clear
With Sheet1.Cells.Resize(ROW_SIZE, COL_SIZE).Offset(1, 1)
.Formula = "=RANDBETWEEN(0,1)"
.EntireColumn.AutoFit
With .FormatConditions.Add(xlCellValue, xlEqual, 0)
.Interior.ColorIndex = 2
.Font.ColorIndex = 2
End With
With .FormatConditions.Add(xlCellValue, xlEqual, 1)
.Interior.ColorIndex = 1
.Font.ColorIndex = 1
End With
End With
End Sub
More than 3 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme