static void Main(string[] args) { Cube cube = new Cube(); DrawFlatCube(cube); if (RESOLVE) { do { DrawFlatCube(cube); cube.Scramble(30); CubeSolver solver = new CubeSolver(cube); AlgorithmCollection solution = solver.Solve(); solution.Optimize(); foreach (AlgorithmViewPair pair in solution) { cube.SetView(pair.View); DrawFlatCube(cube); Wait(); foreach (Move move in pair.Algorithm) { cube.ExecuteMove(move); Console.Clear(); DrawFlatCube(cube); Wait(); } } }while (Console.ReadKey().Key == ConsoleKey.Enter); } else { while (true) { Console.Write("Inserisci mossa: "); Move m = (Move)Enum.Parse(typeof(Move), Console.ReadLine()); cube.ExecuteMove(m); DrawFlatCube(cube); } } Console.ReadLine(); }
private IEnumerator SolveCube(bool ip = true) { int moves = 0; CubeSolver.Solve(); finishedRotation = true; isPaused = ip; ct.SetRotationSpeedIndex(4); playPauseButton.GetComponent <Button>().interactable = true; nextButton.GetComponent <Button>().interactable = lastButton.GetComponent <Button>().interactable = true; fasterButton.GetComponent <Button>().interactable = slowerButton.GetComponent <Button>().interactable = true; playPauseButton.GetComponent <Image>().sprite = play; yield return(new WaitUntil(() => CubeSolver.solution.Count > 0 && CubeSolver.guides.Count > 0)); int solutionIndex = -1; int guideIndex = 0; gc.SetGuideNum(CubeSolver.guides[guideIndex].Item2); while (true) { ct.finishedRotation = false; yield return(new WaitUntil(() => !isPaused || stepForward || stepBackward)); if (!isPaused || stepForward) { if (solutionIndex < CubeSolver.solution.Count - 1) { solutionIndex++; ct.Rotate(CubeSolver.solution[solutionIndex]); if (guideIndex < CubeSolver.guides.Count - 1 && CubeSolver.guides[guideIndex + 1].Item1 == solutionIndex) { gc.SetGuideNum(CubeSolver.guides[++guideIndex].Item2); } } else { ct.finishedRotation = true; } } else { if (solutionIndex >= 0) { ct.Rotate(CubeSolver.solution[solutionIndex].Item1, !CubeSolver.solution[solutionIndex].Item2); solutionIndex--; if (guideIndex > 0 && CubeSolver.guides[guideIndex].Item1 > solutionIndex) { gc.SetGuideNum(CubeSolver.guides[--guideIndex].Item2); } } else { ct.finishedRotation = true; } } stepForward = stepBackward = false; yield return(new WaitUntil(() => ct.finishedRotation)); yield return(new WaitForSeconds(0.1f)); } }
//Runs solve with the step selected by the slider public void Solve() { cube.Solve((int)slider.value); }