I'm trying to make a scramble generator for the rubik's cube, every letter corresponds to a move on the cube, but I don't want that two moves get printed next to each other, for example " R R U U2 L' " because that would make quite inefficient that scramble. I'll paste part of the code down below:
char a0[] = "R ";
char a1[] = "L' ";
char a2[] = "B' ";
char a3[] = "D2 ";
char a4[] = "F ";
char a5[] = "U2 ";
int moveA;
for (int i=0; i < 6; i++)
{
moveA = random(0,5);
if (moveA == 0)
Serial.print(a0);
else if (moveA == 1)
Serial.print(a1);
else if (moveA == 2)
Serial.print(a2);
else if (moveA == 3)
Serial.print(a3);
else if (moveA == 4)
Serial.print(a4);
else if (moveA == 5)
Serial.print(a5);
delay(200);
will return a value between 0 and 4, not between 0 and 5
Have you got a list of code pairs that must not appear in adjacent moves or can you provide an algorithm that given 2 codes can return a true/false value indicating whether they are allowed ?
R should not be next to R or L since "R R" is the same as "R2" and "R L" would result in no change.
For each move, pick an axis (RL, UD, or FB) that is different from the previous axis. Then pick a random move on that axis:
RL -> R, R2, R', L, L2, L'
UD -> U, U2, U', D, D2, D'
FB -> F, F2, F', B, B2, B'
Oops. I got that bit wrong. The reason you don't want to do "R L" is that if you then do R' it will undo the "R". The scramble will be two steps shorter than expected. By switching axis each time (RL, UD, FB) there is no way for a single move to undo a previous move.