Example #1
0
        public Box()
        {
            pieces       = new Pieces();
            boxContainer = new int[PieceSize, PieceSize, PieceSize];

            // Initialize array with NoPiece
            for (int z = 0; z < PieceSize; z++)
            {
                for (int y = 0; y < PieceSize; y++)
                {
                    for (int x = 0; x < PieceSize; x++)
                    {
                        boxContainer[z, y, x] = NoPiece;
                    }
                }
            }

            // This is used in Simulate_Two, for keeping track of previous iterations for back tracking
            log = new BoxCoordinate[NumPieces];

            for (int i = 0; i < log.Length; i++)
            {
                log[i] = new BoxCoordinate(0, 0, 0);
            }

            currentCount = 0;
            highCount    = currentCount;
            lowCount     = currentCount;
        }
Example #2
0
        /// <summary>
        /// This method will try and place a piece at the specified z/y/z coordinates. If it can, this method
        /// will place the piece at that position and return true, otherwise will return false.
        /// </summary>
        /// <param name="x">x value</param>
        /// <param name="y">y value</param>
        /// <param name="z">z value</param>
        /// <param name="collection">Possible pieces that can go into that position</param>
        /// <returns>If a piece can fit at that specified location</returns>
        private bool place(int x, int y, int z, BoxCoordinate[][] collection) {
            foreach (BoxCoordinate[] pieces in collection) {
                // This is so valid never sets to true as no pieces will skip foreach loop
                if (pieces.Length == 0) continue;

                bool valid = true;

                foreach (BoxCoordinate piece in pieces) {
                    // If cell has already been set, move onto next piece orientation
                    if (boxContainer[piece.Z + z, piece.Y + y, piece.X + x] != NoPiece) {
                        valid = false;
                        break;
                    }
                }

                // If found a place for a piece, set that piece equal to CurrentCount, then increment
                if (valid) {
                    foreach (BoxCoordinate piece in pieces) {
                        boxContainer[piece.Z + z, piece.Y + y, piece.X + x] = currentCount;
                    }

                    return true;
                }
            }

            return false;
        }
Example #3
0
        public Box() {
            pieces = new Pieces();
            boxContainer = new int[PieceSize, PieceSize, PieceSize];

            // Initialize array with NoPiece
            for (int z = 0; z < PieceSize; z++) {
                for (int y = 0; y < PieceSize; y++) {
                    for (int x = 0; x < PieceSize; x++) {
                        boxContainer[z, y, x] = NoPiece;
                    }
                }
            }

            // This is used in Simulate_Two, for keeping track of previous iterations for back tracking
            log = new BoxCoordinate[NumPieces];
            
            for (int i = 0; i < log.Length; i++) {
                log[i] = new BoxCoordinate(0, 0, 0);
            }

            currentCount = 0;
            highCount = currentCount;
            lowCount = currentCount;           
        }