Esempio n. 1
0
        public List <Cell> GetNeighbors(Board board, Cell cell)
        {
            var neighbors = NeighborhoodCache.GetCachedNeighbors(board, cell);

            if (neighbors.Any())
            {
                return(neighbors);
            }

            var horiNeighbors = new[] { cell.PosX - 1, cell.PosX, cell.PosX + 1 }
            .Where(z => z > 0 && z < board.Width);

            var vertiNeighbors = new[] { cell.PosY - 1, cell.PosY, cell.PosY + 1 }
            .Where(z => z > 0 && z < board.Height);

            horiNeighbors.ToList().ForEach(x =>
                                           vertiNeighbors.ToList().ForEach(y =>
            {
                var nCell = board.State[x, y];
                if (cell != nCell)
                {
                    neighbors.Add(nCell);
                }
            })
                                           );

            return(neighbors);
        }
Esempio n. 2
0
        public List <Cell> GetNeighbors(Board board, Cell cell)
        {
            var neighbors = NeighborhoodCache.GetCachedNeighbors(board, cell);

            if (neighbors.Any())
            {
                return(neighbors);
            }

            var leftEdge  = cell.PosX - 1 < 0 ? board.Width - 1 : cell.PosX - 1;
            var rightEdge = cell.PosX + 1 == board.Width ? 0 : cell.PosX + 1;
            var topEdge   = cell.PosY - 1 < 0 ? board.Height - 1 : cell.PosY - 1;
            var botEdge   = cell.PosY + 1 == board.Height ? 0 : cell.PosY + 1;

            var cols = new[] { leftEdge, cell.PosX, rightEdge }.ToList();
            var rows = new[] { topEdge, cell.PosY, botEdge }.ToList();

            cols.ForEach(x =>
                         rows.ForEach(y =>
            {
                var nCell = board.State[x, y];
                if (cell != nCell)
                {
                    neighbors.Add(nCell);
                }
            }
                                      ));

            return(neighbors);
        }
Esempio n. 3
0
        public List <Cell> GetNeighbors(Board board, Cell cell)
        {
            var neighbors = NeighborhoodCache.GetCachedNeighbors(board, cell);

            if (neighbors.Any())
            {
                return(neighbors);
            }

            var coordinantes = GetNeighborCoords(new Coordinant(cell.PosX, cell.PosY));

            coordinantes.ForEach(z =>
            {
                if (TryProcessBounds(board.Height - 1, board.Width - 1, ref z))
                {
                    neighbors.Add(board.State[z.X, z.Y]);
                }
            });

            return(neighbors);
        }