public void QueueCommand(string word, float turnRate = 30.0f) { if (word == "") { return; } //Debug.Log(word); List <Transform> list; Vector3 center; Vector3 axis; float amount = 0.0f; _cube.SortCubeGroups(); _cube.CmdToTurn(word, out list, out center, out axis, out amount); rotations.Add(new Rotator(list, center, axis, amount, turnRate, word)); if (rotations.Count == 1) // was previously empty, initialize rotations { Animator rotator = rotations[0] as Animator; rotator.Start(); current = 0; } }
// Solve for cubie given the passed constraints private int Search(CubeInfo.Cubie c, List <CubeInfo.Cubie> constraints, ArrayList steps, int stepNum, ScoreStateFn scoreFn, ref List <string> path, ref List <string> bestPath) { int score = scoreFn(c, constraints); if (stepNum >= steps.Count) { //Debug.Log(" score " + score + " " + path[0]); if (score > 0) { // bonus for empty moves (e.g. fewer moves is better) foreach (string s in path) { if (s == "") { score += 10; } } //string spath = ""; //foreach (string s in path) spath += s + " "; //Debug.Log("SCORE " + score + " " + spath + " " + path.Count); } bestPath = new List <string>(path); return(score); } string[] turns = (string[])steps[stepNum]; for (int i = 0; i < turns.Length; i++) { List <Transform> list = new List <Transform>(); Vector3 center = new Vector3(0, 0, 0); Vector3 axis = new Vector3(0, 0, 0); float amount = 0.0f; string turn = turns[i]; if (turn != "") { if (turn == "X") { turn = _cube.Reverse((string)path[path.Count - 2]); } _cube.CmdToTurn(turn, out list, out center, out axis, out amount); _cube.turn(list, center, axis, amount); // un-apply move } path.Add(turn); List <string> bestChild = new List <string>(); int tmp = Search(c, constraints, steps, stepNum + 1, scoreFn, ref path, ref bestChild); if (tmp > score) { score = tmp; bestPath = new List <string>(bestChild); } if (turn != "") { _cube.turn(list, center, axis, -amount); // un-apply move } path.RemoveAt(path.Count - 1); } return(score); }