Пример #1
0
        private List <BaseCell> Neighbours(BaseCell cell)
        {
            int             startPosition = _cells.IndexOf(cell);
            List <BaseCell> neighbours    = new List <BaseCell>();

            for (int i = -1; i <= 1; i++)
            {
                for (int j = -1; j <= 1; j++)
                {
                    int neighPosition = startPosition + i * _cols + j;
                    if (ValidatePosition(startPosition, neighPosition))
                    {
                        neighbours.Add(_cells[neighPosition]);
                    }
                }
            }
            return(neighbours);
        }
Пример #2
0
        public BaseCell RandomNeighbour(BaseCell startCell)
        {
            BaseCell cell = Neighbours(startCell).Filter().Random();

            return(cell ?? startCell);
        }
Пример #3
0
        public int RandomNeighbour(int startCell)
        {
            BaseCell cell = Neighbours(_cells[startCell]).Filter().Random();

            return(cell == null ? startCell : _cells.IndexOf(cell));
        }
Пример #4
0
 public int IndexOf(BaseCell cell)
 {
     return(_cells.IndexOf(cell));
 }