using System.Collections.Generic;
public static class Program
private static Cell[, ] _grid;
private static readonly Random _r = new Random();
public static bool FloodFill(Point p)
var queue = new Queue<(Point point, Cell cell)>();
queue.Enqueue((p, Get(p)));
var(point, current) = queue.Dequeue();
Scan(point, (next, cell) =>
cell.Neighbors = GetNeighbors(next);
queue!.Enqueue((next, cell));
private static bool CheckBounds(Point p) => p.X >= 0 && p.X < _grid.GetLength(0) && p.Y >= 0 && p.Y < _grid.GetLength(1);
private static Cell Get(Point p) => _grid[p.X, p.Y];
private static void Scan(Point p, Action<Point, Cell> action)
for (var x = p.X - 1; x <= p.X + 1; x++)
for (var y = p.Y - 1; y <= p.Y + 1; y++)
var next = new Point(x, y);
public static int GetNeighbors(Point p)
Scan(p, (next, cell) => count += cell.Live ? 1 : 0);
public static void Print()
for (var i = 0; i < _grid.GetLength(0); i++)
for (var j = 0; j < _grid.GetLength(1); j++)
Console.Write(_grid[i, j].Live ? "X" : _grid[i, j].Visited ? _grid[i, j].Neighbors.ToString() : " ");
public static void Main()
var rows = _r.Next(5, 10);
var columns = _r.Next(5, 10);
_grid = new Cell[rows, columns];
for (var i = 0; i < rows; i++)
for (var j = 0; j < columns; j++)
{Live = _r.Next(0, 3) == 0};
var p = new Point(_r.Next(0, rows), _r.Next(0, columns));
Console.WriteLine("Dead");