cube-state-engine 1.2.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 CHANGED
@@ -19,12 +19,13 @@ A core state manager designed to integrate with custom 3D cube models. This engi
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, x, y, z, M, Dw, Uw, Rw, Lw with ', 2). | `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` |
23
23
  | `rotateU(clockwise?: boolean)` | Rotates the **Upper** layer clockwise or counterclockwise. | `void` |
24
24
  | `rotateD(clockwise?: boolean)` | Rotates the **Down** layer clockwise or counterclockwise. | `void` |
25
25
  | `rotateL(clockwise?: boolean)` | Rotates the **Left** layer clockwise or counterclockwise. | `void` |
26
26
  | `rotateR(clockwise?: boolean)` | Rotates the **Right** layer clockwise or counterclockwise. | `void` |
27
27
  | `rotateF(clockwise?: boolean)` | Rotates the **Front** layer clockwise or counterclockwise. | `void` |
28
+ | `rotateB(clockwise?: boolean)` | Rotates the **Back** layer clockwise or counterclockwise. | `void` |
28
29
  | `rotateX(clockwise?: boolean)` | Rotates the cube along the **X-axis** clockwise or counterclockwise. | `void` |
29
30
  | `rotateY(clockwise?: boolean)` | Rotates the cube along the **Y-axis** clockwise or counterclockwise. | `void` |
30
31
  | `rotateZ(clockwise?: boolean)` | Rotates the cube along the **Z-axis** clockwise or counterclockwise. | `void` |
package/dist/index.d.mts CHANGED
@@ -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
  */
@@ -662,6 +689,12 @@ class CubeEngine {
662
689
  () => (record ? this.rotateF(false) : this.#rotateF(false))
663
690
  );
664
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;
665
698
  case 'x':
666
699
  exec(
667
700
  () => (record ? this.rotateX(true) : this.#rotateX(true)),
package/dist/index.d.ts CHANGED
@@ -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
  */
@@ -662,6 +689,12 @@ class CubeEngine {
662
689
  () => (record ? this.rotateF(false) : this.#rotateF(false))
663
690
  );
664
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;
665
698
  case 'x':
666
699
  exec(
667
700
  () => (record ? this.rotateX(true) : this.#rotateX(true)),
package/dist/index.js CHANGED
@@ -45,7 +45,7 @@ __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
50
  constructor(initialScramble = "") {
51
51
  __privateAdd(this, _CubeEngine_instances);
@@ -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
  */
@@ -365,6 +377,17 @@ rotateF_fn = function(clockwise = true) {
365
377
  __privateMethod(this, _CubeEngine_instances, rotateX_fn).call(this, false);
366
378
  }
367
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
+ };
368
391
  rotateR_fn = function(clockwise = true) {
369
392
  if (clockwise) {
370
393
  __privateMethod(this, _CubeEngine_instances, rotateY_fn).call(this, true);
@@ -634,6 +657,12 @@ applyMovesFromString_fn = function(sequence, record = true) {
634
657
  () => record ? this.rotateF(false) : __privateMethod(this, _CubeEngine_instances, rotateF_fn).call(this, false)
635
658
  );
636
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;
637
666
  case "x":
638
667
  exec(
639
668
  () => record ? this.rotateX(true) : __privateMethod(this, _CubeEngine_instances, rotateX_fn).call(this, true),
package/dist/index.mjs CHANGED
@@ -23,7 +23,7 @@ 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
28
  constructor(initialScramble = "") {
29
29
  __privateAdd(this, _CubeEngine_instances);
@@ -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
  */
@@ -343,6 +355,17 @@ rotateF_fn = function(clockwise = true) {
343
355
  __privateMethod(this, _CubeEngine_instances, rotateX_fn).call(this, false);
344
356
  }
345
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
+ };
346
369
  rotateR_fn = function(clockwise = true) {
347
370
  if (clockwise) {
348
371
  __privateMethod(this, _CubeEngine_instances, rotateY_fn).call(this, true);
@@ -612,6 +635,12 @@ applyMovesFromString_fn = function(sequence, record = true) {
612
635
  () => record ? this.rotateF(false) : __privateMethod(this, _CubeEngine_instances, rotateF_fn).call(this, false)
613
636
  );
614
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;
615
644
  case "x":
616
645
  exec(
617
646
  () => record ? this.rotateX(true) : __privateMethod(this, _CubeEngine_instances, rotateX_fn).call(this, true),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cube-state-engine",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "An efficient representation in memory for tracking the Rubik's cube state on each movement.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",