# Optimal 2x2 Scrambles for CCT (for versions <=0.9.4)



## masterofthebass (Jan 17, 2010)

Thanks to Tim Sun (who basically translated Jaap's code), I was able to put together a cct scramble plugin for random state, optimal 2x2. Just put the .class file in the scramble plugins folder of your CCT directory.


----------



## Anthony (Jan 17, 2010)

Thanks, I've been hoping someone would do this for a while now.


----------



## Muesli (Jan 17, 2010)

I APPROVE OF THIS!


----------



## puzzlemaster (Jan 17, 2010)

hm...how many moves should it be?


----------



## masterofthebass (Jan 17, 2010)

hmm... Apparently version 0.9.5 already has this, but this plugin will work for earlier versions of CCT (I'm running 0.9.4).


----------



## JustinJ (Jan 17, 2010)

Doesn't CCT 0.9.5 already have optimal 2x2 scrambles? This is good if you're using an older version though, I guess.

Edit: ninja'd


----------



## Kian (Jan 17, 2010)

puzzlemaster said:


> hm...how many moves should it be?



11 or less.


----------



## gpt_kibutz (Jan 18, 2010)

Where can I get CCT 0.9.5? Because my CCT is 0.9.3 and that file doesn't seems to work...
EDIT: Found it, nevermind


----------



## Swordsman Kirby (Jan 18, 2010)

masterofthebass said:


> hmm... Apparently version 0.9.5 already has this, but this plugin will work for earlier versions of CCT (I'm running 0.9.4).



Wasted my time, fool!


----------



## linkmaster03 (Jan 18, 2010)

masterofthebass said:


> who basically translated Jaap's code)



Does anyone have a link to this code? I can't seem to find it.


----------



## Shortey (Jan 18, 2010)

luisgepeto said:


> Where can I get CCT 0.9.5? Because my CCT is 0.9.3 and that file doesn't seems to work...
> EDIT: Found it, nevermind



On Lucas' website of course. 

EDIT: 200th post. =)


----------



## masterofthebass (Jan 18, 2010)

Swordsman Kirby said:


> masterofthebass said:
> 
> 
> > hmm... Apparently version 0.9.5 already has this, but this plugin will work for earlier versions of CCT (I'm running 0.9.4).
> ...



I really didn't want it for cct. I already told you that.



linkmaster03 said:


> masterofthebass said:
> 
> 
> > who basically translated Jaap's code)
> ...



check the source of the official scrambler.


----------



## linkmaster03 (Jan 18, 2010)

masterofthebass said:


> linkmaster03 said:
> 
> 
> > masterofthebass said:
> ...



This scrambler? It doesn't seem to use optimal 2x2 scrambles, unless I am missing something.


----------



## masterofthebass (Jan 18, 2010)

http://www.worldcubeassociation.org/regulations/scrambles/scramble_cube_222.html

that's the scrambler you get when you look in the regulations.


----------



## linkmaster03 (Jan 18, 2010)

Ah, didn't look there. Thanks!


----------



## Swordsman Kirby (Jan 28, 2010)

http://www.jaapsch.net/puzzles/javascript/cube2j.htm

Nubs.


----------



## Cride5 (Jan 28, 2010)

masterofthebass said:


> http://www.worldcubeassociation.org/regulations/scrambles/scramble_cube_222.html
> 
> that's the scrambler you get when you look in the regulations.



Correct me if I'm wrong but technically that isn't a random-state scrambler.

The function which does the scramble is as follows:

```
function mix(){
    initbrd();
    for(var i=0;i<500;i++){
        var f=Math.floor(Math.random()*3+3) + 16*Math.floor(Math.random()*3);
        domove(f);
    }
}
```
...which basically applies 500 random moves to the cube. I know this because I made use of Jaap's solver for the 2x2 scrambler in cTimer, but I had to write supporting code to generate random cube states (code here). Of course, the statistical difference between a 500-move scramble and a random-state scramble will be negligible on a 2x2, but using 500 random moves just seems like an inefficient hack.


----------



## Swordsman Kirby (Feb 4, 2010)

Cride5 said:


> Correct me if I'm wrong but technically that isn't a random-state scrambler.
> 
> The function which does the scramble is as follows:
> 
> ...



It just means that the programmer doesn't really understand what random-state refers to. It's also very very easy to generate a random position; I don't understand why you guys are using such convoluted methods. >_>


----------



## Cride5 (Feb 5, 2010)

Swordsman Kirby said:


> It just means that the programmer doesn't really understand what random-state refers to. It's also very very easy to generate a random position; I don't understand why you guys are using such convoluted methods. >_>



Hmm, is my randomCube() function a bit bloated?? I couldn't think of a more direct algorithm than that :confused:


----------



## Swordsman Kirby (Feb 6, 2010)

Cride5 said:


> Swordsman Kirby said:
> 
> 
> > It just means that the programmer doesn't really understand what random-state refers to. It's also very very easy to generate a random position; I don't understand why you guys are using such convoluted methods. >_>
> ...



Given that Jaap's solver just uses two numbers for the position, you should just be randomly generating those two numbers. I don't know what Dan did to modify the code for CCT, but this is how I generated a random position in the original scrambler:

int p = (int)(Math.random()*5040), o = (int)(Math.random()*729);


----------



## reThinking the Cube (Feb 8, 2010)

Swordsman Kirby said:


> Cride5 said:
> 
> 
> > Swordsman Kirby said:
> ...



I am looking for a trustworthy source of info that shows the distribution for true random state positions (generated by this 2 random# method) according to the #of moves away from solved state. What % of positions generated this way will be 1,2,3,4,5.....11 moves away from solved at the completion of the scramble?


----------



## Cride5 (Feb 8, 2010)

reThinking the Cube said:


> Swordsman Kirby said:
> 
> 
> > Cride5 said:
> ...



p is just an index uniquely identifying all possible permutations of the 8 (actually 7) cubies, and o identifies all possible orientations. The Math.random() function generates random numbers in a uniform distribution between 0(inclusive) and 1(exclusive). Multiplying by 5040 means p will represent one out of every possible permutation with equal probability (similarly for o).

Jaap's script accepts the cube state in facelet form, so I wrote my randomCube() function to supply exactly that, but the search function itself converts this format into an index (the variables are called q and t). Bypassing the facelet format completely would indeed have been much simpler. Oh well..


----------



## hr.mohr (Feb 8, 2010)

[offtopic but related]

Herbert Kociemba has made a java package of the 2-phase algorithm. Perhaps this could be used to make random state 3x3x3 scrambles as well?


----------



## Cride5 (Feb 8, 2010)

hr.mohr said:


> [offtopic but related]
> 
> Herbert Kociemba has made a java package of the 2-phase algorithm. Perhaps this could be used to make random state 3x3x3 scrambles as well?



Implementing 3x3 random-state scrambles in CCT sounds like a great idea. There's a already a java applet, and JS timer which does exactly that.


----------



## Pedro (Feb 9, 2010)

Isn't it implemented on cct 0.9.5?


----------



## deepSubDiver (Feb 9, 2010)

It indeed is. Unfortunately it sometimes seems to cancel the search algorithm and throws exceptions instead of scrambles 
Further than that, it sometimes needs a few seconds to generate the algorithm. I sometimes begin scrambling and just one or two seconds later the algorithm updates, while I was scrambling the old scramble once again.


----------



## Pedro (Feb 9, 2010)

deepSubDiver said:


> It indeed is. Unfortunately it sometimes seems to cancel the search algorithm and throws exceptions instead of scrambles
> Further than that, it sometimes needs a few seconds to generate the algorithm. I sometimes begin scrambling and just one or two seconds later the algorithm updates, while I was scrambling the old scramble once again.



So true 

Is it "fixable"?


----------



## reThinking the Cube (Feb 9, 2010)

masterofthebass said:


> http://www.worldcubeassociation.org/regulations/scrambles/scramble_cube_222.html
> 
> that's the scrambler you get when you look in the regulations.




WR: Javier Paris 2x2x2 1.63'' Murcia Open 2008 

Scramble:F' D2 L2 B' D' B R' D' R' U L' B' L2 U' L2 U2 R2 B2 R2 U2 B2 R2 D R2 D2

How was _THIS_ scramble generated?


----------



## masterofthebass (Feb 9, 2010)

that was back when we still used 25 random moves.


----------



## reThinking the Cube (Feb 9, 2010)

masterofthebass said:


> that was back when we still used 25 random moves.



WR: Javier Paris 2x2x2 1.63'' Murcia Open 2008 

Scramble:F' D2 L2 B' D' B R' D' R' U L' B' L2 U' L2 U2 R2 B2 R2 U2 B2 R2 D R2 D2

Is this scramble 25 random moves?


----------



## masterofthebass (Feb 9, 2010)

looks a lot like it to me...


----------



## reThinking the Cube (Feb 9, 2010)

masterofthebass said:


> looks a lot like it to me...



Looks can be deceiving. Are you 100% sure that it is a 25 move _RANDOM_ scramble?


----------



## masterofthebass (Feb 9, 2010)

reThinking the Cube said:


> masterofthebass said:
> 
> 
> > looks a lot like it to me...
> ...



a you 100% sure you aren't a _RETARDED_ person?


----------



## Caedus (Feb 9, 2010)

masterofthebass said:


> reThinking the Cube said:
> 
> 
> > masterofthebass said:
> ...



Win. Go Dan!
Agreed.


----------



## Stefan (Feb 9, 2010)

CCT has 3x3 random-state scrambles? How do I activate them?


----------



## Caedus (Feb 9, 2010)

Cride5 said:


> hr.mohr said:
> 
> 
> > [offtopic but related]
> ...



I believe they are talk about implementing it in the future.

2x2 is the only random state scrambling I know of so far in CCT

I think the argument about whether the random-state scrambling was random or not was about a different scrambler.


----------



## shelley (Feb 9, 2010)

StefanPochmann said:


> CCT has 3x3 random-state scrambles? How do I activate them?



CCT 0.9.5 has random state scrambles for 3x3. The last testing version I played with did, anyway (I'm still using an older version because 0.9.5 runs slower and uses more memory)


----------



## reThinking the Cube (Feb 9, 2010)

Caedus said:


> masterofthebass said:
> 
> 
> > reThinking the Cube said:
> ...



Fail. That scramble only appears random to retards.


----------



## Faz (Feb 9, 2010)

reThinking the Cube said:


> Caedus said:
> 
> 
> > masterofthebass said:
> ...



Lmao wtf. What is wrong with the scramble?


----------



## reThinking the Cube (Feb 9, 2010)

fazrulz said:


> reThinking the Cube said:
> 
> 
> > Caedus said:
> ...



Lmao wtf. What is wrong with YOU? Are you pretending to be retarded too? 

Hint: What is this? --> (U2 R2 B2 R2 U2 B2 R2)



Spoiler



(U2 R2 B2 R2 U2 B2 R2) = (B2)

I could expose the whole scramble, but then I would spoil it for all you wannabee pompous retards!


----------



## aronpm (Feb 9, 2010)

reThinking the Cube said:


> Hint: What is this? --> (U2 R2 B2 R2 U2 B2 R2)
> 
> 
> 
> ...



Wow! I never thought that applying random moves would give a non-optimal scramble!



reThinking the Cube said:


> I could expose the whole scramble, but then I would spoil it for all you wannabee pompous retards!


Also **** you.


----------



## Swordsman Kirby (Feb 9, 2010)

What is the probability that a 25-move scramble is optimal?



Spoiler



0%, but apparently reThinking the Cube doesn't know that.


----------



## hr.mohr (Feb 9, 2010)

Cride5 said:


> hr.mohr said:
> 
> 
> > [offtopic but related]
> ...



Lucas posted this link in the WCA forum:

http://cube.garron.us/WCA/proposals/random_state_3x3x3/kociemba.html


----------



## Tim Major (Feb 9, 2010)

reThinking the Cube said:


> fazrulz said:
> 
> 
> > reThinking the Cube said:
> ...



It's not our fault. When you do enough 2x2, you get scrambles like this every now and then. It's just random chance. If you toss a coin many times, you'd think it's normally 50/50 chance. That doesn't stop there from being ten heads in a row. It's just chance. It' _RANDOM._


----------



## Henrik (Feb 9, 2010)

reThinking the Cube said:


> masterofthebass said:
> 
> 
> > http://www.worldcubeassociation.org/regulations/scrambles/scramble_cube_222.html
> ...



As far as I know the program was designed to just pick a letter and a number. It did not think of a random position for the cube, but just picked a random letter. Only in the later versions of the official scrambler "looked" at the cube and picked one of the random states and the generated a scramble.

thats how I understand the old versions of the scramblers.


----------



## Lucas Garron (Feb 9, 2010)

StefanPochmann said:


> CCT has 3x3 random-state scrambles? How do I activate them?


Ask Jeremy for his beta version. It's not in the main release because it's slow to load, and I don't think he created a "initialize-kociemba-after-startup" version.

Henrik: You're mainly saying the right thing, but cumbersomely phrased and inaccurate. In particular, current 2x2x2 scrambles are not random-state. Not your fault, but I tend to cringe at wrong information that someone might read and then use/retell as if it were true.


----------



## Henrik (Feb 9, 2010)

Lucas:
Yea as my first language is not English, but I do try to phrase the best way I know.

I can speak fluently, but writing and phrasing,,, nope 

Yea my fault about random-state scrambles in the new version.

I would have hope you or someone else could have said it better than me, so I tried my best.


----------



## Cride5 (Feb 9, 2010)

hr.mohr said:


> Lucas posted this link in the WCA forum:
> 
> http://cube.garron.us/WCA/proposals/random_state_3x3x3/kociemba.html



I tried it using:
Ubuntu 8.04.4 LTS
Linux 2.6.24-27-generic kernel
Firefox 3.0.17 browser
Sun java 1.6.0_17-b04

... and it crashed the browser :/


----------



## jfly (Feb 16, 2010)

Cride5 said:


> hr.mohr said:
> 
> 
> > Lucas posted this link in the WCA forum:
> ...


Haha, seriously? Lame. Any stack traces or the like to work with? I know you already did something similar with your javascript timer, so you must have some idea of what could go wrong.


----------



## Cride5 (Feb 16, 2010)

j-fly said:


> Cride5 said:
> 
> 
> > ... and it crashed the browser :/
> ...



Well what it does is cause the browser to hang, with the CPU sitting at 100%. I've left it for a good few minutes, with no change. Since there's no actual error produced by the applet, there won't be any stack trace.

The only thing I can think of is that perhaps the requirements set for the search algorithm are too high. I think on my implementation, for the call to Search.solution() I use 25 for max depth and 60 sec for max search time. As well as that, I also have a buffer storing generated scrambles so that the solver can feed it in a separate thread while previously generated scrambles can be served to the user instantaneously.


----------



## jfly (Feb 16, 2010)

Interesting. I still don't see exactly why my implementation would hang at 100% for you, but your solution is definitely the better one. How big a pool of pre-generated scrambles do you keep? I wish there was something we could do about the initialization time of the applet. For cct I hacked in the ability to write the pruning tables to disk and read them back upon startup. That gave a bit of a performance boost.


----------



## Cride5 (Feb 16, 2010)

I keep 4 scrambles in the buffer. The startup is a bit of an issue, but unfortunately saving to disk isn't as easy in a webapp. It requires deploying the program as a signed applet, which means it has much more control over the client's comp. Many folks (including myslef) aren't very comfortable with this.

With regards to the source details ... I've sent you a pm.


----------



## Cride5 (Apr 14, 2010)

Swordsman Kirby said:


> Cride5 said:
> 
> 
> > Swordsman Kirby said:
> ...



BUMP: I've finally gotten round to fixing the scramble generator in the light of SK's comments.

For convenience, theres a page to generate the scrambles here: 
http://www.ctimer.co.uk/solver2x2.html

And the code which does it is here:
http://www.ctimer.co.uk/solver2x2.js

I've also updated cTimer with the new changes.

Folks are welcome to use the code in solver2x2.js provided permission is sought from Jaap Scherphuis before-hand. To make use of the code, simply include solver2x2.js in your application and make a call to: initSolver2x2() on page load, then use calls to genScramble2x2() to return your scramble.


----------



## Parad0x13 (Jan 1, 2015)

Cride5 said:


> BUMP: I've finally gotten round to fixing the scramble generator in the light of SK's comments.
> 
> For convenience, theres a page to generate the scrambles here:
> http://www.ctimer.co.uk/solver2x2.html
> ...



Hey all, I rewrote his code in Objective-C for iOS devices. GLHF!

```
https://github.com/bryanandhallie/Cride5Solver
```


----------

