//Piece Constructor (get the piece type and change the shape and rotation/original matricies to reflect this) public Piece(int pieceType) { shape = pieceType; switch (pieceType) { case 0: rotatingMatrix = CPosition5.Clone() as bool[, , ]; originalMatrix = CPosition5.Clone() as bool[, , ]; break; case 1: rotatingMatrix = fourCPosition5.Clone() as bool[, , ]; originalMatrix = fourCPosition5.Clone() as bool[, , ]; break; case 2: rotatingMatrix = IPosition5.Clone() as bool[, , ]; originalMatrix = IPosition5.Clone() as bool[, , ]; break; case 3: rotatingMatrix = LPosition5.Clone() as bool[, , ]; originalMatrix = LPosition5.Clone() as bool[, , ]; break; case 4: rotatingMatrix = OPosition5.Clone() as bool[, , ]; originalMatrix = OPosition5.Clone() as bool[, , ]; break; case 5: rotatingMatrix = SPosition5.Clone() as bool[, , ]; originalMatrix = SPosition5.Clone() as bool[, , ]; break; case 6: rotatingMatrix = StPosition5.Clone() as bool[, , ]; originalMatrix = StPosition5.Clone() as bool[, , ]; break; case 7: rotatingMatrix = TPosition5.Clone() as bool[, , ]; originalMatrix = TPosition5.Clone() as bool[, , ]; break; default: Debug.Log("INVALID OBJECT TAG"); break; } }
IEnumerator Rotating() { //Setup and start Rotation routine bool[,,] rotatingMatrix = CurrentPiece.RotatingMatrix; Rotation.RotatingMatrix = rotatingMatrix.Clone() as bool[, , ]; Rotation.RotatingObject = PieceGameOb[currentTurn]; Rotation.RotatingPiece = CurrentPiece; Rotation.Rotating = true; //Wait for rotation Routine to finish while (Rotation.Rotating != false) { yield return(null); } //If undo is NOT pushed if (Rotation.undo == false) { //Get information from Rotation rotatingMatrix = Rotation.RotatingMatrix; PieceGameOb[currentTurn] = Rotation.RotatingObject; CurrentPiece = Rotation.RotatingPiece; //Move GameObject PieceGameOb[currentTurn].transform.position = CurrentPiece.Center; PieceGameOb[currentTurn].gameObject.layer = LayerMask.NameToLayer("Default"); foreach (Transform child in PieceGameOb[currentTurn].transform) { child.gameObject.layer = LayerMask.NameToLayer("Default"); } //Get rotating and translating matricies CurrentPiece.RotatingMatrix = rotatingMatrix.Clone() as bool[, , ]; CurrentPiece.TranslatingMatrix = rotatingMatrix.Clone() as bool[, , ]; state = GameState.TRANSLATION; active = true; } else { UndoRotation(); Basker.basking = true; state = GameState.BASKING; active = true; } }
public void UndoTranslation() { StopAllCoroutines(); //Play undo sound effect AudioMan.Play("Undo"); //Undo what translation routine has done CurrentPiece.TranslatingMatrix = null; bool[,,] rotatingMatrix = CurrentPiece.OriginalMatrix; CurrentPiece.RotatingMatrix = rotatingMatrix.Clone() as bool[, , ]; PieceGameOb[currentTurn].transform.position = new Vector3(0f, 1.5f, 0f); PieceGameOb[currentTurn].transform.eulerAngles = new Vector3(0f, 0f, 0f); CurrentPiece.Center = new Vector3(0f, 1.5f, 0f); //Reset all values at begining of translation routine Translation.TranslatingMatrix = null; Translation.BoardMatrix = null; Translation.TranslatingObject = null; Translation.Translating = false; PieceGameOb[currentTurn].gameObject.layer = LayerMask.NameToLayer("RotatingPosition"); foreach (Transform child in PieceGameOb[currentTurn].transform) { child.gameObject.layer = LayerMask.NameToLayer("RotatingPosition"); } //Reset undo for translation Translation.undo = false; }
public void UndoBask() { StopAllCoroutines(); //Play undo sound effect AudioMan.Play("Undo"); //undo what translation routine does currentTurn -= 1; CurrentPiece = Boards[currentTurn].BoardPiece; //Reset this and all proceeding boards to either a blank board or the board of currentturn-1 bool[,,] boardMatrix = new bool[boardDimensions[0], boardDimensions[1], boardDimensions[2]]; if (currentTurn > 0) { boardMatrix = Boards[currentTurn - 1].BoardMatrix; } for (int i = (currentTurn); i < (Boards.Length); i++) { Boards[i].BoardMatrix = boardMatrix.Clone() as bool[, , ]; } Boards[currentTurn].BoardPiece = null; bool[,,] translationMatrix = CurrentPiece.RotatingMatrix; CurrentPiece.TranslatingMatrix = translationMatrix.Clone() as bool[, , ]; PieceGameOb[currentTurn].transform.position = CurrentPiece.Center; Basker.basking = false; //Reset undo for basker Basker.undo = false; }
IEnumerator Translating() { testing(); //Setup and start translation routine bool[,,] translatingMatrix = CurrentPiece.TranslatingMatrix; Translation.TranslatingMatrix = translatingMatrix.Clone() as bool[, , ]; bool[,,] boardMatrix = Boards[currentTurn].BoardMatrix; Translation.BoardMatrix = boardMatrix; Translation.TranslatingObject = PieceGameOb[currentTurn]; Translation.Translating = true; while (Translation.Translating != false) { yield return(null); } if (Translation.undo == false) { //Get board matrix, completed piece and piece Gameobject boardMatrix = Translation.BoardMatrix; CurrentPiece.TranslatingMatrix = Translation.TranslatingMatrix; PieceGameOb[currentTurn] = Translation.TranslatingObject; //Give the board object the correct piece Boards[currentTurn].BoardPiece = CurrentPiece; //Clone the board matrix for every preceeding turn for (int i = (currentTurn); i < (Boards.Length); i++) { Boards[i].BoardMatrix = boardMatrix.Clone() as bool[, , ]; } //Nullify CurrentPiece and increase turn by one CurrentPiece = null; currentTurn += 1; //If there are no pieces left and it's not the first turn don't move on if (!piecesLeft() && currentTurn > 0) { GameObject destroyerOfWorlds = GameObject.Find("LevelLoader"); LevelLoader ll = destroyerOfWorlds.GetComponent <LevelLoader>(); ll.LoadNextLevel(); } Basker.basking = true; state = GameState.BASKING; active = true; } else { UndoTranslation(); state = GameState.ROTATION; active = true; } }
public void SetModelFromFile(bool[,,] _grid, int _width, int _height, int _length) { Width = _width; Length = _length; Height = _height; this.grid = _grid.Clone() as bool[, , ]; UpdateModel(); SetCamera(_width, _height, _length); RestartTransformation(); }
public bool[,,] InvertSegment(bool[,,] segment) { bool[,,] inverted = (bool[, , ])segment.Clone(); for (int a = 0; a < inverted.GetLength(0); a++) { for (int b = 0; b < inverted.GetLength(1); b++) { for (int c = 0; c < inverted.GetLength(2); c++) { inverted[a, b, c] = !inverted[a, b, c]; } } } return(inverted); }
private static bool[,,] Cycle3D(bool[,,] nodes) { bool[,,] nodes2 = (bool[, , ])nodes.Clone(); int maxx = nodes.GetLength(0); int maxy = nodes.GetLength(1); int maxz = nodes.GetLength(2); for (int x = 1; x < maxx - 1; x++) { for (int y = 1; y < maxy - 1; y++) { for (int z = 1; z < maxz - 1; z++) { int count = 0; for (int dx = -1; dx <= 1; dx++) { for (int dy = -1; dy <= 1; dy++) { for (int dz = -1; dz <= 1; dz++) { if (dx != 0 || dy != 0 || dz != 0) { if (nodes[x + dx, y + dy, z + dz]) { count++; } } } } } if (nodes[x, y, z]) { nodes2[x, y, z] = (count == 2 || count == 3); } else { nodes2[x, y, z] = (count == 3); } } } } return(nodes2); }
public Matrix Clone() { return(new Matrix((bool[, , ])matrix.Clone())); }
public List <bool[, , ]> SeparateSegment(bool[,,] segment, int maxSegments) { // do DFS from each point unless its already visited. Each iteration of DFS increment group counter // finally for each group create a new bool[,,] and assign values to true where the group is. bool[,,] segmentCopy = (bool[, , ])segment.Clone(); List <bool[, , ]> segments = new List <bool[, , ]>(); List <int> segmentVolumes = new List <int>(); Stack <Point> searchArea = new Stack <Point>(); int smallestVolume = -1; for (int a = 0; a < segment.GetLength(0); a++) { for (int b = 0; b < segment.GetLength(1); b++) { for (int c = 0; c < segment.GetLength(2); c++) { if (segmentCopy[a, b, c]) { int volume = 0; bool[,,] group = new bool[segment.GetLength(0), segment.GetLength(1), segment.GetLength(2)]; searchArea.Push(new Point(a, b, c)); while (searchArea.Count > 0) { Point point = searchArea.Pop(); if (point.x >= 0 && point.x < segment.GetLength(0) && point.y >= 0 && point.y < segment.GetLength(1) && point.z >= 0 && point.z < segment.GetLength(2)) { if (segmentCopy[point.x, point.y, point.z]) { segmentCopy[point.x, point.y, point.z] = false; group[point.x, point.y, point.z] = true; volume++; searchArea.Push(new Point(point.x - 1, point.y, point.z)); searchArea.Push(new Point(point.x + 1, point.y, point.z)); searchArea.Push(new Point(point.x, point.y - 1, point.z)); searchArea.Push(new Point(point.x, point.y + 1, point.z)); searchArea.Push(new Point(point.x, point.y, point.z + 1)); searchArea.Push(new Point(point.x, point.y, point.z - 1)); } } } if (volume > smallestVolume && segments.Count >= maxSegments) { int minVolume = segmentVolumes[0]; int minIndex = 0; for (int index = 1; index < segments.Count; index++) { if (segmentVolumes[index] < minVolume) { minVolume = segmentVolumes[index]; minIndex = index; } } segments.RemoveAt(minIndex); segmentVolumes.RemoveAt(minIndex); segments.Add(group); segmentVolumes.Add(volume); smallestVolume = Math.Min(smallestVolume, volume); } else { smallestVolume = Math.Min(smallestVolume, volume); segments.Add(group); segmentVolumes.Add(volume); } } } } } return(segments); }
public void BeginSculpturing() { helperGrid = grid.Clone() as bool[, , ]; }