How do scrambling programs get their scramble?

maxcube

Regular
Joined
Dec 12, 2008
Messages
184
WCA ID
2008LAND01
YouTube
Visit Channel
I am creating a Rubik's program thingy;) and I need to know how to generate scrambles. Completely random? Certain alg? How? Thank you very much!

EDIT: This is for 3x3
 
Last edited:
Well there's different guide lines to follow when making a scrambler. First, will it only be 3x3, or will it include 4x4 5x5 pyra sq-1 etc.? Each of which is completely different in the way they should be scrambled.

You should really be experienced enough to know what is and what isn't a valid scramble to start making this.
 
This is pseudocode of what my scramblers look like:

Code:
previousMove = 0
for scrambleLength{
	currentMove = random(1,3)
	while currentMove=previousMove {
		currentMove = random(1,3)
	}
	modifier = random(1,3)
	movePart2 = random(1,2)
	if(movePart2==1){
		if(currentMove==1){
			print "F"
		}
		if(currentMove==2){
			print "R"
		}
		if(currentMove==3){
			print "U"
		}
	}else{
		if(currentMove==1){
			print "B"
		}
		if(currentMove==2){
			print "L"
		}
		if(currentMove==3){
			print "D"
		}
	}
	if(modifier==2){
		print "'"
	}
	if(modifier==3){
		print "2"
	}
	print " "
	previousMove = currentMove
}

I determine what moves to do in two steps. I first choose a random number between 1 and 3 which may not be the same as the previous one and a random number between 1 and 2 two finally determine the move. This avoids situations such as F F' or F B F'. I choose the modifier seperately.
 
You could use a library to call these javascript routines for you (spidermonkey, for example) and then extract the results.

Another idea: Generate a random (yet possible) cube state and feed Cube Explorer (through it's http-based API) with it.
 
Last edited:
hi, i'v just converted that code up there into a visual basic code and modified few things, but guidlines are still the same :)

Code:
Dim currentMove As Integer
Dim PrevMove As Integer
Dim modifier As Integer
Dim movepart2 As Integer

Label1 = ""
'---
PrevMove = 0

For i = 1 To 25

Randomize
currentMove = (2 * Rnd)

While currentMove = PrevMove
    currentMove = (2 * Rnd)
Wend

modifier = (2 * Rnd)
movepart2 = (1 * Rnd)
If movepart2 = 0 Then
    Select Case currentMove
    Case 0
    Label1 = Label1 + "F"
    Case 1
    Label1 = Label1 + "R"
    Case 2
    Label1 = Label1 + "U"
    End Select
Else
    Select Case currentMove
    Case 0
    Label1 = Label1 + "B"
    Case 1
    Label1 = Label1 + "L"
    Case 2
    Label1 = Label1 + "D"
    End Select
End If

If modifier = 1 Then
    Label1 = Label1 + "'"
End If

If modifier = 2 Then
    Label1 = Label1 + "2"
End If

Label1 = Label1 + " "
PrevMove = currentMove

Next i

PS. u will need a label "Label1" and a command buttom "Command1" for the form

copy paste the code in the command button and it shall work :)
 
i'v just converted that code up there into a visual basic code
Why?
LOL!

Here's code I wrote before I joined the community. It takes a slightly different tactic than others I've seen, mine won't do two turns on the same axis in a row, it picks a new axis every time, then a face on that axis, then a twist. It's in Python.
Code:
def randomtwist():
    axes = "xxxyyyzz"
    faces = { "x": ('L', 'R'),
              "y": ('U', 'D'),
              "z": ('F', 'B') }
    directions = ('', "'", '2')
    axis = ""
    last = ""
    while True:
        while (axis == last):
            axis,direction = choice(axes),choice(directions)
            face = choice(faces[axis])

        last = axis
        yield (face + direction)


def scramble(min = 25, max = 25):
    from random import randint 
    count = randint(min, max)
    seq = []
    for twist in randomtwist():
        seq.append(twist)
        if (len(seq) > count):
            break

    return " ".join(seq)
From how I've heard the old WCA scrambler described, it would allow sequential turns on the same axis (F L or B F') and had a little backtracking to make sure it didn't undo a face turn.

After reading about Dan Hoey's concept of "syllables", I think I'd write a new scrambler to generate random face turns and after every move decide if I'd started a new syllable. If I had, then I'd backtrack to collapse the syllable into it's most concise form, then continue until I have enough turns.

The current WCA scrambler (as I understand it) generates a random position by choosing a random color for each cubie face while making sure it remains a valid state. It then uses a solver to generate the moves to reach that state.
 
Back
Top