cube-state-engine 1.0.3 → 1.0.5

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
@@ -4,12 +4,19 @@ A core state manager designed to integrate with custom 3D cube models. This engi
4
4
 
5
5
  ---
6
6
 
7
+ ## Installation
8
+
9
+ npm install cube-state-engine
10
+
11
+ ---
12
+
7
13
  ## Methods
8
14
 
9
15
  | Method | Description | Return Type |
10
16
  | ----------------------------- | -------------------------------------------------------------------------- | ----------- |
11
17
  | `isSolved()` | Checks if the cube is solved. | `boolean` |
12
18
  | `state()` | Returns the current state of the cube as an object representing each face. | `object` |
19
+ | `getMoves(asString: boolean)` | Returns the history of all movements made. | `string` |
13
20
  | `rotateU(clockwise: boolean)` | Rotates the **Upper** face clockwise or counterclockwise. | `void` |
14
21
  | `rotateF(clockwise: boolean)` | Rotates the **Front** face clockwise or counterclockwise. | `void` |
15
22
  | `rotateD(clockwise: boolean)` | Rotates the **Down** face clockwise or counterclockwise. | `void` |
package/dist/index.d.mts CHANGED
@@ -1,4 +1,6 @@
1
1
  class CubeEngine {
2
+ MOVES = [];
3
+
2
4
  // States object for the rotation
3
5
  STATES = {
4
6
  UPPER: [
@@ -40,11 +42,20 @@ class CubeEngine {
40
42
  };
41
43
 
42
44
  /**
43
- * Rotates the top (U) layer clockwise or counterclockwise.
45
+ * Rotates the (UPPER) layer clockwise or counterclockwise.
44
46
  */
45
47
  rotateU(clockwise = true) {
46
48
  if (clockwise) {
47
- // Rotate the top layer (UPPER) clockwise
49
+ this.#rotateU(true);
50
+ this.MOVES.push("U");
51
+ } else {
52
+ this.#rotateU(false);
53
+ this.MOVES.push("U'");
54
+ }
55
+ }
56
+
57
+ #rotateU(clockwise = true) {
58
+ if (clockwise) {
48
59
  this.STATES.UPPER = this.#switchMatrix(this.STATES.UPPER, true);
49
60
 
50
61
  const tempFront = [...this.STATES.FRONT[0]];
@@ -57,7 +68,6 @@ class CubeEngine {
57
68
  this.STATES.BACK[0] = [...tempLeft];
58
69
  this.STATES.RIGHT[0] = [...tempBack];
59
70
  } else {
60
- // Rotate the top layer (UPPER) counterclockwise
61
71
  this.STATES.UPPER = this.#switchMatrix(this.STATES.UPPER, false);
62
72
 
63
73
  const tempFront = [...this.STATES.FRONT[0]];
@@ -73,61 +83,110 @@ class CubeEngine {
73
83
  }
74
84
 
75
85
  /**
76
- * Rotates the front (F) layer clockwise or counterclockwise.
86
+ * Rotates the (FRONT) layer clockwise or counterclockwise.
77
87
  */
78
88
  rotateF(clockwise = true) {
79
89
  if (clockwise) {
80
- this.rotateX(true);
81
- this.rotateU(true);
82
- this.rotateX(false);
90
+ this.#rotateF(true);
91
+ this.MOVES.push("F");
83
92
  } else {
84
- this.rotateX(true);
85
- this.rotateU(false);
86
- this.rotateX(false);
93
+ this.#rotateF(false);
94
+ this.MOVES.push("F'");
87
95
  }
88
96
  }
89
97
 
98
+ #rotateF(clockwise = true) {
99
+ if (clockwise) {
100
+ this.#rotateX(true);
101
+ this.#rotateU(true);
102
+ this.#rotateX(false);
103
+ } else {
104
+ this.#rotateX(true);
105
+ this.#rotateU(false);
106
+ this.#rotateX(false);
107
+ }
108
+ }
109
+
110
+ /**
111
+ * Rotates the (RIGHT) layer clockwise or counterclockwise.
112
+ */
90
113
  rotateR(clockwise = true) {
91
114
  if (clockwise) {
92
- this.rotateY(true);
93
- this.rotateX(true);
94
- this.rotateU(true);
95
- this.rotateX(false);
96
- this.rotateY(false);
115
+ this.#rotateR(true);
116
+ this.MOVES.push("R");
117
+ } else {
118
+ this.#rotateR(false);
119
+ this.MOVES.push("R'");
120
+ }
121
+ }
122
+
123
+ #rotateR(clockwise = true) {
124
+ if (clockwise) {
125
+ this.#rotateY(true);
126
+ this.#rotateX(true);
127
+ this.#rotateU(true);
128
+ this.#rotateX(false);
129
+ this.#rotateY(false);
97
130
  } else {
98
- this.rotateY(true);
99
- this.rotateX(true);
100
- this.rotateU(false);
101
- this.rotateX(false);
102
- this.rotateY(false);
131
+ this.#rotateY(true);
132
+ this.#rotateX(true);
133
+ this.#rotateU(false);
134
+ this.#rotateX(false);
135
+ this.#rotateY(false);
103
136
  }
104
137
  }
105
138
 
139
+ /**
140
+ * Rotates the (LEFT) layer clockwise or counterclockwise.
141
+ */
106
142
  rotateL(clockwise = true) {
107
143
  if (clockwise) {
108
- this.rotateY(false);
109
- this.rotateX(true);
110
- this.rotateU(true);
111
- this.rotateX(false);
112
- this.rotateY(true);
144
+ this.#rotateL(true);
145
+ this.MOVES.push("L");
146
+ } else {
147
+ this.#rotateL(false);
148
+ this.MOVES.push("L'");
149
+ }
150
+ }
151
+
152
+ #rotateL(clockwise = true) {
153
+ if (clockwise) {
154
+ this.#rotateY(false);
155
+ this.#rotateX(true);
156
+ this.#rotateU(true);
157
+ this.#rotateX(false);
158
+ this.#rotateY(true);
113
159
  } else {
114
- this.rotateY(false);
115
- this.rotateX(true);
116
- this.rotateU(false);
117
- this.rotateX(false);
118
- this.rotateY(true);
160
+ this.#rotateY(false);
161
+ this.#rotateX(true);
162
+ this.#rotateU(false);
163
+ this.#rotateX(false);
164
+ this.#rotateY(true);
119
165
  }
120
166
  }
121
167
 
168
+ /**
169
+ * Rotates the (DOWN) layer clockwise or counterclockwise.
170
+ */
122
171
  rotateD(clockwise = true) {
123
172
  if (clockwise) {
124
- this.rotateX(true);
125
- this.rotateF(true);
126
- this.rotateX(false);
173
+ this.#rotateD(true);
174
+ this.MOVES.push("D");
175
+ } else {
176
+ this.#rotateD(false);
177
+ this.MOVES.push("D'");
178
+ }
179
+ }
180
+
181
+ #rotateD(clockwise = true) {
182
+ if (clockwise) {
183
+ this.#rotateX(true);
184
+ this.#rotateF(true);
185
+ this.#rotateX(false);
127
186
  } else {
128
- this.rotateX(true);
129
- this.rotateF(false);
130
- this.rotateX(false);
187
+ this.#rotateX(true);
188
+ this.#rotateF(false);
189
+ this.#rotateX(false);
131
190
  }
132
191
  }
133
192
 
@@ -135,6 +194,16 @@ class CubeEngine {
135
194
  * Rotates the (x) axis clockwise or counterclockwise.
136
195
  */
137
196
  rotateX(clockwise = true) {
197
+ if (clockwise) {
198
+ this.#rotateX(true);
199
+ this.MOVES.push("x");
200
+ } else {
201
+ this.#rotateX(false);
202
+ this.MOVES.push("x'");
203
+ }
204
+ }
205
+
206
+ #rotateX(clockwise = true) {
138
207
  const tempFront = structuredClone(this.STATES.FRONT);
139
208
  const tempDown = structuredClone(this.STATES.DOWN);
140
209
  const tempUpper = structuredClone(this.STATES.UPPER);
@@ -143,27 +212,24 @@ class CubeEngine {
143
212
  const tempRight = structuredClone(this.STATES.RIGHT);
144
213
 
145
214
  if (clockwise) {
146
- // Rotate the RIGHT and LEFT layers
215
+ // Balance the rotation
147
216
  this.STATES.LEFT = this.#switchMatrix(tempLeft, false);
148
217
  this.STATES.RIGHT = this.#switchMatrix(tempRight, true);
149
218
 
150
- // Rotation X axis
219
+ // Rotate mid X axis
151
220
  this.STATES.FRONT = [...tempDown];
152
221
  this.STATES.UPPER = [...tempFront];
153
222
 
154
- // Special permutation
223
+ // Special permutation (BACK view elements)
155
224
  this.STATES.BACK = this.#specialFlip(tempUpper);
156
225
  this.STATES.DOWN = this.#specialFlip(tempBack);
157
226
  } else {
158
- // Rotate the RIGHT and LEFT layers
159
227
  this.STATES.LEFT = this.#switchMatrix(tempLeft, true);
160
228
  this.STATES.RIGHT = this.#switchMatrix(tempRight, false);
161
229
 
162
- // Rotation X axis
163
230
  this.STATES.FRONT = [...tempUpper];
164
231
  this.STATES.DOWN = [...tempFront];
165
232
 
166
- // Special permutation
167
233
  this.STATES.BACK = this.#specialFlip(tempDown);
168
234
  this.STATES.UPPER = this.#specialFlip(tempBack);
169
235
  }
@@ -173,6 +239,16 @@ class CubeEngine {
173
239
  * Rotates the (y) axis clockwise or counterclockwise.
174
240
  */
175
241
  rotateY(clockwise = true) {
242
+ if (clockwise) {
243
+ this.#rotateY(true);
244
+ this.MOVES.push("y");
245
+ } else {
246
+ this.#rotateY(false);
247
+ this.MOVES.push("y'");
248
+ }
249
+ }
250
+
251
+ #rotateY(clockwise = true) {
176
252
  const tempFront = structuredClone(this.STATES.FRONT);
177
253
  const tempRight = structuredClone(this.STATES.RIGHT);
178
254
  const tempBack = structuredClone(this.STATES.BACK);
@@ -182,7 +258,6 @@ class CubeEngine {
182
258
  this.STATES.UPPER = this.#switchMatrix(this.STATES.UPPER, true);
183
259
  this.STATES.DOWN = this.#switchMatrix(this.STATES.DOWN, false);
184
260
 
185
- // Rotation X axis
186
261
  this.STATES.FRONT = [...tempRight];
187
262
  this.STATES.RIGHT = [...tempBack];
188
263
  this.STATES.LEFT = [...tempFront];
@@ -191,7 +266,6 @@ class CubeEngine {
191
266
  this.STATES.UPPER = this.#switchMatrix(this.STATES.UPPER, false);
192
267
  this.STATES.DOWN = this.#switchMatrix(this.STATES.DOWN, true);
193
268
 
194
- // Rotation X axis
195
269
  this.STATES.FRONT = [...tempLeft];
196
270
  this.STATES.RIGHT = [...tempFront];
197
271
  this.STATES.LEFT = [...tempBack];
@@ -232,10 +306,6 @@ class CubeEngine {
232
306
  * Logs the current state of the cube.
233
307
  */
234
308
  state() {
235
- console.clear();
236
- console.log({
237
- ...this.STATES,
238
- });
239
309
  return {
240
310
  ...this.STATES,
241
311
  };
@@ -263,6 +333,16 @@ class CubeEngine {
263
333
 
264
334
  return layersSolved.every((isLayerSolved) => isLayerSolved);
265
335
  }
336
+
337
+ /**
338
+ * Returns the history of all movements made.
339
+ *
340
+ * @param {boolean} asString - If true, returns the history as a string; otherwise, returns it as an array.
341
+ * @returns {string|array} The history of movements as an array or string.
342
+ */
343
+ getMoves(asString = true) {
344
+ return asString ? this.MOVES.join(" ") : this.MOVES;
345
+ }
266
346
  }
267
347
 
268
348
  const COLOR = {
package/dist/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  class CubeEngine {
2
+ MOVES = [];
3
+
2
4
  // States object for the rotation
3
5
  STATES = {
4
6
  UPPER: [
@@ -40,11 +42,20 @@ class CubeEngine {
40
42
  };
41
43
 
42
44
  /**
43
- * Rotates the top (U) layer clockwise or counterclockwise.
45
+ * Rotates the (UPPER) layer clockwise or counterclockwise.
44
46
  */
45
47
  rotateU(clockwise = true) {
46
48
  if (clockwise) {
47
- // Rotate the top layer (UPPER) clockwise
49
+ this.#rotateU(true);
50
+ this.MOVES.push("U");
51
+ } else {
52
+ this.#rotateU(false);
53
+ this.MOVES.push("U'");
54
+ }
55
+ }
56
+
57
+ #rotateU(clockwise = true) {
58
+ if (clockwise) {
48
59
  this.STATES.UPPER = this.#switchMatrix(this.STATES.UPPER, true);
49
60
 
50
61
  const tempFront = [...this.STATES.FRONT[0]];
@@ -57,7 +68,6 @@ class CubeEngine {
57
68
  this.STATES.BACK[0] = [...tempLeft];
58
69
  this.STATES.RIGHT[0] = [...tempBack];
59
70
  } else {
60
- // Rotate the top layer (UPPER) counterclockwise
61
71
  this.STATES.UPPER = this.#switchMatrix(this.STATES.UPPER, false);
62
72
 
63
73
  const tempFront = [...this.STATES.FRONT[0]];
@@ -73,61 +83,110 @@ class CubeEngine {
73
83
  }
74
84
 
75
85
  /**
76
- * Rotates the front (F) layer clockwise or counterclockwise.
86
+ * Rotates the (FRONT) layer clockwise or counterclockwise.
77
87
  */
78
88
  rotateF(clockwise = true) {
79
89
  if (clockwise) {
80
- this.rotateX(true);
81
- this.rotateU(true);
82
- this.rotateX(false);
90
+ this.#rotateF(true);
91
+ this.MOVES.push("F");
83
92
  } else {
84
- this.rotateX(true);
85
- this.rotateU(false);
86
- this.rotateX(false);
93
+ this.#rotateF(false);
94
+ this.MOVES.push("F'");
87
95
  }
88
96
  }
89
97
 
98
+ #rotateF(clockwise = true) {
99
+ if (clockwise) {
100
+ this.#rotateX(true);
101
+ this.#rotateU(true);
102
+ this.#rotateX(false);
103
+ } else {
104
+ this.#rotateX(true);
105
+ this.#rotateU(false);
106
+ this.#rotateX(false);
107
+ }
108
+ }
109
+
110
+ /**
111
+ * Rotates the (RIGHT) layer clockwise or counterclockwise.
112
+ */
90
113
  rotateR(clockwise = true) {
91
114
  if (clockwise) {
92
- this.rotateY(true);
93
- this.rotateX(true);
94
- this.rotateU(true);
95
- this.rotateX(false);
96
- this.rotateY(false);
115
+ this.#rotateR(true);
116
+ this.MOVES.push("R");
117
+ } else {
118
+ this.#rotateR(false);
119
+ this.MOVES.push("R'");
120
+ }
121
+ }
122
+
123
+ #rotateR(clockwise = true) {
124
+ if (clockwise) {
125
+ this.#rotateY(true);
126
+ this.#rotateX(true);
127
+ this.#rotateU(true);
128
+ this.#rotateX(false);
129
+ this.#rotateY(false);
97
130
  } else {
98
- this.rotateY(true);
99
- this.rotateX(true);
100
- this.rotateU(false);
101
- this.rotateX(false);
102
- this.rotateY(false);
131
+ this.#rotateY(true);
132
+ this.#rotateX(true);
133
+ this.#rotateU(false);
134
+ this.#rotateX(false);
135
+ this.#rotateY(false);
103
136
  }
104
137
  }
105
138
 
139
+ /**
140
+ * Rotates the (LEFT) layer clockwise or counterclockwise.
141
+ */
106
142
  rotateL(clockwise = true) {
107
143
  if (clockwise) {
108
- this.rotateY(false);
109
- this.rotateX(true);
110
- this.rotateU(true);
111
- this.rotateX(false);
112
- this.rotateY(true);
144
+ this.#rotateL(true);
145
+ this.MOVES.push("L");
146
+ } else {
147
+ this.#rotateL(false);
148
+ this.MOVES.push("L'");
149
+ }
150
+ }
151
+
152
+ #rotateL(clockwise = true) {
153
+ if (clockwise) {
154
+ this.#rotateY(false);
155
+ this.#rotateX(true);
156
+ this.#rotateU(true);
157
+ this.#rotateX(false);
158
+ this.#rotateY(true);
113
159
  } else {
114
- this.rotateY(false);
115
- this.rotateX(true);
116
- this.rotateU(false);
117
- this.rotateX(false);
118
- this.rotateY(true);
160
+ this.#rotateY(false);
161
+ this.#rotateX(true);
162
+ this.#rotateU(false);
163
+ this.#rotateX(false);
164
+ this.#rotateY(true);
119
165
  }
120
166
  }
121
167
 
168
+ /**
169
+ * Rotates the (DOWN) layer clockwise or counterclockwise.
170
+ */
122
171
  rotateD(clockwise = true) {
123
172
  if (clockwise) {
124
- this.rotateX(true);
125
- this.rotateF(true);
126
- this.rotateX(false);
173
+ this.#rotateD(true);
174
+ this.MOVES.push("D");
175
+ } else {
176
+ this.#rotateD(false);
177
+ this.MOVES.push("D'");
178
+ }
179
+ }
180
+
181
+ #rotateD(clockwise = true) {
182
+ if (clockwise) {
183
+ this.#rotateX(true);
184
+ this.#rotateF(true);
185
+ this.#rotateX(false);
127
186
  } else {
128
- this.rotateX(true);
129
- this.rotateF(false);
130
- this.rotateX(false);
187
+ this.#rotateX(true);
188
+ this.#rotateF(false);
189
+ this.#rotateX(false);
131
190
  }
132
191
  }
133
192
 
@@ -135,6 +194,16 @@ class CubeEngine {
135
194
  * Rotates the (x) axis clockwise or counterclockwise.
136
195
  */
137
196
  rotateX(clockwise = true) {
197
+ if (clockwise) {
198
+ this.#rotateX(true);
199
+ this.MOVES.push("x");
200
+ } else {
201
+ this.#rotateX(false);
202
+ this.MOVES.push("x'");
203
+ }
204
+ }
205
+
206
+ #rotateX(clockwise = true) {
138
207
  const tempFront = structuredClone(this.STATES.FRONT);
139
208
  const tempDown = structuredClone(this.STATES.DOWN);
140
209
  const tempUpper = structuredClone(this.STATES.UPPER);
@@ -143,27 +212,24 @@ class CubeEngine {
143
212
  const tempRight = structuredClone(this.STATES.RIGHT);
144
213
 
145
214
  if (clockwise) {
146
- // Rotate the RIGHT and LEFT layers
215
+ // Balance the rotation
147
216
  this.STATES.LEFT = this.#switchMatrix(tempLeft, false);
148
217
  this.STATES.RIGHT = this.#switchMatrix(tempRight, true);
149
218
 
150
- // Rotation X axis
219
+ // Rotate mid X axis
151
220
  this.STATES.FRONT = [...tempDown];
152
221
  this.STATES.UPPER = [...tempFront];
153
222
 
154
- // Special permutation
223
+ // Special permutation (BACK view elements)
155
224
  this.STATES.BACK = this.#specialFlip(tempUpper);
156
225
  this.STATES.DOWN = this.#specialFlip(tempBack);
157
226
  } else {
158
- // Rotate the RIGHT and LEFT layers
159
227
  this.STATES.LEFT = this.#switchMatrix(tempLeft, true);
160
228
  this.STATES.RIGHT = this.#switchMatrix(tempRight, false);
161
229
 
162
- // Rotation X axis
163
230
  this.STATES.FRONT = [...tempUpper];
164
231
  this.STATES.DOWN = [...tempFront];
165
232
 
166
- // Special permutation
167
233
  this.STATES.BACK = this.#specialFlip(tempDown);
168
234
  this.STATES.UPPER = this.#specialFlip(tempBack);
169
235
  }
@@ -173,6 +239,16 @@ class CubeEngine {
173
239
  * Rotates the (y) axis clockwise or counterclockwise.
174
240
  */
175
241
  rotateY(clockwise = true) {
242
+ if (clockwise) {
243
+ this.#rotateY(true);
244
+ this.MOVES.push("y");
245
+ } else {
246
+ this.#rotateY(false);
247
+ this.MOVES.push("y'");
248
+ }
249
+ }
250
+
251
+ #rotateY(clockwise = true) {
176
252
  const tempFront = structuredClone(this.STATES.FRONT);
177
253
  const tempRight = structuredClone(this.STATES.RIGHT);
178
254
  const tempBack = structuredClone(this.STATES.BACK);
@@ -182,7 +258,6 @@ class CubeEngine {
182
258
  this.STATES.UPPER = this.#switchMatrix(this.STATES.UPPER, true);
183
259
  this.STATES.DOWN = this.#switchMatrix(this.STATES.DOWN, false);
184
260
 
185
- // Rotation X axis
186
261
  this.STATES.FRONT = [...tempRight];
187
262
  this.STATES.RIGHT = [...tempBack];
188
263
  this.STATES.LEFT = [...tempFront];
@@ -191,7 +266,6 @@ class CubeEngine {
191
266
  this.STATES.UPPER = this.#switchMatrix(this.STATES.UPPER, false);
192
267
  this.STATES.DOWN = this.#switchMatrix(this.STATES.DOWN, true);
193
268
 
194
- // Rotation X axis
195
269
  this.STATES.FRONT = [...tempLeft];
196
270
  this.STATES.RIGHT = [...tempFront];
197
271
  this.STATES.LEFT = [...tempBack];
@@ -232,10 +306,6 @@ class CubeEngine {
232
306
  * Logs the current state of the cube.
233
307
  */
234
308
  state() {
235
- console.clear();
236
- console.log({
237
- ...this.STATES,
238
- });
239
309
  return {
240
310
  ...this.STATES,
241
311
  };
@@ -263,6 +333,16 @@ class CubeEngine {
263
333
 
264
334
  return layersSolved.every((isLayerSolved) => isLayerSolved);
265
335
  }
336
+
337
+ /**
338
+ * Returns the history of all movements made.
339
+ *
340
+ * @param {boolean} asString - If true, returns the history as a string; otherwise, returns it as an array.
341
+ * @returns {string|array} The history of movements as an array or string.
342
+ */
343
+ getMoves(asString = true) {
344
+ return asString ? this.MOVES.join(" ") : this.MOVES;
345
+ }
266
346
  }
267
347
 
268
348
  const COLOR = {
package/dist/index.js CHANGED
@@ -45,10 +45,11 @@ __export(src_exports, {
45
45
  CubeEngine: () => CubeEngine
46
46
  });
47
47
  module.exports = __toCommonJS(src_exports);
48
- var _CubeEngine_instances, switchMatrix_fn, specialFlip_fn;
48
+ var _CubeEngine_instances, rotateU_fn, rotateF_fn, rotateR_fn, rotateL_fn, rotateD_fn, rotateX_fn, rotateY_fn, switchMatrix_fn, specialFlip_fn;
49
49
  var CubeEngine = class {
50
50
  constructor() {
51
51
  __privateAdd(this, _CubeEngine_instances);
52
+ __publicField(this, "MOVES", []);
52
53
  // States object for the rotation
53
54
  __publicField(this, "STATES", {
54
55
  UPPER: [
@@ -90,142 +91,93 @@ var CubeEngine = class {
90
91
  });
91
92
  }
92
93
  /**
93
- * Rotates the top (U) layer clockwise or counterclockwise.
94
+ * Rotates the (UPPER) layer clockwise or counterclockwise.
94
95
  */
95
96
  rotateU(clockwise = true) {
96
97
  if (clockwise) {
97
- this.STATES.UPPER = __privateMethod(this, _CubeEngine_instances, switchMatrix_fn).call(this, this.STATES.UPPER, true);
98
- const tempFront = [...this.STATES.FRONT[0]];
99
- const tempRight = [...this.STATES.RIGHT[0]];
100
- const tempLeft = [...this.STATES.LEFT[0]];
101
- const tempBack = [...this.STATES.BACK[0]];
102
- this.STATES.FRONT[0] = [...tempRight];
103
- this.STATES.LEFT[0] = [...tempFront];
104
- this.STATES.BACK[0] = [...tempLeft];
105
- this.STATES.RIGHT[0] = [...tempBack];
98
+ __privateMethod(this, _CubeEngine_instances, rotateU_fn).call(this, true);
99
+ this.MOVES.push("U");
106
100
  } else {
107
- this.STATES.UPPER = __privateMethod(this, _CubeEngine_instances, switchMatrix_fn).call(this, this.STATES.UPPER, false);
108
- const tempFront = [...this.STATES.FRONT[0]];
109
- const tempRight = [...this.STATES.RIGHT[0]];
110
- const tempLeft = [...this.STATES.LEFT[0]];
111
- const tempBack = [...this.STATES.BACK[0]];
112
- this.STATES.FRONT[0] = [...tempLeft];
113
- this.STATES.LEFT[0] = [...tempBack];
114
- this.STATES.BACK[0] = [...tempRight];
115
- this.STATES.RIGHT[0] = [...tempFront];
101
+ __privateMethod(this, _CubeEngine_instances, rotateU_fn).call(this, false);
102
+ this.MOVES.push("U'");
116
103
  }
117
104
  }
118
105
  /**
119
- * Rotates the front (F) layer clockwise or counterclockwise.
106
+ * Rotates the (FRONT) layer clockwise or counterclockwise.
120
107
  */
121
108
  rotateF(clockwise = true) {
122
109
  if (clockwise) {
123
- this.rotateX(true);
124
- this.rotateU(true);
125
- this.rotateX(false);
110
+ __privateMethod(this, _CubeEngine_instances, rotateF_fn).call(this, true);
111
+ this.MOVES.push("F");
126
112
  } else {
127
- this.rotateX(true);
128
- this.rotateU(false);
129
- this.rotateX(false);
113
+ __privateMethod(this, _CubeEngine_instances, rotateF_fn).call(this, false);
114
+ this.MOVES.push("F'");
130
115
  }
131
116
  }
117
+ /**
118
+ * Rotates the (RIGHT) layer clockwise or counterclockwise.
119
+ */
132
120
  rotateR(clockwise = true) {
133
121
  if (clockwise) {
134
- this.rotateY(true);
135
- this.rotateX(true);
136
- this.rotateU(true);
137
- this.rotateX(false);
138
- this.rotateY(false);
122
+ __privateMethod(this, _CubeEngine_instances, rotateR_fn).call(this, true);
123
+ this.MOVES.push("R");
139
124
  } else {
140
- this.rotateY(true);
141
- this.rotateX(true);
142
- this.rotateU(false);
143
- this.rotateX(false);
144
- this.rotateY(false);
125
+ __privateMethod(this, _CubeEngine_instances, rotateR_fn).call(this, false);
126
+ this.MOVES.push("R'");
145
127
  }
146
128
  }
129
+ /**
130
+ * Rotates the (LEFT) layer clockwise or counterclockwise.
131
+ */
147
132
  rotateL(clockwise = true) {
148
133
  if (clockwise) {
149
- this.rotateY(false);
150
- this.rotateX(true);
151
- this.rotateU(true);
152
- this.rotateX(false);
153
- this.rotateY(true);
134
+ __privateMethod(this, _CubeEngine_instances, rotateL_fn).call(this, true);
135
+ this.MOVES.push("L");
154
136
  } else {
155
- this.rotateY(false);
156
- this.rotateX(true);
157
- this.rotateU(false);
158
- this.rotateX(false);
159
- this.rotateY(true);
137
+ __privateMethod(this, _CubeEngine_instances, rotateL_fn).call(this, false);
138
+ this.MOVES.push("L'");
160
139
  }
161
140
  }
141
+ /**
142
+ * Rotates the (DOWN) layer clockwise or counterclockwise.
143
+ */
162
144
  rotateD(clockwise = true) {
163
145
  if (clockwise) {
164
- this.rotateX(true);
165
- this.rotateF(true);
166
- this.rotateX(false);
146
+ __privateMethod(this, _CubeEngine_instances, rotateD_fn).call(this, true);
147
+ this.MOVES.push("D");
167
148
  } else {
168
- this.rotateX(true);
169
- this.rotateF(false);
170
- this.rotateX(false);
149
+ __privateMethod(this, _CubeEngine_instances, rotateD_fn).call(this, false);
150
+ this.MOVES.push("D'");
171
151
  }
172
152
  }
173
153
  /**
174
154
  * Rotates the (x) axis clockwise or counterclockwise.
175
155
  */
176
156
  rotateX(clockwise = true) {
177
- const tempFront = structuredClone(this.STATES.FRONT);
178
- const tempDown = structuredClone(this.STATES.DOWN);
179
- const tempUpper = structuredClone(this.STATES.UPPER);
180
- const tempBack = structuredClone(this.STATES.BACK);
181
- const tempLeft = structuredClone(this.STATES.LEFT);
182
- const tempRight = structuredClone(this.STATES.RIGHT);
183
157
  if (clockwise) {
184
- this.STATES.LEFT = __privateMethod(this, _CubeEngine_instances, switchMatrix_fn).call(this, tempLeft, false);
185
- this.STATES.RIGHT = __privateMethod(this, _CubeEngine_instances, switchMatrix_fn).call(this, tempRight, true);
186
- this.STATES.FRONT = [...tempDown];
187
- this.STATES.UPPER = [...tempFront];
188
- this.STATES.BACK = __privateMethod(this, _CubeEngine_instances, specialFlip_fn).call(this, tempUpper);
189
- this.STATES.DOWN = __privateMethod(this, _CubeEngine_instances, specialFlip_fn).call(this, tempBack);
158
+ __privateMethod(this, _CubeEngine_instances, rotateX_fn).call(this, true);
159
+ this.MOVES.push("x");
190
160
  } else {
191
- this.STATES.LEFT = __privateMethod(this, _CubeEngine_instances, switchMatrix_fn).call(this, tempLeft, true);
192
- this.STATES.RIGHT = __privateMethod(this, _CubeEngine_instances, switchMatrix_fn).call(this, tempRight, false);
193
- this.STATES.FRONT = [...tempUpper];
194
- this.STATES.DOWN = [...tempFront];
195
- this.STATES.BACK = __privateMethod(this, _CubeEngine_instances, specialFlip_fn).call(this, tempDown);
196
- this.STATES.UPPER = __privateMethod(this, _CubeEngine_instances, specialFlip_fn).call(this, tempBack);
161
+ __privateMethod(this, _CubeEngine_instances, rotateX_fn).call(this, false);
162
+ this.MOVES.push("x'");
197
163
  }
198
164
  }
199
165
  /**
200
166
  * Rotates the (y) axis clockwise or counterclockwise.
201
167
  */
202
168
  rotateY(clockwise = true) {
203
- const tempFront = structuredClone(this.STATES.FRONT);
204
- const tempRight = structuredClone(this.STATES.RIGHT);
205
- const tempBack = structuredClone(this.STATES.BACK);
206
- const tempLeft = structuredClone(this.STATES.LEFT);
207
169
  if (clockwise) {
208
- this.STATES.UPPER = __privateMethod(this, _CubeEngine_instances, switchMatrix_fn).call(this, this.STATES.UPPER, true);
209
- this.STATES.DOWN = __privateMethod(this, _CubeEngine_instances, switchMatrix_fn).call(this, this.STATES.DOWN, false);
210
- this.STATES.FRONT = [...tempRight];
211
- this.STATES.RIGHT = [...tempBack];
212
- this.STATES.LEFT = [...tempFront];
213
- this.STATES.BACK = [...tempLeft];
170
+ __privateMethod(this, _CubeEngine_instances, rotateY_fn).call(this, true);
171
+ this.MOVES.push("y");
214
172
  } else {
215
- this.STATES.UPPER = __privateMethod(this, _CubeEngine_instances, switchMatrix_fn).call(this, this.STATES.UPPER, false);
216
- this.STATES.DOWN = __privateMethod(this, _CubeEngine_instances, switchMatrix_fn).call(this, this.STATES.DOWN, true);
217
- this.STATES.FRONT = [...tempLeft];
218
- this.STATES.RIGHT = [...tempFront];
219
- this.STATES.LEFT = [...tempBack];
220
- this.STATES.BACK = [...tempRight];
173
+ __privateMethod(this, _CubeEngine_instances, rotateY_fn).call(this, false);
174
+ this.MOVES.push("y'");
221
175
  }
222
176
  }
223
177
  /**
224
178
  * Logs the current state of the cube.
225
179
  */
226
180
  state() {
227
- console.clear();
228
- console.log(__spreadValues({}, this.STATES));
229
181
  return __spreadValues({}, this.STATES);
230
182
  }
231
183
  /**
@@ -244,8 +196,136 @@ var CubeEngine = class {
244
196
  });
245
197
  return layersSolved.every((isLayerSolved) => isLayerSolved);
246
198
  }
199
+ /**
200
+ * Returns the history of all movements made.
201
+ *
202
+ * @param {boolean} asString - If true, returns the history as a string; otherwise, returns it as an array.
203
+ * @returns {string|array} The history of movements as an array or string.
204
+ */
205
+ getMoves(asString = true) {
206
+ return asString ? this.MOVES.join(" ") : this.MOVES;
207
+ }
247
208
  };
248
209
  _CubeEngine_instances = new WeakSet();
210
+ rotateU_fn = function(clockwise = true) {
211
+ if (clockwise) {
212
+ this.STATES.UPPER = __privateMethod(this, _CubeEngine_instances, switchMatrix_fn).call(this, this.STATES.UPPER, true);
213
+ const tempFront = [...this.STATES.FRONT[0]];
214
+ const tempRight = [...this.STATES.RIGHT[0]];
215
+ const tempLeft = [...this.STATES.LEFT[0]];
216
+ const tempBack = [...this.STATES.BACK[0]];
217
+ this.STATES.FRONT[0] = [...tempRight];
218
+ this.STATES.LEFT[0] = [...tempFront];
219
+ this.STATES.BACK[0] = [...tempLeft];
220
+ this.STATES.RIGHT[0] = [...tempBack];
221
+ } else {
222
+ this.STATES.UPPER = __privateMethod(this, _CubeEngine_instances, switchMatrix_fn).call(this, this.STATES.UPPER, false);
223
+ const tempFront = [...this.STATES.FRONT[0]];
224
+ const tempRight = [...this.STATES.RIGHT[0]];
225
+ const tempLeft = [...this.STATES.LEFT[0]];
226
+ const tempBack = [...this.STATES.BACK[0]];
227
+ this.STATES.FRONT[0] = [...tempLeft];
228
+ this.STATES.LEFT[0] = [...tempBack];
229
+ this.STATES.BACK[0] = [...tempRight];
230
+ this.STATES.RIGHT[0] = [...tempFront];
231
+ }
232
+ };
233
+ rotateF_fn = function(clockwise = true) {
234
+ if (clockwise) {
235
+ __privateMethod(this, _CubeEngine_instances, rotateX_fn).call(this, true);
236
+ __privateMethod(this, _CubeEngine_instances, rotateU_fn).call(this, true);
237
+ __privateMethod(this, _CubeEngine_instances, rotateX_fn).call(this, false);
238
+ } else {
239
+ __privateMethod(this, _CubeEngine_instances, rotateX_fn).call(this, true);
240
+ __privateMethod(this, _CubeEngine_instances, rotateU_fn).call(this, false);
241
+ __privateMethod(this, _CubeEngine_instances, rotateX_fn).call(this, false);
242
+ }
243
+ };
244
+ rotateR_fn = function(clockwise = true) {
245
+ if (clockwise) {
246
+ __privateMethod(this, _CubeEngine_instances, rotateY_fn).call(this, true);
247
+ __privateMethod(this, _CubeEngine_instances, rotateX_fn).call(this, true);
248
+ __privateMethod(this, _CubeEngine_instances, rotateU_fn).call(this, true);
249
+ __privateMethod(this, _CubeEngine_instances, rotateX_fn).call(this, false);
250
+ __privateMethod(this, _CubeEngine_instances, rotateY_fn).call(this, false);
251
+ } else {
252
+ __privateMethod(this, _CubeEngine_instances, rotateY_fn).call(this, true);
253
+ __privateMethod(this, _CubeEngine_instances, rotateX_fn).call(this, true);
254
+ __privateMethod(this, _CubeEngine_instances, rotateU_fn).call(this, false);
255
+ __privateMethod(this, _CubeEngine_instances, rotateX_fn).call(this, false);
256
+ __privateMethod(this, _CubeEngine_instances, rotateY_fn).call(this, false);
257
+ }
258
+ };
259
+ rotateL_fn = function(clockwise = true) {
260
+ if (clockwise) {
261
+ __privateMethod(this, _CubeEngine_instances, rotateY_fn).call(this, false);
262
+ __privateMethod(this, _CubeEngine_instances, rotateX_fn).call(this, true);
263
+ __privateMethod(this, _CubeEngine_instances, rotateU_fn).call(this, true);
264
+ __privateMethod(this, _CubeEngine_instances, rotateX_fn).call(this, false);
265
+ __privateMethod(this, _CubeEngine_instances, rotateY_fn).call(this, true);
266
+ } else {
267
+ __privateMethod(this, _CubeEngine_instances, rotateY_fn).call(this, false);
268
+ __privateMethod(this, _CubeEngine_instances, rotateX_fn).call(this, true);
269
+ __privateMethod(this, _CubeEngine_instances, rotateU_fn).call(this, false);
270
+ __privateMethod(this, _CubeEngine_instances, rotateX_fn).call(this, false);
271
+ __privateMethod(this, _CubeEngine_instances, rotateY_fn).call(this, true);
272
+ }
273
+ };
274
+ rotateD_fn = function(clockwise = true) {
275
+ if (clockwise) {
276
+ __privateMethod(this, _CubeEngine_instances, rotateX_fn).call(this, true);
277
+ __privateMethod(this, _CubeEngine_instances, rotateF_fn).call(this, true);
278
+ __privateMethod(this, _CubeEngine_instances, rotateX_fn).call(this, false);
279
+ } else {
280
+ __privateMethod(this, _CubeEngine_instances, rotateX_fn).call(this, true);
281
+ __privateMethod(this, _CubeEngine_instances, rotateF_fn).call(this, false);
282
+ __privateMethod(this, _CubeEngine_instances, rotateX_fn).call(this, false);
283
+ }
284
+ };
285
+ rotateX_fn = function(clockwise = true) {
286
+ const tempFront = structuredClone(this.STATES.FRONT);
287
+ const tempDown = structuredClone(this.STATES.DOWN);
288
+ const tempUpper = structuredClone(this.STATES.UPPER);
289
+ const tempBack = structuredClone(this.STATES.BACK);
290
+ const tempLeft = structuredClone(this.STATES.LEFT);
291
+ const tempRight = structuredClone(this.STATES.RIGHT);
292
+ if (clockwise) {
293
+ this.STATES.LEFT = __privateMethod(this, _CubeEngine_instances, switchMatrix_fn).call(this, tempLeft, false);
294
+ this.STATES.RIGHT = __privateMethod(this, _CubeEngine_instances, switchMatrix_fn).call(this, tempRight, true);
295
+ this.STATES.FRONT = [...tempDown];
296
+ this.STATES.UPPER = [...tempFront];
297
+ this.STATES.BACK = __privateMethod(this, _CubeEngine_instances, specialFlip_fn).call(this, tempUpper);
298
+ this.STATES.DOWN = __privateMethod(this, _CubeEngine_instances, specialFlip_fn).call(this, tempBack);
299
+ } else {
300
+ this.STATES.LEFT = __privateMethod(this, _CubeEngine_instances, switchMatrix_fn).call(this, tempLeft, true);
301
+ this.STATES.RIGHT = __privateMethod(this, _CubeEngine_instances, switchMatrix_fn).call(this, tempRight, false);
302
+ this.STATES.FRONT = [...tempUpper];
303
+ this.STATES.DOWN = [...tempFront];
304
+ this.STATES.BACK = __privateMethod(this, _CubeEngine_instances, specialFlip_fn).call(this, tempDown);
305
+ this.STATES.UPPER = __privateMethod(this, _CubeEngine_instances, specialFlip_fn).call(this, tempBack);
306
+ }
307
+ };
308
+ rotateY_fn = function(clockwise = true) {
309
+ const tempFront = structuredClone(this.STATES.FRONT);
310
+ const tempRight = structuredClone(this.STATES.RIGHT);
311
+ const tempBack = structuredClone(this.STATES.BACK);
312
+ const tempLeft = structuredClone(this.STATES.LEFT);
313
+ if (clockwise) {
314
+ this.STATES.UPPER = __privateMethod(this, _CubeEngine_instances, switchMatrix_fn).call(this, this.STATES.UPPER, true);
315
+ this.STATES.DOWN = __privateMethod(this, _CubeEngine_instances, switchMatrix_fn).call(this, this.STATES.DOWN, false);
316
+ this.STATES.FRONT = [...tempRight];
317
+ this.STATES.RIGHT = [...tempBack];
318
+ this.STATES.LEFT = [...tempFront];
319
+ this.STATES.BACK = [...tempLeft];
320
+ } else {
321
+ this.STATES.UPPER = __privateMethod(this, _CubeEngine_instances, switchMatrix_fn).call(this, this.STATES.UPPER, false);
322
+ this.STATES.DOWN = __privateMethod(this, _CubeEngine_instances, switchMatrix_fn).call(this, this.STATES.DOWN, true);
323
+ this.STATES.FRONT = [...tempLeft];
324
+ this.STATES.RIGHT = [...tempFront];
325
+ this.STATES.LEFT = [...tempBack];
326
+ this.STATES.BACK = [...tempRight];
327
+ }
328
+ };
249
329
  /**
250
330
  * Rotate the entire face in the direction set
251
331
  */
package/dist/index.mjs CHANGED
@@ -23,10 +23,11 @@ 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, switchMatrix_fn, specialFlip_fn;
26
+ var _CubeEngine_instances, rotateU_fn, rotateF_fn, rotateR_fn, rotateL_fn, rotateD_fn, rotateX_fn, rotateY_fn, switchMatrix_fn, specialFlip_fn;
27
27
  var CubeEngine = class {
28
28
  constructor() {
29
29
  __privateAdd(this, _CubeEngine_instances);
30
+ __publicField(this, "MOVES", []);
30
31
  // States object for the rotation
31
32
  __publicField(this, "STATES", {
32
33
  UPPER: [
@@ -68,142 +69,93 @@ var CubeEngine = class {
68
69
  });
69
70
  }
70
71
  /**
71
- * Rotates the top (U) layer clockwise or counterclockwise.
72
+ * Rotates the (UPPER) layer clockwise or counterclockwise.
72
73
  */
73
74
  rotateU(clockwise = true) {
74
75
  if (clockwise) {
75
- this.STATES.UPPER = __privateMethod(this, _CubeEngine_instances, switchMatrix_fn).call(this, this.STATES.UPPER, true);
76
- const tempFront = [...this.STATES.FRONT[0]];
77
- const tempRight = [...this.STATES.RIGHT[0]];
78
- const tempLeft = [...this.STATES.LEFT[0]];
79
- const tempBack = [...this.STATES.BACK[0]];
80
- this.STATES.FRONT[0] = [...tempRight];
81
- this.STATES.LEFT[0] = [...tempFront];
82
- this.STATES.BACK[0] = [...tempLeft];
83
- this.STATES.RIGHT[0] = [...tempBack];
76
+ __privateMethod(this, _CubeEngine_instances, rotateU_fn).call(this, true);
77
+ this.MOVES.push("U");
84
78
  } else {
85
- this.STATES.UPPER = __privateMethod(this, _CubeEngine_instances, switchMatrix_fn).call(this, this.STATES.UPPER, false);
86
- const tempFront = [...this.STATES.FRONT[0]];
87
- const tempRight = [...this.STATES.RIGHT[0]];
88
- const tempLeft = [...this.STATES.LEFT[0]];
89
- const tempBack = [...this.STATES.BACK[0]];
90
- this.STATES.FRONT[0] = [...tempLeft];
91
- this.STATES.LEFT[0] = [...tempBack];
92
- this.STATES.BACK[0] = [...tempRight];
93
- this.STATES.RIGHT[0] = [...tempFront];
79
+ __privateMethod(this, _CubeEngine_instances, rotateU_fn).call(this, false);
80
+ this.MOVES.push("U'");
94
81
  }
95
82
  }
96
83
  /**
97
- * Rotates the front (F) layer clockwise or counterclockwise.
84
+ * Rotates the (FRONT) layer clockwise or counterclockwise.
98
85
  */
99
86
  rotateF(clockwise = true) {
100
87
  if (clockwise) {
101
- this.rotateX(true);
102
- this.rotateU(true);
103
- this.rotateX(false);
88
+ __privateMethod(this, _CubeEngine_instances, rotateF_fn).call(this, true);
89
+ this.MOVES.push("F");
104
90
  } else {
105
- this.rotateX(true);
106
- this.rotateU(false);
107
- this.rotateX(false);
91
+ __privateMethod(this, _CubeEngine_instances, rotateF_fn).call(this, false);
92
+ this.MOVES.push("F'");
108
93
  }
109
94
  }
95
+ /**
96
+ * Rotates the (RIGHT) layer clockwise or counterclockwise.
97
+ */
110
98
  rotateR(clockwise = true) {
111
99
  if (clockwise) {
112
- this.rotateY(true);
113
- this.rotateX(true);
114
- this.rotateU(true);
115
- this.rotateX(false);
116
- this.rotateY(false);
100
+ __privateMethod(this, _CubeEngine_instances, rotateR_fn).call(this, true);
101
+ this.MOVES.push("R");
117
102
  } else {
118
- this.rotateY(true);
119
- this.rotateX(true);
120
- this.rotateU(false);
121
- this.rotateX(false);
122
- this.rotateY(false);
103
+ __privateMethod(this, _CubeEngine_instances, rotateR_fn).call(this, false);
104
+ this.MOVES.push("R'");
123
105
  }
124
106
  }
107
+ /**
108
+ * Rotates the (LEFT) layer clockwise or counterclockwise.
109
+ */
125
110
  rotateL(clockwise = true) {
126
111
  if (clockwise) {
127
- this.rotateY(false);
128
- this.rotateX(true);
129
- this.rotateU(true);
130
- this.rotateX(false);
131
- this.rotateY(true);
112
+ __privateMethod(this, _CubeEngine_instances, rotateL_fn).call(this, true);
113
+ this.MOVES.push("L");
132
114
  } else {
133
- this.rotateY(false);
134
- this.rotateX(true);
135
- this.rotateU(false);
136
- this.rotateX(false);
137
- this.rotateY(true);
115
+ __privateMethod(this, _CubeEngine_instances, rotateL_fn).call(this, false);
116
+ this.MOVES.push("L'");
138
117
  }
139
118
  }
119
+ /**
120
+ * Rotates the (DOWN) layer clockwise or counterclockwise.
121
+ */
140
122
  rotateD(clockwise = true) {
141
123
  if (clockwise) {
142
- this.rotateX(true);
143
- this.rotateF(true);
144
- this.rotateX(false);
124
+ __privateMethod(this, _CubeEngine_instances, rotateD_fn).call(this, true);
125
+ this.MOVES.push("D");
145
126
  } else {
146
- this.rotateX(true);
147
- this.rotateF(false);
148
- this.rotateX(false);
127
+ __privateMethod(this, _CubeEngine_instances, rotateD_fn).call(this, false);
128
+ this.MOVES.push("D'");
149
129
  }
150
130
  }
151
131
  /**
152
132
  * Rotates the (x) axis clockwise or counterclockwise.
153
133
  */
154
134
  rotateX(clockwise = true) {
155
- const tempFront = structuredClone(this.STATES.FRONT);
156
- const tempDown = structuredClone(this.STATES.DOWN);
157
- const tempUpper = structuredClone(this.STATES.UPPER);
158
- const tempBack = structuredClone(this.STATES.BACK);
159
- const tempLeft = structuredClone(this.STATES.LEFT);
160
- const tempRight = structuredClone(this.STATES.RIGHT);
161
135
  if (clockwise) {
162
- this.STATES.LEFT = __privateMethod(this, _CubeEngine_instances, switchMatrix_fn).call(this, tempLeft, false);
163
- this.STATES.RIGHT = __privateMethod(this, _CubeEngine_instances, switchMatrix_fn).call(this, tempRight, true);
164
- this.STATES.FRONT = [...tempDown];
165
- this.STATES.UPPER = [...tempFront];
166
- this.STATES.BACK = __privateMethod(this, _CubeEngine_instances, specialFlip_fn).call(this, tempUpper);
167
- this.STATES.DOWN = __privateMethod(this, _CubeEngine_instances, specialFlip_fn).call(this, tempBack);
136
+ __privateMethod(this, _CubeEngine_instances, rotateX_fn).call(this, true);
137
+ this.MOVES.push("x");
168
138
  } else {
169
- this.STATES.LEFT = __privateMethod(this, _CubeEngine_instances, switchMatrix_fn).call(this, tempLeft, true);
170
- this.STATES.RIGHT = __privateMethod(this, _CubeEngine_instances, switchMatrix_fn).call(this, tempRight, false);
171
- this.STATES.FRONT = [...tempUpper];
172
- this.STATES.DOWN = [...tempFront];
173
- this.STATES.BACK = __privateMethod(this, _CubeEngine_instances, specialFlip_fn).call(this, tempDown);
174
- this.STATES.UPPER = __privateMethod(this, _CubeEngine_instances, specialFlip_fn).call(this, tempBack);
139
+ __privateMethod(this, _CubeEngine_instances, rotateX_fn).call(this, false);
140
+ this.MOVES.push("x'");
175
141
  }
176
142
  }
177
143
  /**
178
144
  * Rotates the (y) axis clockwise or counterclockwise.
179
145
  */
180
146
  rotateY(clockwise = true) {
181
- const tempFront = structuredClone(this.STATES.FRONT);
182
- const tempRight = structuredClone(this.STATES.RIGHT);
183
- const tempBack = structuredClone(this.STATES.BACK);
184
- const tempLeft = structuredClone(this.STATES.LEFT);
185
147
  if (clockwise) {
186
- this.STATES.UPPER = __privateMethod(this, _CubeEngine_instances, switchMatrix_fn).call(this, this.STATES.UPPER, true);
187
- this.STATES.DOWN = __privateMethod(this, _CubeEngine_instances, switchMatrix_fn).call(this, this.STATES.DOWN, false);
188
- this.STATES.FRONT = [...tempRight];
189
- this.STATES.RIGHT = [...tempBack];
190
- this.STATES.LEFT = [...tempFront];
191
- this.STATES.BACK = [...tempLeft];
148
+ __privateMethod(this, _CubeEngine_instances, rotateY_fn).call(this, true);
149
+ this.MOVES.push("y");
192
150
  } else {
193
- this.STATES.UPPER = __privateMethod(this, _CubeEngine_instances, switchMatrix_fn).call(this, this.STATES.UPPER, false);
194
- this.STATES.DOWN = __privateMethod(this, _CubeEngine_instances, switchMatrix_fn).call(this, this.STATES.DOWN, true);
195
- this.STATES.FRONT = [...tempLeft];
196
- this.STATES.RIGHT = [...tempFront];
197
- this.STATES.LEFT = [...tempBack];
198
- this.STATES.BACK = [...tempRight];
151
+ __privateMethod(this, _CubeEngine_instances, rotateY_fn).call(this, false);
152
+ this.MOVES.push("y'");
199
153
  }
200
154
  }
201
155
  /**
202
156
  * Logs the current state of the cube.
203
157
  */
204
158
  state() {
205
- console.clear();
206
- console.log(__spreadValues({}, this.STATES));
207
159
  return __spreadValues({}, this.STATES);
208
160
  }
209
161
  /**
@@ -222,8 +174,136 @@ var CubeEngine = class {
222
174
  });
223
175
  return layersSolved.every((isLayerSolved) => isLayerSolved);
224
176
  }
177
+ /**
178
+ * Returns the history of all movements made.
179
+ *
180
+ * @param {boolean} asString - If true, returns the history as a string; otherwise, returns it as an array.
181
+ * @returns {string|array} The history of movements as an array or string.
182
+ */
183
+ getMoves(asString = true) {
184
+ return asString ? this.MOVES.join(" ") : this.MOVES;
185
+ }
225
186
  };
226
187
  _CubeEngine_instances = new WeakSet();
188
+ rotateU_fn = function(clockwise = true) {
189
+ if (clockwise) {
190
+ this.STATES.UPPER = __privateMethod(this, _CubeEngine_instances, switchMatrix_fn).call(this, this.STATES.UPPER, true);
191
+ const tempFront = [...this.STATES.FRONT[0]];
192
+ const tempRight = [...this.STATES.RIGHT[0]];
193
+ const tempLeft = [...this.STATES.LEFT[0]];
194
+ const tempBack = [...this.STATES.BACK[0]];
195
+ this.STATES.FRONT[0] = [...tempRight];
196
+ this.STATES.LEFT[0] = [...tempFront];
197
+ this.STATES.BACK[0] = [...tempLeft];
198
+ this.STATES.RIGHT[0] = [...tempBack];
199
+ } else {
200
+ this.STATES.UPPER = __privateMethod(this, _CubeEngine_instances, switchMatrix_fn).call(this, this.STATES.UPPER, false);
201
+ const tempFront = [...this.STATES.FRONT[0]];
202
+ const tempRight = [...this.STATES.RIGHT[0]];
203
+ const tempLeft = [...this.STATES.LEFT[0]];
204
+ const tempBack = [...this.STATES.BACK[0]];
205
+ this.STATES.FRONT[0] = [...tempLeft];
206
+ this.STATES.LEFT[0] = [...tempBack];
207
+ this.STATES.BACK[0] = [...tempRight];
208
+ this.STATES.RIGHT[0] = [...tempFront];
209
+ }
210
+ };
211
+ rotateF_fn = function(clockwise = true) {
212
+ if (clockwise) {
213
+ __privateMethod(this, _CubeEngine_instances, rotateX_fn).call(this, true);
214
+ __privateMethod(this, _CubeEngine_instances, rotateU_fn).call(this, true);
215
+ __privateMethod(this, _CubeEngine_instances, rotateX_fn).call(this, false);
216
+ } else {
217
+ __privateMethod(this, _CubeEngine_instances, rotateX_fn).call(this, true);
218
+ __privateMethod(this, _CubeEngine_instances, rotateU_fn).call(this, false);
219
+ __privateMethod(this, _CubeEngine_instances, rotateX_fn).call(this, false);
220
+ }
221
+ };
222
+ rotateR_fn = function(clockwise = true) {
223
+ if (clockwise) {
224
+ __privateMethod(this, _CubeEngine_instances, rotateY_fn).call(this, true);
225
+ __privateMethod(this, _CubeEngine_instances, rotateX_fn).call(this, true);
226
+ __privateMethod(this, _CubeEngine_instances, rotateU_fn).call(this, true);
227
+ __privateMethod(this, _CubeEngine_instances, rotateX_fn).call(this, false);
228
+ __privateMethod(this, _CubeEngine_instances, rotateY_fn).call(this, false);
229
+ } else {
230
+ __privateMethod(this, _CubeEngine_instances, rotateY_fn).call(this, true);
231
+ __privateMethod(this, _CubeEngine_instances, rotateX_fn).call(this, true);
232
+ __privateMethod(this, _CubeEngine_instances, rotateU_fn).call(this, false);
233
+ __privateMethod(this, _CubeEngine_instances, rotateX_fn).call(this, false);
234
+ __privateMethod(this, _CubeEngine_instances, rotateY_fn).call(this, false);
235
+ }
236
+ };
237
+ rotateL_fn = function(clockwise = true) {
238
+ if (clockwise) {
239
+ __privateMethod(this, _CubeEngine_instances, rotateY_fn).call(this, false);
240
+ __privateMethod(this, _CubeEngine_instances, rotateX_fn).call(this, true);
241
+ __privateMethod(this, _CubeEngine_instances, rotateU_fn).call(this, true);
242
+ __privateMethod(this, _CubeEngine_instances, rotateX_fn).call(this, false);
243
+ __privateMethod(this, _CubeEngine_instances, rotateY_fn).call(this, true);
244
+ } else {
245
+ __privateMethod(this, _CubeEngine_instances, rotateY_fn).call(this, false);
246
+ __privateMethod(this, _CubeEngine_instances, rotateX_fn).call(this, true);
247
+ __privateMethod(this, _CubeEngine_instances, rotateU_fn).call(this, false);
248
+ __privateMethod(this, _CubeEngine_instances, rotateX_fn).call(this, false);
249
+ __privateMethod(this, _CubeEngine_instances, rotateY_fn).call(this, true);
250
+ }
251
+ };
252
+ rotateD_fn = function(clockwise = true) {
253
+ if (clockwise) {
254
+ __privateMethod(this, _CubeEngine_instances, rotateX_fn).call(this, true);
255
+ __privateMethod(this, _CubeEngine_instances, rotateF_fn).call(this, true);
256
+ __privateMethod(this, _CubeEngine_instances, rotateX_fn).call(this, false);
257
+ } else {
258
+ __privateMethod(this, _CubeEngine_instances, rotateX_fn).call(this, true);
259
+ __privateMethod(this, _CubeEngine_instances, rotateF_fn).call(this, false);
260
+ __privateMethod(this, _CubeEngine_instances, rotateX_fn).call(this, false);
261
+ }
262
+ };
263
+ rotateX_fn = function(clockwise = true) {
264
+ const tempFront = structuredClone(this.STATES.FRONT);
265
+ const tempDown = structuredClone(this.STATES.DOWN);
266
+ const tempUpper = structuredClone(this.STATES.UPPER);
267
+ const tempBack = structuredClone(this.STATES.BACK);
268
+ const tempLeft = structuredClone(this.STATES.LEFT);
269
+ const tempRight = structuredClone(this.STATES.RIGHT);
270
+ if (clockwise) {
271
+ this.STATES.LEFT = __privateMethod(this, _CubeEngine_instances, switchMatrix_fn).call(this, tempLeft, false);
272
+ this.STATES.RIGHT = __privateMethod(this, _CubeEngine_instances, switchMatrix_fn).call(this, tempRight, true);
273
+ this.STATES.FRONT = [...tempDown];
274
+ this.STATES.UPPER = [...tempFront];
275
+ this.STATES.BACK = __privateMethod(this, _CubeEngine_instances, specialFlip_fn).call(this, tempUpper);
276
+ this.STATES.DOWN = __privateMethod(this, _CubeEngine_instances, specialFlip_fn).call(this, tempBack);
277
+ } else {
278
+ this.STATES.LEFT = __privateMethod(this, _CubeEngine_instances, switchMatrix_fn).call(this, tempLeft, true);
279
+ this.STATES.RIGHT = __privateMethod(this, _CubeEngine_instances, switchMatrix_fn).call(this, tempRight, false);
280
+ this.STATES.FRONT = [...tempUpper];
281
+ this.STATES.DOWN = [...tempFront];
282
+ this.STATES.BACK = __privateMethod(this, _CubeEngine_instances, specialFlip_fn).call(this, tempDown);
283
+ this.STATES.UPPER = __privateMethod(this, _CubeEngine_instances, specialFlip_fn).call(this, tempBack);
284
+ }
285
+ };
286
+ rotateY_fn = function(clockwise = true) {
287
+ const tempFront = structuredClone(this.STATES.FRONT);
288
+ const tempRight = structuredClone(this.STATES.RIGHT);
289
+ const tempBack = structuredClone(this.STATES.BACK);
290
+ const tempLeft = structuredClone(this.STATES.LEFT);
291
+ if (clockwise) {
292
+ this.STATES.UPPER = __privateMethod(this, _CubeEngine_instances, switchMatrix_fn).call(this, this.STATES.UPPER, true);
293
+ this.STATES.DOWN = __privateMethod(this, _CubeEngine_instances, switchMatrix_fn).call(this, this.STATES.DOWN, false);
294
+ this.STATES.FRONT = [...tempRight];
295
+ this.STATES.RIGHT = [...tempBack];
296
+ this.STATES.LEFT = [...tempFront];
297
+ this.STATES.BACK = [...tempLeft];
298
+ } else {
299
+ this.STATES.UPPER = __privateMethod(this, _CubeEngine_instances, switchMatrix_fn).call(this, this.STATES.UPPER, false);
300
+ this.STATES.DOWN = __privateMethod(this, _CubeEngine_instances, switchMatrix_fn).call(this, this.STATES.DOWN, true);
301
+ this.STATES.FRONT = [...tempLeft];
302
+ this.STATES.RIGHT = [...tempFront];
303
+ this.STATES.LEFT = [...tempBack];
304
+ this.STATES.BACK = [...tempRight];
305
+ }
306
+ };
227
307
  /**
228
308
  * Rotate the entire face in the direction set
229
309
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cube-state-engine",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
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",