# Scramble generating scripts/algorithms?



## Gerra (Jan 14, 2012)

Hi there, I'm interested on finding any resources that can guide me trough scramble generating.

I want to write a scramble generator script for a lot of puzzle types. Where can I find a good starting point?

I think they are something more difficult that simple random numbers.

Isn't speedsolving the best place to ask this question?


----------



## Lucas Garron (Jan 14, 2012)

What's the purpose, and what language do you want to use?
It's fine to ask in speedsolving, but you should ask a more specific question if you want a useful answer.

Look through the software area to see what you need.

Mark 2, https://github.com/jfly/tnoodle, and PPT have various pieces of sample code for good scramblers.

Jaap's page has a lot of good math explanations.


----------



## Gerra (Jan 14, 2012)

Whoa, you're the guy who made CCT?
Did a great job! Really. Thanks for the response, my pleasure.

Generating scrambles seems too difficult for my timeframe. Or maybe the reason behind the huge codes here - https://github.com/lgarron/mark2/tree/master/inc/scramblers - is the visual display? I'm makin' a timer, and I need only the literal scrambles.

I'll use predefined scrambles for now, or maybe we can collaborate on my project, if interested. I've seen you have C experience as well, I'll drop you a mail in private.


----------



## qqwref (Jan 14, 2012)

Nope, Lucas made Mark 2, but Jeremy Fleischman (and Ryan Zheng) made CCT.

If you want simpler scrambles, you might want to take a look at the code in http://mzrg.com/qqtimer/. The "megascramble" function is a little hard to understand, but it's very general. A typical 3x3x3 scrambler would work something like this:
- Generate a sequence of L, R, U, D, F, B moves, such that (a) the same move doesn't occur twice in a row, and (b) there are no sequences such as "U D U" where the same move gets repeated without changing "axis".
- For each move, add a suffix to specify a random amount of that move. So, for R, we randomly choose between R, R', and R2.
The megascramble function basically generates random moves just like this, and you can specify which moves are in each axis group as well as which suffixes are allowed. Of course, you can just make a separate scramble function for each puzzle if you want. The main idea is to generate random moves that don't have cancellations. 

A lot of modern programs have much more complicated scramblers, which choose a random position and generate a short sequence that solves it. Many of them also have functions to create images (I think all of the Mark 2 and CCT ones do this). Depending on what you want, you can save a lot of space and complexity by getting rid of those features.


----------



## tim (Jan 14, 2012)

Gerra said:


> Generating scrambles seems too difficult for my timeframe. Or maybe the reason behind the huge codes here - https://github.com/lgarron/mark2/tree/master/inc/scramblers - is the visual display? I'm makin' a timer, and I need only the literal scrambles.


 
If you're making a timer in Ruby (or JRuby/whatever), feel free to use this: https://github.com/timhabermaas/scrambler (not random-state, though)

I've also made a tiny(!) API around it: http://scrambler-api.herokuapp.com/3x3x3 (Code). Feel free to fork it and adapt it to your needs.


----------

