Esempio n. 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);
        }
Esempio n. 2
0
        public BaseCell RandomNeighbour(BaseCell startCell)
        {
            BaseCell cell = Neighbours(startCell).Filter().Random();

            return(cell ?? startCell);
        }
Esempio n. 3
0
        public int RandomNeighbour(int startCell)
        {
            BaseCell cell = Neighbours(_cells[startCell]).Filter().Random();

            return(cell == null ? startCell : _cells.IndexOf(cell));
        }
Esempio n. 4
0
 public int IndexOf(BaseCell cell)
 {
     return(_cells.IndexOf(cell));
 }