Ejemplo n.º 1
0
        public virtual int CountNeighbors(int cellX, int cellY)
        {
            int neighbors = 0;

            for (int neighborIndex = 0; neighborIndex < _neighborhoodCoordinates.Length; ++neighborIndex)
            {
                GridCoordinate neighborCoordinate = _neighborhoodCoordinates [neighborIndex];
                int            x = neighborCoordinate.X + cellX;
                int            y = neighborCoordinate.Y + cellY;
                // Neighbors off the grid do not count
                if (x >= 0 && x < _columns && y >= 0 && y < _rows && _matrix [x, y].State > 0)
                {
                    ++neighbors;
                }
            }
            return(neighbors);
        }
Ejemplo n.º 2
0
 public bool IsContained(GridCoordinate coordinate)
 {
     return((coordinate.X >= X) && (coordinate.X < X + Width) && (coordinate.Y >= Y) && (coordinate.Y < Y + Height));
 }