hakatashi / smart-cube-timer

Proof-of-concept smart timer for GiiKER
https://hakatashi.github.io/smart-cube-timer/
MIT License
72 stars 22 forks source link

Random scramble #6

Closed timhuff closed 6 years ago

timhuff commented 6 years ago

This code will provide a random scramble.

Cube.initSolver();
const cube = Cube.random();
const solution = cube.solve();
const scramble = Cube.inverse(solution);
hakatashi commented 6 years ago

On many platforms Cube.initSolver() takes several seconds in sync, which means screen is frozen for several times on load. I don't prefer it and am seeking for more lightweight solution.

timhuff commented 6 years ago

Yea, I was bummed about that, too. Though you could put up a "Finding Scramble..." screen. Not great, though. Perhaps I can try to patch the library to make it async. In the meantime, here's a thousand scrambles to provide a bit more variety.

tussosedan commented 6 years ago

The TwistyTimer app also takes a couple of seconds to load the scramble, during which it shows some loading icon. It's okay, cubers expect the scramble generation to take some time. I'm not sure how cstimer does it though, it seems to be in the background there somehow.

tussosedan commented 6 years ago

@hakatashi could you add more scrambles in the meantime? I'm using this a lot and don't want to start repeating scrambles :)

hakatashi commented 6 years ago

@tussosedan Okay. I'll add up to 1000. (currently 500)

Memo: scramble_333.js seems much faster than Cube.js. I got following scores on my Android.

import Cube from 'cubejs';
import 'cubejs/lib/solve';
import scrambo from 'scrambo/lib/scramblers/333';

console.time('scrambo.init');
scrambo.initialize(Math);
console.timeEnd('scrambo.init');
for (const i of Array(10).keys()) {
  console.time('scrambo.scramble');
  scrambo.getRandomScramble();
  console.timeEnd('scrambo.scramble');
}

console.time('cubejs.init');
Cube.initSolver();
console.timeEnd('cubejs.init');
for (const i of Array(10).keys()) {
  console.time('cubejs.scramble');
  Cube.scramble();
  console.timeEnd('cubejs.scramble');
}
scrambo.init: 4026.0478515625ms
scrambo.scramble: 445.650146484375ms
scrambo.scramble: 98.74609375ms
scrambo.scramble: 7.961181640625ms
scrambo.scramble: 226.947265625ms
scrambo.scramble: 38.23388671875ms
scrambo.scramble: 36.613037109375ms
scrambo.scramble: 5.102294921875ms
scrambo.scramble: 71.0361328125ms
scrambo.scramble: 59.135986328125ms
scrambo.scramble: 130.429931640625ms
cubejs.init: 14741.630126953125ms
cubejs.scramble: 2374.02978515625ms
cubejs.scramble: 740.69677734375ms
cubejs.scramble: 1218.901123046875ms
cubejs.scramble: 184.737060546875ms
cubejs.scramble: 151.781982421875ms
cubejs.scramble: 425.2509765625ms
cubejs.scramble: 428.794921875ms
cubejs.scramble: 295.6650390625ms
cubejs.scramble: 674.1103515625ms
cubejs.scramble: 202.23291015625ms
tussosedan commented 6 years ago

@hakatashi how about the official tnoodle, is it faster? https://github.com/thewca/tnoodle/tree/master/tnoodlejs

hakatashi commented 6 years ago

@tussosedan It seems much slower... plus, it's huge (700KB).

import './tnoodle.js';

console.time('tnoodlejs.init')
window.puzzlesLoaded = (puzzles) => {
  console.timeEnd('tnoodlejs.init')
  for (const i of Array(10).keys()) {
    console.time('tnoodlejs.scramble');
    puzzles['333'].generateScramble();
    console.timeEnd('tnoodlejs.scramble');
  }
}
tnoodlejs.init: 1010.31298828125ms
tnoodlejs.scramble: 3216.7578125ms
tnoodlejs.scramble: 983.172119140625ms
tnoodlejs.scramble: 883.116943359375ms
tnoodlejs.scramble: 974.243896484375ms
tnoodlejs.scramble: 861.143798828125ms
tnoodlejs.scramble: 906.15087890625ms
tnoodlejs.scramble: 886.588134765625ms
tnoodlejs.scramble: 907.77099609375ms
tnoodlejs.scramble: 890.77880859375ms
tnoodlejs.scramble: 985.172119140625ms
hakatashi commented 6 years ago

Now we switched to random scrambles generated by scramble_333.js. Initialization is proceeded on background of giiker connection. Feel free to report any performance problems here.