- Joined
- Aug 9, 2007
- Sythe Gold
- 0
- Messages
- 115
Ok, I am trying to make a script that will generate scrambles for a Rubik's Cube. But it's not that simple. The scrambles look something like this; RU'B'DL. The problem is, they can't repeat and I don't know how I would do that. I tried making it so that if they do repeat it would do the rescram() function until they were different but that didn't work.
Any ideas would be great. Here's what I have so far.
Any ideas would be great. Here's what I have so far.
Code:
<script type="text/javascript">
var scramble = new Array(11)
scramble[0]="D'";
scramble[1]="R";
scramble[2]="L";
scramble[3]="U";
scramble[4]="D";
scramble[5]="F";
scramble[6]="B";
scramble[7]="R'";
scramble[8]="L'";
scramble[9]="U'";
scramble[10]="D'";
scramble[11]="F'";
var scram1 = Math.floor(Math.random()*11);
var scram2 = Math.floor(Math.random()*11);
var scram3 = Math.floor(Math.random()*11);
var scram4 = Math.floor(Math.random()*11);
var scram5 = Math.floor(Math.random()*11);
var scram6 = Math.floor(Math.random()*11);
function rescram() {
if(scram1 == scram2) {
var scram1 = Math.floor(Math.random()*11);
}
else if(scram2 == scram3) {
var scram2 = Math.floor(Math.random()*11);
}
else if(scram3 == scram4) {
var scram3 = Math.floor(Math.random()*11);
}
else if(scram4 == scram5) {
var scram4 = Math.floor(Math.random()*11);
}
else if(scram5 == scram6) {
var scram5 = Math.floor(Math.random()*11);
}
{
scramblea();
}
}
function displayscramble() {
document.write(scramble[scram1] + scramble[scram2] + scramble[scram3] + scramble[scram4] + scramble[scram5] + scramble[scram6]);
}
function scramblea() {
if(scram1 != "scram2" || scram2 != "scram3" || scram3 != "scram4" || scram4 != "scram5" || scram5 != "scram6")
{
displayscramble();
}
else
{
rescram();
}
}
scramblea();
</script>


