示例#1
0
 protected void CheckPosition(Vector4 pos, out int n)
 {
     n = 0;
     for (int x = -1; x <= 1; x++)
     {
         for (int y = -1; y <= 1; y++)
         {
             for (int z = -1; z <= 1; z++)
             {
                 for (int w = -1; w <= 1; w++)
                 {
                     if (x == 0 && y == 0 && z == 0 && w == 0)
                     {
                         continue;                                       // this is ourselves
                     }
                     var nPos = new Vector4(pos.X + x, pos.Y + y, pos.Z + z, pos.W + w);
                     if (ActiveCells.Contains(nPos))
                     {
                         n++;
                     }
                 }
             }
         }
     }
 }
示例#2
0
            protected virtual void Cycle()
            {
                var neighbourCounts = GatherCounts();

                UpdateCells(neighbourCounts);

                XBounds = UpdateBounds(ActiveCells.Select(r => r.X));
                YBounds = UpdateBounds(ActiveCells.Select(r => r.Y));
                ZBounds = UpdateBounds(ActiveCells.Select(r => r.Z));
            }
示例#3
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public override int GetHashCode()
        {
            int prime  = 31;
            int result = 1;

            result = prime * result + ((ActiveCells == null) ? 0 : ActiveCells.GetHashCode());
            result = prime * result + ((PredictiveCells == null) ? 0 : PredictiveCells.GetHashCode());
            result = prime * result + ((WinnerCells == null) ? 0 : WinnerCells.GetHashCode());
            result = prime * result + ((ActiveSegments == null) ? 0 : ActiveSegments.GetHashCode());
            result = prime * result + ((MatchingSegments == null) ? 0 : MatchingSegments.GetHashCode());
            return(result);
        }
示例#4
0
            public PocketDimension3d Next()
            {
                var minX = ActiveCells.Min(cell => cell.X);
                var minY = ActiveCells.Min(cell => cell.Y);
                var minZ = ActiveCells.Min(cell => cell.Z);
                var maxX = ActiveCells.Max(cell => cell.X);
                var maxY = ActiveCells.Max(cell => cell.Y);
                var maxZ = ActiveCells.Max(cell => cell.Z);

                var nextGenBuilder = ImmutableHashSet <Cell3d> .Empty.ToBuilder();

                for (int x = minX - 1; x <= maxX + 1; x++)
                {
                    for (int y = minY - 1; y <= maxY + 1; y++)
                    {
                        for (int z = minZ - 1; z <= maxZ + 1; z++)
                        {
                            var cell = new Cell3d(x, y, z);
                            var activeNeighboursCount = cell.GetNeighbours()
                                                        .Where(neighbour => ActiveCells.Contains(neighbour))
                                                        .Count();
                            var has2Neighbors = activeNeighboursCount == 2;
                            var has3Neighbors = activeNeighboursCount == 3;
                            var isActive      = ActiveCells.Contains(cell);

                            if (isActive && (has2Neighbors || has3Neighbors))
                            {
                                // If a cube is active and exactly 2 or 3 of its neighbors are also active,
                                // the cube remains active. Otherwise, the cube becomes inactive.
                                nextGenBuilder.Add(cell);
                            }
                            else if (!isActive && has3Neighbors)
                            {
                                // If a cube is inactive but exactly 3 of its neighbors are active,
                                // the cube becomes active. Otherwise, the cube remains inactive.
                                nextGenBuilder.Add(cell);
                            }
                        }
                    }
                }

                return(new PocketDimension3d(nextGenBuilder.ToImmutable()));
            }
示例#5
0
        /* (non-Javadoc)
         * @see java.lang.Object#equals(java.lang.Object)
         */

        public override bool Equals(object obj)
        {
            if (this == obj)
            {
                return(true);
            }
            if (obj == null)
            {
                return(false);
            }
            if (this.GetType() != obj.GetType())
            {
                return(false);
            }
            ComputeCycle other = (ComputeCycle)obj;

            if (ActiveCells == null)
            {
                if (other.ActiveCells != null)
                {
                    return(false);
                }
            }
            else if (!ActiveCells.Equals(other.ActiveCells))
            {
                return(false);
            }
            if (PredictiveCells == null)
            {
                if (other.PredictiveCells != null)
                {
                    return(false);
                }
            }
            else if (!PredictiveCells.Equals(other.PredictiveCells))
            {
                return(false);
            }
            if (WinnerCells == null)
            {
                if (other.WinnerCells != null)
                {
                    return(false);
                }
            }
            else if (!WinnerCells.Equals(other.WinnerCells))
            {
                return(false);
            }
            if (ActiveSegments == null)
            {
                if (other.ActiveSegments != null)
                {
                    return(false);
                }
            }
            else if (!ActiveSegments.Equals(other.ActiveSegments))
            {
                return(false);
            }
            if (MatchingSegments == null)
            {
                if (other.MatchingSegments != null)
                {
                    return(false);
                }
            }
            else if (!MatchingSegments.Equals(other.MatchingSegments))
            {
                return(false);
            }
            return(true);
        }