cube-state-engine 1.1.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -1
- package/dist/index.d.mts +73 -1
- package/dist/index.d.ts +73 -1
- package/dist/index.js +69 -2
- package/dist/index.mjs +69 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,12 +18,14 @@ A core state manager designed to integrate with custom 3D cube models. This engi
|
|
|
18
18
|
| `isSolved()` | Checks if the cube is solved. | `boolean` |
|
|
19
19
|
| `state()` | Returns the current state of the cube as an object representing each face. | `object` |
|
|
20
20
|
| `getMoves(asString?: boolean)` | Returns the history of all movements; as string if `true` (default), or as array if `false`. | `string / string[]` |
|
|
21
|
-
| `
|
|
21
|
+
| `reset()` | Resets the cube to the solved state and clears the move history. | `void` |
|
|
22
|
+
| `applyMoves(sequence: string, options?: {record?: boolean})` | Applies a sequence of moves (supports U, D, L, R, F, B, x, y, z, M, Dw, Uw, Rw, Lw with ', 2). | `void` |
|
|
22
23
|
| `rotateU(clockwise?: boolean)` | Rotates the **Upper** layer clockwise or counterclockwise. | `void` |
|
|
23
24
|
| `rotateD(clockwise?: boolean)` | Rotates the **Down** layer clockwise or counterclockwise. | `void` |
|
|
24
25
|
| `rotateL(clockwise?: boolean)` | Rotates the **Left** layer clockwise or counterclockwise. | `void` |
|
|
25
26
|
| `rotateR(clockwise?: boolean)` | Rotates the **Right** layer clockwise or counterclockwise. | `void` |
|
|
26
27
|
| `rotateF(clockwise?: boolean)` | Rotates the **Front** layer clockwise or counterclockwise. | `void` |
|
|
28
|
+
| `rotateB(clockwise?: boolean)` | Rotates the **Back** layer clockwise or counterclockwise. | `void` |
|
|
27
29
|
| `rotateX(clockwise?: boolean)` | Rotates the cube along the **X-axis** clockwise or counterclockwise. | `void` |
|
|
28
30
|
| `rotateY(clockwise?: boolean)` | Rotates the cube along the **Y-axis** clockwise or counterclockwise. | `void` |
|
|
29
31
|
| `rotateZ(clockwise?: boolean)` | Rotates the cube along the **Z-axis** clockwise or counterclockwise. | `void` |
|
|
@@ -74,6 +76,11 @@ console.log(cube.state());
|
|
|
74
76
|
console.log(cube.getMoves(true)); // "U Dw Dw' M2 ..."
|
|
75
77
|
console.log(cube.getMoves(false)); // ["U", "Dw", "Dw'", "M", "M"]
|
|
76
78
|
|
|
79
|
+
// Reset the cube to solved state and clear history
|
|
80
|
+
cube.reset();
|
|
81
|
+
console.log(cube.isSolved()); // true
|
|
82
|
+
console.log(cube.getMoves(false)); // []
|
|
83
|
+
|
|
77
84
|
// Rotate the cube along the Y-axis
|
|
78
85
|
cube.rotateY(false);
|
|
79
86
|
```
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
class CubeEngine {
|
|
2
2
|
MOVES = [];
|
|
3
3
|
|
|
4
|
-
constructor(initialScramble) {
|
|
4
|
+
constructor(initialScramble = "") {
|
|
5
5
|
// If an initial scramble string is provided, apply it without recording moves
|
|
6
6
|
if (typeof initialScramble === "string" && initialScramble.trim().length > 0) {
|
|
7
7
|
this.#applyMovesFromString(initialScramble, false);
|
|
@@ -116,6 +116,33 @@ class CubeEngine {
|
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
+
/**
|
|
120
|
+
* Rotates the (BACK) layer clockwise or counterclockwise.
|
|
121
|
+
*/
|
|
122
|
+
rotateB(clockwise = true) {
|
|
123
|
+
if (clockwise) {
|
|
124
|
+
this.#rotateB(true);
|
|
125
|
+
this.MOVES.push("B");
|
|
126
|
+
} else {
|
|
127
|
+
this.#rotateB(false);
|
|
128
|
+
this.MOVES.push("B'");
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
#rotateB(clockwise = true) {
|
|
133
|
+
// Implement B as y2 F y2
|
|
134
|
+
// Clockwise/counterclockwise direction is preserved through y2 conjugation
|
|
135
|
+
this.#rotateY(true);
|
|
136
|
+
this.#rotateY(true);
|
|
137
|
+
if (clockwise) {
|
|
138
|
+
this.#rotateF(true);
|
|
139
|
+
} else {
|
|
140
|
+
this.#rotateF(false);
|
|
141
|
+
}
|
|
142
|
+
this.#rotateY(false);
|
|
143
|
+
this.#rotateY(false);
|
|
144
|
+
}
|
|
145
|
+
|
|
119
146
|
/**
|
|
120
147
|
* Rotates the (RIGHT) layer clockwise or counterclockwise.
|
|
121
148
|
*/
|
|
@@ -513,6 +540,45 @@ class CubeEngine {
|
|
|
513
540
|
return asString ? this.MOVES.join(" ") : this.MOVES;
|
|
514
541
|
}
|
|
515
542
|
|
|
543
|
+
/**
|
|
544
|
+
* Resets the cube to the solved state and clears the move history.
|
|
545
|
+
*/
|
|
546
|
+
reset() {
|
|
547
|
+
this.STATES = {
|
|
548
|
+
UPPER: [
|
|
549
|
+
[COLOR.W[0], COLOR.W[1], COLOR.W[2]],
|
|
550
|
+
[COLOR.W[3], COLOR.W[4], COLOR.W[5]],
|
|
551
|
+
[COLOR.W[6], COLOR.W[7], COLOR.W[8]],
|
|
552
|
+
],
|
|
553
|
+
LEFT: [
|
|
554
|
+
[COLOR.O[0], COLOR.O[1], COLOR.O[2]],
|
|
555
|
+
[COLOR.O[3], COLOR.O[4], COLOR.O[5]],
|
|
556
|
+
[COLOR.O[6], COLOR.O[7], COLOR.O[8]],
|
|
557
|
+
],
|
|
558
|
+
FRONT: [
|
|
559
|
+
[COLOR.G[0], COLOR.G[1], COLOR.G[2]],
|
|
560
|
+
[COLOR.G[3], COLOR.G[4], COLOR.G[5]],
|
|
561
|
+
[COLOR.G[6], COLOR.G[7], COLOR.G[8]],
|
|
562
|
+
],
|
|
563
|
+
RIGHT: [
|
|
564
|
+
[COLOR.R[0], COLOR.R[1], COLOR.R[2]],
|
|
565
|
+
[COLOR.R[3], COLOR.R[4], COLOR.R[5]],
|
|
566
|
+
[COLOR.R[6], COLOR.R[7], COLOR.R[8]],
|
|
567
|
+
],
|
|
568
|
+
BACK: [
|
|
569
|
+
[COLOR.B[0], COLOR.B[1], COLOR.B[2]],
|
|
570
|
+
[COLOR.B[3], COLOR.B[4], COLOR.B[5]],
|
|
571
|
+
[COLOR.B[6], COLOR.B[7], COLOR.B[8]],
|
|
572
|
+
],
|
|
573
|
+
DOWN: [
|
|
574
|
+
[COLOR.Y[0], COLOR.Y[1], COLOR.Y[2]],
|
|
575
|
+
[COLOR.Y[3], COLOR.Y[4], COLOR.Y[5]],
|
|
576
|
+
[COLOR.Y[6], COLOR.Y[7], COLOR.Y[8]],
|
|
577
|
+
],
|
|
578
|
+
};
|
|
579
|
+
this.MOVES = [];
|
|
580
|
+
}
|
|
581
|
+
|
|
516
582
|
/**
|
|
517
583
|
* Applies a sequence of moves provided as a string.
|
|
518
584
|
* Supports: U, D, L, R, F, x, y, z; slice moves: M; and wide moves: Dw, Uw, Rw, Lw with optional ' for counterclockwise and 2 for double turns.
|
|
@@ -623,6 +689,12 @@ class CubeEngine {
|
|
|
623
689
|
() => (record ? this.rotateF(false) : this.#rotateF(false))
|
|
624
690
|
);
|
|
625
691
|
break;
|
|
692
|
+
case 'B':
|
|
693
|
+
exec(
|
|
694
|
+
() => (record ? this.rotateB(true) : this.#rotateB(true)),
|
|
695
|
+
() => (record ? this.rotateB(false) : this.#rotateB(false))
|
|
696
|
+
);
|
|
697
|
+
break;
|
|
626
698
|
case 'x':
|
|
627
699
|
exec(
|
|
628
700
|
() => (record ? this.rotateX(true) : this.#rotateX(true)),
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
class CubeEngine {
|
|
2
2
|
MOVES = [];
|
|
3
3
|
|
|
4
|
-
constructor(initialScramble) {
|
|
4
|
+
constructor(initialScramble = "") {
|
|
5
5
|
// If an initial scramble string is provided, apply it without recording moves
|
|
6
6
|
if (typeof initialScramble === "string" && initialScramble.trim().length > 0) {
|
|
7
7
|
this.#applyMovesFromString(initialScramble, false);
|
|
@@ -116,6 +116,33 @@ class CubeEngine {
|
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
+
/**
|
|
120
|
+
* Rotates the (BACK) layer clockwise or counterclockwise.
|
|
121
|
+
*/
|
|
122
|
+
rotateB(clockwise = true) {
|
|
123
|
+
if (clockwise) {
|
|
124
|
+
this.#rotateB(true);
|
|
125
|
+
this.MOVES.push("B");
|
|
126
|
+
} else {
|
|
127
|
+
this.#rotateB(false);
|
|
128
|
+
this.MOVES.push("B'");
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
#rotateB(clockwise = true) {
|
|
133
|
+
// Implement B as y2 F y2
|
|
134
|
+
// Clockwise/counterclockwise direction is preserved through y2 conjugation
|
|
135
|
+
this.#rotateY(true);
|
|
136
|
+
this.#rotateY(true);
|
|
137
|
+
if (clockwise) {
|
|
138
|
+
this.#rotateF(true);
|
|
139
|
+
} else {
|
|
140
|
+
this.#rotateF(false);
|
|
141
|
+
}
|
|
142
|
+
this.#rotateY(false);
|
|
143
|
+
this.#rotateY(false);
|
|
144
|
+
}
|
|
145
|
+
|
|
119
146
|
/**
|
|
120
147
|
* Rotates the (RIGHT) layer clockwise or counterclockwise.
|
|
121
148
|
*/
|
|
@@ -513,6 +540,45 @@ class CubeEngine {
|
|
|
513
540
|
return asString ? this.MOVES.join(" ") : this.MOVES;
|
|
514
541
|
}
|
|
515
542
|
|
|
543
|
+
/**
|
|
544
|
+
* Resets the cube to the solved state and clears the move history.
|
|
545
|
+
*/
|
|
546
|
+
reset() {
|
|
547
|
+
this.STATES = {
|
|
548
|
+
UPPER: [
|
|
549
|
+
[COLOR.W[0], COLOR.W[1], COLOR.W[2]],
|
|
550
|
+
[COLOR.W[3], COLOR.W[4], COLOR.W[5]],
|
|
551
|
+
[COLOR.W[6], COLOR.W[7], COLOR.W[8]],
|
|
552
|
+
],
|
|
553
|
+
LEFT: [
|
|
554
|
+
[COLOR.O[0], COLOR.O[1], COLOR.O[2]],
|
|
555
|
+
[COLOR.O[3], COLOR.O[4], COLOR.O[5]],
|
|
556
|
+
[COLOR.O[6], COLOR.O[7], COLOR.O[8]],
|
|
557
|
+
],
|
|
558
|
+
FRONT: [
|
|
559
|
+
[COLOR.G[0], COLOR.G[1], COLOR.G[2]],
|
|
560
|
+
[COLOR.G[3], COLOR.G[4], COLOR.G[5]],
|
|
561
|
+
[COLOR.G[6], COLOR.G[7], COLOR.G[8]],
|
|
562
|
+
],
|
|
563
|
+
RIGHT: [
|
|
564
|
+
[COLOR.R[0], COLOR.R[1], COLOR.R[2]],
|
|
565
|
+
[COLOR.R[3], COLOR.R[4], COLOR.R[5]],
|
|
566
|
+
[COLOR.R[6], COLOR.R[7], COLOR.R[8]],
|
|
567
|
+
],
|
|
568
|
+
BACK: [
|
|
569
|
+
[COLOR.B[0], COLOR.B[1], COLOR.B[2]],
|
|
570
|
+
[COLOR.B[3], COLOR.B[4], COLOR.B[5]],
|
|
571
|
+
[COLOR.B[6], COLOR.B[7], COLOR.B[8]],
|
|
572
|
+
],
|
|
573
|
+
DOWN: [
|
|
574
|
+
[COLOR.Y[0], COLOR.Y[1], COLOR.Y[2]],
|
|
575
|
+
[COLOR.Y[3], COLOR.Y[4], COLOR.Y[5]],
|
|
576
|
+
[COLOR.Y[6], COLOR.Y[7], COLOR.Y[8]],
|
|
577
|
+
],
|
|
578
|
+
};
|
|
579
|
+
this.MOVES = [];
|
|
580
|
+
}
|
|
581
|
+
|
|
516
582
|
/**
|
|
517
583
|
* Applies a sequence of moves provided as a string.
|
|
518
584
|
* Supports: U, D, L, R, F, x, y, z; slice moves: M; and wide moves: Dw, Uw, Rw, Lw with optional ' for counterclockwise and 2 for double turns.
|
|
@@ -623,6 +689,12 @@ class CubeEngine {
|
|
|
623
689
|
() => (record ? this.rotateF(false) : this.#rotateF(false))
|
|
624
690
|
);
|
|
625
691
|
break;
|
|
692
|
+
case 'B':
|
|
693
|
+
exec(
|
|
694
|
+
() => (record ? this.rotateB(true) : this.#rotateB(true)),
|
|
695
|
+
() => (record ? this.rotateB(false) : this.#rotateB(false))
|
|
696
|
+
);
|
|
697
|
+
break;
|
|
626
698
|
case 'x':
|
|
627
699
|
exec(
|
|
628
700
|
() => (record ? this.rotateX(true) : this.#rotateX(true)),
|
package/dist/index.js
CHANGED
|
@@ -45,9 +45,9 @@ __export(src_exports, {
|
|
|
45
45
|
CubeEngine: () => CubeEngine
|
|
46
46
|
});
|
|
47
47
|
module.exports = __toCommonJS(src_exports);
|
|
48
|
-
var _CubeEngine_instances, rotateU_fn, rotateF_fn, rotateR_fn, rotateL_fn, rotateD_fn, rotateDw_fn, rotateUw_fn, rotateRw_fn, rotateLw_fn, rotateM_fn, rotateX_fn, rotateZ_fn, rotateY_fn, switchMatrix_fn, specialFlip_fn, applyMovesFromString_fn;
|
|
48
|
+
var _CubeEngine_instances, rotateU_fn, rotateF_fn, rotateB_fn, rotateR_fn, rotateL_fn, rotateD_fn, rotateDw_fn, rotateUw_fn, rotateRw_fn, rotateLw_fn, rotateM_fn, rotateX_fn, rotateZ_fn, rotateY_fn, switchMatrix_fn, specialFlip_fn, applyMovesFromString_fn;
|
|
49
49
|
var CubeEngine = class {
|
|
50
|
-
constructor(initialScramble) {
|
|
50
|
+
constructor(initialScramble = "") {
|
|
51
51
|
__privateAdd(this, _CubeEngine_instances);
|
|
52
52
|
__publicField(this, "MOVES", []);
|
|
53
53
|
// States object for the rotation
|
|
@@ -118,6 +118,18 @@ var CubeEngine = class {
|
|
|
118
118
|
this.MOVES.push("F'");
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* Rotates the (BACK) layer clockwise or counterclockwise.
|
|
123
|
+
*/
|
|
124
|
+
rotateB(clockwise = true) {
|
|
125
|
+
if (clockwise) {
|
|
126
|
+
__privateMethod(this, _CubeEngine_instances, rotateB_fn).call(this, true);
|
|
127
|
+
this.MOVES.push("B");
|
|
128
|
+
} else {
|
|
129
|
+
__privateMethod(this, _CubeEngine_instances, rotateB_fn).call(this, false);
|
|
130
|
+
this.MOVES.push("B'");
|
|
131
|
+
}
|
|
132
|
+
}
|
|
121
133
|
/**
|
|
122
134
|
* Rotates the (RIGHT) layer clockwise or counterclockwise.
|
|
123
135
|
*/
|
|
@@ -281,6 +293,44 @@ var CubeEngine = class {
|
|
|
281
293
|
getMoves(asString = true) {
|
|
282
294
|
return asString ? this.MOVES.join(" ") : this.MOVES;
|
|
283
295
|
}
|
|
296
|
+
/**
|
|
297
|
+
* Resets the cube to the solved state and clears the move history.
|
|
298
|
+
*/
|
|
299
|
+
reset() {
|
|
300
|
+
this.STATES = {
|
|
301
|
+
UPPER: [
|
|
302
|
+
[COLOR.W[0], COLOR.W[1], COLOR.W[2]],
|
|
303
|
+
[COLOR.W[3], COLOR.W[4], COLOR.W[5]],
|
|
304
|
+
[COLOR.W[6], COLOR.W[7], COLOR.W[8]]
|
|
305
|
+
],
|
|
306
|
+
LEFT: [
|
|
307
|
+
[COLOR.O[0], COLOR.O[1], COLOR.O[2]],
|
|
308
|
+
[COLOR.O[3], COLOR.O[4], COLOR.O[5]],
|
|
309
|
+
[COLOR.O[6], COLOR.O[7], COLOR.O[8]]
|
|
310
|
+
],
|
|
311
|
+
FRONT: [
|
|
312
|
+
[COLOR.G[0], COLOR.G[1], COLOR.G[2]],
|
|
313
|
+
[COLOR.G[3], COLOR.G[4], COLOR.G[5]],
|
|
314
|
+
[COLOR.G[6], COLOR.G[7], COLOR.G[8]]
|
|
315
|
+
],
|
|
316
|
+
RIGHT: [
|
|
317
|
+
[COLOR.R[0], COLOR.R[1], COLOR.R[2]],
|
|
318
|
+
[COLOR.R[3], COLOR.R[4], COLOR.R[5]],
|
|
319
|
+
[COLOR.R[6], COLOR.R[7], COLOR.R[8]]
|
|
320
|
+
],
|
|
321
|
+
BACK: [
|
|
322
|
+
[COLOR.B[0], COLOR.B[1], COLOR.B[2]],
|
|
323
|
+
[COLOR.B[3], COLOR.B[4], COLOR.B[5]],
|
|
324
|
+
[COLOR.B[6], COLOR.B[7], COLOR.B[8]]
|
|
325
|
+
],
|
|
326
|
+
DOWN: [
|
|
327
|
+
[COLOR.Y[0], COLOR.Y[1], COLOR.Y[2]],
|
|
328
|
+
[COLOR.Y[3], COLOR.Y[4], COLOR.Y[5]],
|
|
329
|
+
[COLOR.Y[6], COLOR.Y[7], COLOR.Y[8]]
|
|
330
|
+
]
|
|
331
|
+
};
|
|
332
|
+
this.MOVES = [];
|
|
333
|
+
}
|
|
284
334
|
/**
|
|
285
335
|
* Applies a sequence of moves provided as a string.
|
|
286
336
|
* Supports: U, D, L, R, F, x, y, z; slice moves: M; and wide moves: Dw, Uw, Rw, Lw with optional ' for counterclockwise and 2 for double turns.
|
|
@@ -327,6 +377,17 @@ rotateF_fn = function(clockwise = true) {
|
|
|
327
377
|
__privateMethod(this, _CubeEngine_instances, rotateX_fn).call(this, false);
|
|
328
378
|
}
|
|
329
379
|
};
|
|
380
|
+
rotateB_fn = function(clockwise = true) {
|
|
381
|
+
__privateMethod(this, _CubeEngine_instances, rotateY_fn).call(this, true);
|
|
382
|
+
__privateMethod(this, _CubeEngine_instances, rotateY_fn).call(this, true);
|
|
383
|
+
if (clockwise) {
|
|
384
|
+
__privateMethod(this, _CubeEngine_instances, rotateF_fn).call(this, true);
|
|
385
|
+
} else {
|
|
386
|
+
__privateMethod(this, _CubeEngine_instances, rotateF_fn).call(this, false);
|
|
387
|
+
}
|
|
388
|
+
__privateMethod(this, _CubeEngine_instances, rotateY_fn).call(this, false);
|
|
389
|
+
__privateMethod(this, _CubeEngine_instances, rotateY_fn).call(this, false);
|
|
390
|
+
};
|
|
330
391
|
rotateR_fn = function(clockwise = true) {
|
|
331
392
|
if (clockwise) {
|
|
332
393
|
__privateMethod(this, _CubeEngine_instances, rotateY_fn).call(this, true);
|
|
@@ -596,6 +657,12 @@ applyMovesFromString_fn = function(sequence, record = true) {
|
|
|
596
657
|
() => record ? this.rotateF(false) : __privateMethod(this, _CubeEngine_instances, rotateF_fn).call(this, false)
|
|
597
658
|
);
|
|
598
659
|
break;
|
|
660
|
+
case "B":
|
|
661
|
+
exec(
|
|
662
|
+
() => record ? this.rotateB(true) : __privateMethod(this, _CubeEngine_instances, rotateB_fn).call(this, true),
|
|
663
|
+
() => record ? this.rotateB(false) : __privateMethod(this, _CubeEngine_instances, rotateB_fn).call(this, false)
|
|
664
|
+
);
|
|
665
|
+
break;
|
|
599
666
|
case "x":
|
|
600
667
|
exec(
|
|
601
668
|
() => record ? this.rotateX(true) : __privateMethod(this, _CubeEngine_instances, rotateX_fn).call(this, true),
|
package/dist/index.mjs
CHANGED
|
@@ -23,9 +23,9 @@ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot
|
|
|
23
23
|
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
24
24
|
|
|
25
25
|
// src/index.js
|
|
26
|
-
var _CubeEngine_instances, rotateU_fn, rotateF_fn, rotateR_fn, rotateL_fn, rotateD_fn, rotateDw_fn, rotateUw_fn, rotateRw_fn, rotateLw_fn, rotateM_fn, rotateX_fn, rotateZ_fn, rotateY_fn, switchMatrix_fn, specialFlip_fn, applyMovesFromString_fn;
|
|
26
|
+
var _CubeEngine_instances, rotateU_fn, rotateF_fn, rotateB_fn, rotateR_fn, rotateL_fn, rotateD_fn, rotateDw_fn, rotateUw_fn, rotateRw_fn, rotateLw_fn, rotateM_fn, rotateX_fn, rotateZ_fn, rotateY_fn, switchMatrix_fn, specialFlip_fn, applyMovesFromString_fn;
|
|
27
27
|
var CubeEngine = class {
|
|
28
|
-
constructor(initialScramble) {
|
|
28
|
+
constructor(initialScramble = "") {
|
|
29
29
|
__privateAdd(this, _CubeEngine_instances);
|
|
30
30
|
__publicField(this, "MOVES", []);
|
|
31
31
|
// States object for the rotation
|
|
@@ -96,6 +96,18 @@ var CubeEngine = class {
|
|
|
96
96
|
this.MOVES.push("F'");
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* Rotates the (BACK) layer clockwise or counterclockwise.
|
|
101
|
+
*/
|
|
102
|
+
rotateB(clockwise = true) {
|
|
103
|
+
if (clockwise) {
|
|
104
|
+
__privateMethod(this, _CubeEngine_instances, rotateB_fn).call(this, true);
|
|
105
|
+
this.MOVES.push("B");
|
|
106
|
+
} else {
|
|
107
|
+
__privateMethod(this, _CubeEngine_instances, rotateB_fn).call(this, false);
|
|
108
|
+
this.MOVES.push("B'");
|
|
109
|
+
}
|
|
110
|
+
}
|
|
99
111
|
/**
|
|
100
112
|
* Rotates the (RIGHT) layer clockwise or counterclockwise.
|
|
101
113
|
*/
|
|
@@ -259,6 +271,44 @@ var CubeEngine = class {
|
|
|
259
271
|
getMoves(asString = true) {
|
|
260
272
|
return asString ? this.MOVES.join(" ") : this.MOVES;
|
|
261
273
|
}
|
|
274
|
+
/**
|
|
275
|
+
* Resets the cube to the solved state and clears the move history.
|
|
276
|
+
*/
|
|
277
|
+
reset() {
|
|
278
|
+
this.STATES = {
|
|
279
|
+
UPPER: [
|
|
280
|
+
[COLOR.W[0], COLOR.W[1], COLOR.W[2]],
|
|
281
|
+
[COLOR.W[3], COLOR.W[4], COLOR.W[5]],
|
|
282
|
+
[COLOR.W[6], COLOR.W[7], COLOR.W[8]]
|
|
283
|
+
],
|
|
284
|
+
LEFT: [
|
|
285
|
+
[COLOR.O[0], COLOR.O[1], COLOR.O[2]],
|
|
286
|
+
[COLOR.O[3], COLOR.O[4], COLOR.O[5]],
|
|
287
|
+
[COLOR.O[6], COLOR.O[7], COLOR.O[8]]
|
|
288
|
+
],
|
|
289
|
+
FRONT: [
|
|
290
|
+
[COLOR.G[0], COLOR.G[1], COLOR.G[2]],
|
|
291
|
+
[COLOR.G[3], COLOR.G[4], COLOR.G[5]],
|
|
292
|
+
[COLOR.G[6], COLOR.G[7], COLOR.G[8]]
|
|
293
|
+
],
|
|
294
|
+
RIGHT: [
|
|
295
|
+
[COLOR.R[0], COLOR.R[1], COLOR.R[2]],
|
|
296
|
+
[COLOR.R[3], COLOR.R[4], COLOR.R[5]],
|
|
297
|
+
[COLOR.R[6], COLOR.R[7], COLOR.R[8]]
|
|
298
|
+
],
|
|
299
|
+
BACK: [
|
|
300
|
+
[COLOR.B[0], COLOR.B[1], COLOR.B[2]],
|
|
301
|
+
[COLOR.B[3], COLOR.B[4], COLOR.B[5]],
|
|
302
|
+
[COLOR.B[6], COLOR.B[7], COLOR.B[8]]
|
|
303
|
+
],
|
|
304
|
+
DOWN: [
|
|
305
|
+
[COLOR.Y[0], COLOR.Y[1], COLOR.Y[2]],
|
|
306
|
+
[COLOR.Y[3], COLOR.Y[4], COLOR.Y[5]],
|
|
307
|
+
[COLOR.Y[6], COLOR.Y[7], COLOR.Y[8]]
|
|
308
|
+
]
|
|
309
|
+
};
|
|
310
|
+
this.MOVES = [];
|
|
311
|
+
}
|
|
262
312
|
/**
|
|
263
313
|
* Applies a sequence of moves provided as a string.
|
|
264
314
|
* Supports: U, D, L, R, F, x, y, z; slice moves: M; and wide moves: Dw, Uw, Rw, Lw with optional ' for counterclockwise and 2 for double turns.
|
|
@@ -305,6 +355,17 @@ rotateF_fn = function(clockwise = true) {
|
|
|
305
355
|
__privateMethod(this, _CubeEngine_instances, rotateX_fn).call(this, false);
|
|
306
356
|
}
|
|
307
357
|
};
|
|
358
|
+
rotateB_fn = function(clockwise = true) {
|
|
359
|
+
__privateMethod(this, _CubeEngine_instances, rotateY_fn).call(this, true);
|
|
360
|
+
__privateMethod(this, _CubeEngine_instances, rotateY_fn).call(this, true);
|
|
361
|
+
if (clockwise) {
|
|
362
|
+
__privateMethod(this, _CubeEngine_instances, rotateF_fn).call(this, true);
|
|
363
|
+
} else {
|
|
364
|
+
__privateMethod(this, _CubeEngine_instances, rotateF_fn).call(this, false);
|
|
365
|
+
}
|
|
366
|
+
__privateMethod(this, _CubeEngine_instances, rotateY_fn).call(this, false);
|
|
367
|
+
__privateMethod(this, _CubeEngine_instances, rotateY_fn).call(this, false);
|
|
368
|
+
};
|
|
308
369
|
rotateR_fn = function(clockwise = true) {
|
|
309
370
|
if (clockwise) {
|
|
310
371
|
__privateMethod(this, _CubeEngine_instances, rotateY_fn).call(this, true);
|
|
@@ -574,6 +635,12 @@ applyMovesFromString_fn = function(sequence, record = true) {
|
|
|
574
635
|
() => record ? this.rotateF(false) : __privateMethod(this, _CubeEngine_instances, rotateF_fn).call(this, false)
|
|
575
636
|
);
|
|
576
637
|
break;
|
|
638
|
+
case "B":
|
|
639
|
+
exec(
|
|
640
|
+
() => record ? this.rotateB(true) : __privateMethod(this, _CubeEngine_instances, rotateB_fn).call(this, true),
|
|
641
|
+
() => record ? this.rotateB(false) : __privateMethod(this, _CubeEngine_instances, rotateB_fn).call(this, false)
|
|
642
|
+
);
|
|
643
|
+
break;
|
|
577
644
|
case "x":
|
|
578
645
|
exec(
|
|
579
646
|
() => record ? this.rotateX(true) : __privateMethod(this, _CubeEngine_instances, rotateX_fn).call(this, true),
|
package/package.json
CHANGED