private Vector3 GetRotationAxis(FaceMove rotation) { switch (rotation.Face) { case Face.Up: case Face.CubeY: return(rotation.Prime ? Vector3.down : Vector3.up); case Face.Down: case Face.Equator: return(rotation.Prime ? Vector3.up : Vector3.down); case Face.Right: case Face.CubeX: return(rotation.Prime ? Vector3.left : Vector3.right); case Face.Left: case Face.Middle: return(rotation.Prime ? Vector3.right : Vector3.left); case Face.Front: case Face.Standing: case Face.CubeZ: return(rotation.Prime ? Vector3.forward : Vector3.back); case Face.Back: return(rotation.Prime ? Vector3.back : Vector3.forward); default: return(Vector3.zero); } }
private void NewMoveStarted(FaceMove move) { if (move.Face == Face.CubeY || move.Face == Face.CubeX) { _audioSource.PlayOneShot(_flipSounds[Random.Range(0, _flipSounds.Length)]); } else { _audioSource.PlayOneShot(_turnSounds[Random.Range(0, _turnSounds.Length)]); } // Perhaps this should be moved to the end or middle of the physical move?t ProcessQuarterMove(move); if (move.Double) { ProcessQuarterMove(move); } if (move.Shuffle && move.Log) { _shuffleMoves.Push(move); } else if (move.Log) { _previousMoves.Push(move); } }
private void Update() { if (_currentMove.Remaining > 0) { if ((!_currentMove.Double && _currentMove.Remaining == 90f) || (_currentMove.Double && _currentMove.Remaining == 180f)) { NewMoveStarted(_currentMove); } var cubeIndexes = GetPhysicalFaceCubeIndexes(_currentMove.Face); var rotationAxis = GetRotationAxis(_currentMove); var worldAxis = transform.TransformDirection(rotationAxis); var rotation = Mathf.Lerp(0, _currentMove.Remaining + _rotationLerpOffset, _rotationSpeed * Time.deltaTime); if (rotation < _rotationThreashold || rotation > _currentMove.Remaining) { rotation = _currentMove.Remaining; } _currentMove.Remaining -= rotation; foreach (var i in cubeIndexes) { var localAxis = _physicalCube[i].transform.InverseTransformDirection(worldAxis); _physicalCube[i].transform.Rotate(localAxis, rotation); } } if (_plannedMoves.Count > 0 && _currentMove.Remaining == 0) { _currentMove = _plannedMoves[0]; _plannedMoves.RemoveAt(0); } }
public void RankedShuffle() { _cylinder.gameObject.SetActive(true); _timer = _prepTime; _prepping = true; _shuffling = true; _controlLocked = true; ToggleButtonLock(_controlLocked); _rCube.ReverseAll(); var lastMove = new FaceMove(); for (int i = 0; i < 20; i++) { Face face = (Face)Random.Range(0, 6); // ignoring middle rings bool prime = Random.value < 0.5f; if (i > 0 && lastMove.Face == face && lastMove.Prime != prime) { i -= 1; } else { lastMove = new FaceMove() { Face = face, Prime = prime }; _rCube.RotateFace(face, prime, shuffle: true, hidden: true); } } }
public void CasualShuffle() { // _controlLocked = true; // ToggleButtonLock(_controlLocked); // _rCube.ReverseAll(); Reset(); _shuffling = true; var lastMove = new FaceMove(); for (int i = 0; i < 20; i++) { Face face = (Face)Random.Range(0, 6); // ignoring middle rings bool prime = Random.value < 0.5f; if (i > 0 && lastMove.Face == face && lastMove.Prime != prime) { i -= 1; } else { lastMove = new FaceMove() { Face = face, Prime = prime }; _rCube.RotateFace(face, prime, shuffle: true); } } }
public void RotateFace(Face face, bool prime, bool alreadyDouble = false, bool shuffle = false, bool hidden = false, bool log = true) { var newMove = new FaceMove() { Face = face, Prime = prime, Remaining = alreadyDouble ? 180f : 90f, Double = alreadyDouble, Shuffle = shuffle, Hidden = hidden, Log = log }; if (GeneralSettings.NoDoubleMove) { _plannedMoves.Add(newMove); return; } // Doubling a planned move if (!alreadyDouble && _plannedMoves.Count > 0 && !_plannedMoves[_plannedMoves.Count - 1].Double && _plannedMoves[_plannedMoves.Count - 1].Face == face && _plannedMoves[_plannedMoves.Count - 1].Prime == prime) { var move = _plannedMoves[_plannedMoves.Count - 1]; move.Remaining += 90f; move.Double = true; _plannedMoves[_plannedMoves.Count - 1] = move; } // doubling the ongoing move else if (!alreadyDouble && _plannedMoves.Count == 0 && _currentMove.Remaining > 0 && !_currentMove.Double && _currentMove.Face == face && _currentMove.Prime == prime) { _currentMove.Remaining += 90f; _currentMove.Double = true; // same move but on a currently happening move, so we need to process it once more ProcessQuarterMove(_currentMove); if (_currentMove.Shuffle && _currentMove.Log) { var tempMove = _shuffleMoves.Pop(); tempMove.Double = true; tempMove.Remaining = 180f; _shuffleMoves.Push(tempMove); } else if (_currentMove.Log) { var tempMove = _previousMoves.Pop(); tempMove.Double = true; tempMove.Remaining = 180f; _previousMoves.Push(tempMove); } } // normal move else { _plannedMoves.Add(newMove); } }
private void ProcessQuarterMove(FaceMove move) { if (move.Face == Face.Equator || move.Face == Face.Middle || move.Face == Face.Standing) { // ring rotation PhysicalFaceRotation(move.Face, move.Prime); VirtualRingRotation(GetVituralRingIndexes(move.Face), move.Prime); } else if (move.Face == Face.CubeY) { // horizontal cube rotation PhysicalFaceRotation(Face.Up, move.Prime); PhysicalFaceRotation(Face.Equator, !move.Prime); PhysicalFaceRotation(Face.Down, !move.Prime); VirtualFaceRotation(Face.Up, move.Prime); VirtualRingRotation(GetVituralRingIndexes(Face.Equator), !move.Prime); VirtualFaceRotation(Face.Down, !move.Prime); } else if (move.Face == Face.CubeX) { // vertical cube rotation PhysicalFaceRotation(Face.Right, move.Prime); PhysicalFaceRotation(Face.Middle, !move.Prime); PhysicalFaceRotation(Face.Left, !move.Prime); VirtualFaceRotation(Face.Right, move.Prime); VirtualRingRotation(GetVituralRingIndexes(Face.Middle), !move.Prime); VirtualFaceRotation(Face.Left, !move.Prime); } else if (move.Face == Face.CubeZ) { // vertical cube rotation PhysicalFaceRotation(Face.Front, move.Prime); PhysicalFaceRotation(Face.Standing, move.Prime); PhysicalFaceRotation(Face.Back, !move.Prime); VirtualFaceRotation(Face.Front, move.Prime); VirtualRingRotation(GetVituralRingIndexes(Face.Standing), move.Prime); VirtualFaceRotation(Face.Back, !move.Prime); } else { // standard rotation PhysicalFaceRotation(move.Face, move.Prime); VirtualFaceRotation(move.Face, move.Prime); } }
public List <FaceMove> ProcessInputString(string inputs) { List <FaceMove> moves = new List <FaceMove>(); var stringMoves = inputs.Split(' '); foreach (var sm in stringMoves) { var move = new FaceMove(); move.Shuffle = true; move.Log = false; move.Hidden = false; bool valid = true; if (sm.Length == 0) { continue; } // check face if (sm[0] == 'R') { move.Face = Face.Right; } else if (sm[0] == 'L') { move.Face = Face.Left; } else if (sm[0] == 'U') { move.Face = Face.Up; } else if (sm[0] == 'D') { move.Face = Face.Down; } else if (sm[0] == 'B') { move.Face = Face.Back; } else if (sm[0] == 'F') { move.Face = Face.Front; } else if (sm[0] == 'E') { move.Face = Face.Equator; } else if (sm[0] == 'S') { move.Face = Face.Standing; } else if (sm[0] == 'M') { move.Face = Face.Middle; } else if (sm[0] == 'X') { move.Face = Face.CubeX; } else if (sm[0] == 'Y') { move.Face = Face.CubeY; } else if (sm[0] == 'Z') { move.Face = Face.CubeZ; } else { valid = false; } // check prime if (sm.Contains("'")) { move.Prime = true; } // check double if (sm.Contains("2")) { move.Double = true; move.Remaining = 180f; } else { move.Remaining = 90f; } if (valid) { moves.Add(move); } else { Debug.LogError("Cannot identify move: " + sm); } } return(moves); }