示例#1
0
        public int ActiveNeighboursPart2(List <TimeCell> cells, VectorNInt position)
        {
            //return cells.Count(c => c.Active && Vector3Int.Distance(c.Position, position) < 2 && Vector3Int.Distance(c.Position, position) > 0);
            return(cells.Count(c => c.Active && c.Position != position &&
                               Math.Abs(c.Position.Values[0] - position.Values[0]) <= 1 &&
                               Math.Abs(c.Position.Values[1] - position.Values[1]) <= 1 &&
                               Math.Abs(c.Position.Values[2] - position.Values[2]) <= 1 &&
                               Math.Abs(c.Position.Values[3] - position.Values[3]) <= 1));


            //return cells.Count(c => c.Active && Vector3Int.DistanceManhattan(c.Position, position) == 1);
        }
示例#2
0
        public List <TimeCell> TickPart2(List <TimeCell> activeCells, int tickCount)
        {
            List <TimeCell> updatedActiveCells = new List <TimeCell>();

            for (int l = -startOffset - tickCount - startOffset; l < startOffset + tickCount + startOffset; l++)
            {
                for (int k = -startOffset - tickCount - startOffset; k <= startOffset + tickCount + startOffset; k++)
                {
                    for (int j = -startOffset - tickCount - startOffset; j <= startOffset + tickCount + startOffset; j++)
                    {
                        for (int i = -startOffset - tickCount - startOffset; i <= startOffset + tickCount + startOffset; i++)
                        {
                            VectorNInt pos = new VectorNInt(4);
                            pos.Values[0] = i;
                            pos.Values[1] = j;
                            pos.Values[2] = k;
                            pos.Values[3] = l;

                            //Vector3Int pos = new Vector3Int(i, j, k);

                            int activeNeighbours = ActiveNeighboursPart2(activeCells, pos);

                            if (activeCells.FirstOrDefault(c => c.Position == pos) != null)
                            {
                                if (activeNeighbours == 2 || activeNeighbours == 3)
                                {
                                    updatedActiveCells.Add(new TimeCell()
                                    {
                                        Position = pos,
                                        Active   = true
                                    });

                                    //Console.Write("#");
                                }
                                else
                                {
                                    //Console.Write(".");
                                }
                            }
                            else if (activeNeighbours == 3)
                            {
                                updatedActiveCells.Add(new TimeCell()
                                {
                                    Position = pos,
                                    Active   = true
                                });

                                //Console.Write("#");
                            }
                            else
                            {
                                //Console.Write(".");
                            }
                        }

                        //Console.WriteLine();
                    }

                    //Console.WriteLine();
                }
            }

            return(updatedActiveCells);
        }