forked from daniel-j/node-two-phase-algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTools.js
More file actions
37 lines (32 loc) · 908 Bytes
/
Tools.js
File metadata and controls
37 lines (32 loc) · 908 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
'use strict';
var CubieCube = require('./CubieCube.js');
var CoordCube = require('./CoordCube.js');
var FaceCube = require('./FaceCube.js');
module.exports = {
verify: function (s) {
var count = new Int32Array(6);
try {
for (var i = 0; i < 54; i++)
count[Color.valueOfStr(s.substring(i, i + 1)).ordinal()]++;
} catch (e) {
return -1;
}
for (var i = 0; i < 6; i++)
if (count[i] != 9)
return -1;
var fc = new FaceCube(s);
var cc = fc.toCubieCube();
return cc.verify();
},
randomCube: function () {
var cc = new CubieCube();
cc.setFlip(~~(Math.random() * CoordCube.N_FLIP));
cc.setTwist(~~(Math.random() * CoordCube.N_TWIST));
do {
cc.setURFtoDLB(~~(Math.random() * CoordCube.N_URFtoDLB));
cc.setURtoBR(~~(Math.random() * CoordCube.N_URtoBR));
} while ((cc.edgeParity() ^ cc.cornerParity()) != 0);
var fc = cc.toFaceCube();
return fc.toString();
}
}