Commits

Anonymous committed fc69dfb

support for most move notations

  • Participants
  • Parent commits c1a52b6

Comments (0)

Files changed (1)

 function endstep() {
     while (st < sol.length)
 	nextstep();
+    nextstep();
 }
 function nextstep() {
-    var i, j, str = "";
-    var num = ["+", "2", "-"];
+    var i, j, c, num, inc, str = "";
 
     if (st < 0) st = 0;
-    if (st > sol.length) {
+    if (st >= sol.length) {
 	document.forms[0].elements["solution"].value = sol;
 	return;
     }
     for (i = 0; i < sol.length; i++) {
 	if (i == st) {
-	    for (j = 0; j < 3; j++) {
+	    sol.charAt(i);
+	    num = 1;
+	    if (i + 1 < sol.length) {
+		switch (sol.charAt(i + 1)) {
+		    case '-':
+		    case '\'':
+		    case '3': num = 3; break;
+		    case '2': num = 2; break;
+		    default:  num = 1; break;
+		}
+	    }
+
+	    if (i + 1 < sol.length) {
+		for (inc = 1; inc + i < sol.length; inc++) {
+		    c = sol.charAt(i + inc);
+		    if (c == "U" || c == "D" || c == "F" ||
+			c == "B" || c == "R" || c == "L")
+			break;
+		}
+	    }
+
+	    for (j = 0; j < num; j++)
 		mov(sol.charAt(i));
-		if (sol.charAt(i + 1) == num[j])
-		    break;
-	    }
-	    str += sol.charAt(i) + sol.charAt(i + 1) + "  | ";
-	    i++;
+
+	    for (j = 0; j < inc; j++)
+		str += sol.charAt(i + j);
+	    str += "  |  ";
+	    i += inc - 1;
 	} else {
 	    str += sol.charAt(i);
 	}
     }
-    st += 3;
+    st += inc;
 
     document.forms[0].elements["solution"].value = str;
 }
 function firststep() {
     while (st > 0)
 	priorstep();
+    priorstep();
 }
 function priorstep() {
-    var i, j, str = "";
-    var num = ["-", "2", "+"];
+    var i, j, c, num, inc, str = "";
 
     if (st > sol.length) st = sol.length;
     if (st < 0) {
 	document.forms[0].elements["solution"].value = sol;
 	return;
     }
-    st -= 3;
+    for (st--; st >= 0; st--) {
+	c = sol.charAt(st);
+	if (c == "U" || c == "D" || c == "F" ||
+	    c == "B" || c == "R" || c == "L")
+	    break;
+    }
+
     for (i = 0; i < sol.length; i++) {
 	if (i == st) {
-	    for (j = 0; j < 3; j++) {
+	    sol.charAt(i);
+	    num = 1;
+	    if (i + 1 < sol.length) {
+		switch (sol.charAt(i + 1)) {
+		    case '-':
+		    case '\'':
+		    case '3': num = 1; break;
+		    case '2': num = 2; break;
+		    default:  num = 3; break;
+		}
+	    }
+
+	    if (i + 1 < sol.length) {
+		for (inc = 1; inc + i < sol.length; inc++) {
+		    c = sol.charAt(i + inc);
+		    if (c == "U" || c == "D" || c == "F" ||
+			c == "B" || c == "R" || c == "L")
+			break;
+		}
+	    }
+
+	    for (j = 0; j < num; j++)
 		mov(sol.charAt(i));
-		if (sol.charAt(i + 1) == num[j])
-		    break;
-	    }
-	    str += " |  " + sol.charAt(i) + sol.charAt(i + 1);
-	    i++;
+
+	    str += "  |  ";
+	    for (j = 0; j < inc; j++)
+		str += sol.charAt(i + j);
+	    i += inc - 1;
 	} else {
 	    str += sol.charAt(i);
 	}
 function setsol() {
     var i, j, k, str = document.forms[0].elements["solution"].value ;
 
-    k = 2;
+    k = 1;
     for (i = 0; i < str.length; i++) {
 	switch (str.charAt(i)) {
 	    case 'U':
 	    case 'B':
 	    case 'R':
 	    case 'L': j = 0; break;
+	    case '1':
 	    case '+':
 	    case '2':
+	    case '3':
+	    case '\'':
 	    case '-': j = 1; break;
 	    case ' ': j = 2; break;
 	    default : j = 3; break;
 	}
-	if (j == 3 || j != (k + 1) % 3) {
+	if (j == 3 || (j == 1 && k == 1)) {
 	    // put better error messages in...
 	    validation.innerHTML = "Bad character in sequence at pos " + i + " : " + str.charAt(i);
 	    return;
 	}
 	k = j;
     }
-    if (j == 0)
-	validation.innerHTML = "Missing direction at end of sequence";
-    if (j == 1) str += " ";
+    str += " ";
     sol = str;
     st = 0;
 }