Js help

Discussion in 'Web Programming' started by rubiksmaster12, Jan 31, 2008.

Js help
  1. Unread #1 - Jan 31, 2008 at 4:19 PM
  2. rubiksmaster12
    Joined:
    Aug 9, 2007
    Posts:
    115
    Referrals:
    0
    Sythe Gold:
    0

    rubiksmaster12 Active Member
    $5 USD Donor

    Js help

    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.

    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>
     
  3. Unread #2 - Feb 1, 2008 at 5:38 PM
  4. rubiksmaster12
    Joined:
    Aug 9, 2007
    Posts:
    115
    Referrals:
    0
    Sythe Gold:
    0

    rubiksmaster12 Active Member
    $5 USD Donor

    Js help

    Ok, I got it. There were a couple things wrong with it but I got it :)
     
< Dark Basic | innerHTML and getElementById() >

Users viewing this thread
1 guest


 
 
Adblock breaks this site