arcanumcube 0.1.2 → 0.1.3

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.
@@ -0,0 +1,733 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/core.ts
21
+ var core_exports = {};
22
+ __export(core_exports, {
23
+ ArcanumCube: () => ArcanumCube,
24
+ CUBE: () => CUBE,
25
+ CUBE_ANGLES: () => CUBE_ANGLES,
26
+ CUBE_SIZE: () => CUBE_SIZE,
27
+ Cube: () => Cube,
28
+ DOUBLE_TWIST_LIST: () => DOUBLE_TWIST_LIST,
29
+ FACE: () => FACE,
30
+ MatchGoalState: () => MatchGoalState,
31
+ SIDE_MAX: () => SIDE_MAX,
32
+ SIDE_MIDDLE: () => SIDE_MIDDLE,
33
+ SIDE_MIN: () => SIDE_MIN,
34
+ SINGLE_TWIST_LIST: () => SINGLE_TWIST_LIST,
35
+ STICKER_COLOR: () => STICKER_COLOR,
36
+ TWIST: () => TWIST,
37
+ TWIST_LIST: () => TWIST_LIST,
38
+ TWIST_RULE: () => TWIST_RULE,
39
+ getArrayForTensor: () => getArrayForTensor,
40
+ getCubeFromStickerIndex: () => getCubeFromStickerIndex,
41
+ getCubePermutationGroup: () => getCubePermutationGroup,
42
+ getNextStickerColors: () => getNextStickerColors,
43
+ getRandomTwistList: () => getRandomTwistList,
44
+ getStickerIndex: () => getStickerIndex,
45
+ getStickerPermutationGroup: () => getStickerPermutationGroup
46
+ });
47
+ module.exports = __toCommonJS(core_exports);
48
+ var CUBE_SIZE = 3;
49
+ var SIDE_MAX = CUBE_SIZE - 1;
50
+ var SIDE_MIN = 0;
51
+ var SIDE_MIDDLE = Math.floor(CUBE_SIZE / 2);
52
+ var STICKER_COLOR = {
53
+ UP: 0,
54
+ FRONT: 1,
55
+ RIGHT: 2,
56
+ DOWN: 3,
57
+ BACK: 4,
58
+ LEFT: 5,
59
+ PLAIN: 6
60
+ };
61
+ var CUBE = {
62
+ AXIS: "axis",
63
+ CENTER: "center",
64
+ EDGE: "edge",
65
+ CORNER: "corner",
66
+ STICKER: "sticker"
67
+ };
68
+ var CUBETYPE_LIST = [CUBE.AXIS, CUBE.CENTER, CUBE.EDGE, CUBE.CORNER];
69
+ var FACE_LIST = ["U", "F", "R", "D", "B", "L"];
70
+ var FACE = Object.assign(
71
+ {},
72
+ ...FACE_LIST.map((k, i) => ({ [k]: i }))
73
+ );
74
+ var TWIST = {
75
+ U: "U",
76
+ UR: "U'",
77
+ F: "F",
78
+ FR: "F'",
79
+ R: "R",
80
+ RR: "R'",
81
+ D: "D",
82
+ DR: "D'",
83
+ B: "B",
84
+ BR: "B'",
85
+ L: "L",
86
+ LR: "L'",
87
+ M: "M",
88
+ MR: "M'",
89
+ E: "E",
90
+ ER: "E'",
91
+ S: "S",
92
+ SR: "S'",
93
+ U2: "U2",
94
+ F2: "F2",
95
+ R2: "R2",
96
+ D2: "D2",
97
+ B2: "B2",
98
+ L2: "L2",
99
+ M2: "M2",
100
+ E2: "E2",
101
+ S2: "S2"
102
+ };
103
+ var SINGLE_TWIST_LIST = [
104
+ TWIST.U,
105
+ TWIST.UR,
106
+ TWIST.F,
107
+ TWIST.FR,
108
+ TWIST.R,
109
+ TWIST.RR,
110
+ TWIST.D,
111
+ TWIST.DR,
112
+ TWIST.B,
113
+ TWIST.BR,
114
+ TWIST.L,
115
+ TWIST.LR,
116
+ TWIST.M,
117
+ TWIST.MR,
118
+ TWIST.E,
119
+ TWIST.ER,
120
+ TWIST.S,
121
+ TWIST.SR
122
+ ];
123
+ var DOUBLE_TWIST_LIST = [
124
+ TWIST.U2,
125
+ TWIST.F2,
126
+ TWIST.R2,
127
+ TWIST.D2,
128
+ TWIST.B2,
129
+ TWIST.L2,
130
+ TWIST.M2,
131
+ TWIST.E2,
132
+ TWIST.S2
133
+ ];
134
+ var TWIST_LIST = [...SINGLE_TWIST_LIST, ...DOUBLE_TWIST_LIST];
135
+ var CUBE_ANGLES = [
136
+ [
137
+ // down 3x3 cubes
138
+ [
139
+ [TWIST.B],
140
+ // [0, 0, 90]
141
+ [TWIST.B2],
142
+ // [0, 0, 180]
143
+ [TWIST.B2]
144
+ // [0, 0, 180]
145
+ ],
146
+ [
147
+ [TWIST.UR, TWIST.SR],
148
+ // [0, 90, 90]
149
+ [TWIST.M2],
150
+ // [180, 0, 0]
151
+ [TWIST.U, TWIST.S]
152
+ // [0, -90, -90]
153
+ ],
154
+ [
155
+ [TWIST.L2],
156
+ // [180, 0, 0]
157
+ [TWIST.M2],
158
+ // [180, 0, 0]
159
+ [TWIST.L, TWIST.UR, TWIST.F]
160
+ // [90, 90, -90]
161
+ ]
162
+ ],
163
+ [
164
+ // middle 3x3 cubes
165
+ [
166
+ [TWIST.B],
167
+ // [0, 0, 90]
168
+ [TWIST.MR],
169
+ // [-90, 0, 0]
170
+ [TWIST.BR]
171
+ // [0, 0, -90]
172
+ ],
173
+ [
174
+ [TWIST.SR],
175
+ // [0, 0, 90]
176
+ [],
177
+ // [0, 0, 0] original axis
178
+ [TWIST.S]
179
+ // [0, 0, -90]
180
+ ],
181
+ [
182
+ [TWIST.M, TWIST.FR],
183
+ // [90, 0, 90]
184
+ [TWIST.M],
185
+ // [90, 0, 0]
186
+ [TWIST.M, TWIST.F]
187
+ // [90, 0, -90]
188
+ ]
189
+ ],
190
+ [
191
+ // up 3x3 cubes
192
+ [
193
+ [],
194
+ // [0, 0, 0] original corner
195
+ [],
196
+ // [0, 0, 0] original edge
197
+ [TWIST.U]
198
+ // [0, -90, 0]
199
+ ],
200
+ [
201
+ [TWIST.UR],
202
+ // [0, 90, 0]
203
+ [],
204
+ // [0, 0, 0] original center
205
+ [TWIST.U]
206
+ // [0, -90, 0]
207
+ ],
208
+ [
209
+ [TWIST.UR],
210
+ // [0, 90, 0]
211
+ [TWIST.U2],
212
+ // [0, 180, 0]
213
+ [TWIST.U2]
214
+ // [0, 180, 0]
215
+ ]
216
+ ]
217
+ ];
218
+ var TWIST_RULE = {
219
+ [TWIST.U]: { axis: [0, -1, 0], levels: [2], steps: 1 },
220
+ [TWIST.UR]: { axis: [0, 1, 0], levels: [2], steps: 1 },
221
+ [TWIST.F]: { axis: [0, 0, -1], levels: [2], steps: 1 },
222
+ [TWIST.FR]: { axis: [0, 0, 1], levels: [2], steps: 1 },
223
+ [TWIST.R]: { axis: [-1, 0, 0], levels: [2], steps: 1 },
224
+ [TWIST.RR]: { axis: [1, 0, 0], levels: [2], steps: 1 },
225
+ [TWIST.D]: { axis: [0, 1, 0], levels: [0], steps: 1 },
226
+ [TWIST.DR]: { axis: [0, -1, 0], levels: [0], steps: 1 },
227
+ [TWIST.B]: { axis: [0, 0, 1], levels: [0], steps: 1 },
228
+ [TWIST.BR]: { axis: [0, 0, -1], levels: [0], steps: 1 },
229
+ [TWIST.L]: { axis: [1, 0, 0], levels: [0], steps: 1 },
230
+ [TWIST.LR]: { axis: [-1, 0, 0], levels: [0], steps: 1 },
231
+ [TWIST.M]: { axis: [1, 0, 0], levels: [1], steps: 1 },
232
+ [TWIST.MR]: { axis: [-1, 0, 0], levels: [1], steps: 1 },
233
+ [TWIST.E]: { axis: [0, 1, 0], levels: [1], steps: 1 },
234
+ [TWIST.ER]: { axis: [0, -1, 0], levels: [1], steps: 1 },
235
+ [TWIST.S]: { axis: [0, 0, -1], levels: [1], steps: 1 },
236
+ [TWIST.SR]: { axis: [0, 0, 1], levels: [1], steps: 1 },
237
+ [TWIST.U2]: { axis: [0, -1, 0], levels: [2], steps: 2 },
238
+ [TWIST.F2]: { axis: [0, 0, -1], levels: [2], steps: 2 },
239
+ [TWIST.R2]: { axis: [-1, 0, 0], levels: [2], steps: 2 },
240
+ [TWIST.D2]: { axis: [0, 1, 0], levels: [0], steps: 2 },
241
+ [TWIST.B2]: { axis: [0, 0, 1], levels: [0], steps: 2 },
242
+ [TWIST.L2]: { axis: [1, 0, 0], levels: [0], steps: 2 },
243
+ [TWIST.M2]: { axis: [1, 0, 0], levels: [1], steps: 2 },
244
+ [TWIST.E2]: { axis: [0, 1, 0], levels: [1], steps: 2 },
245
+ [TWIST.S2]: { axis: [0, 0, -1], levels: [1], steps: 2 }
246
+ };
247
+ function getStickerIndex(x, y, z, face) {
248
+ let [px, py] = [0, 0];
249
+ if (face === FACE.U) {
250
+ px = x;
251
+ py = z;
252
+ } else if (face === FACE.D) {
253
+ px = x;
254
+ py = SIDE_MAX - z;
255
+ } else if (face === FACE.F) {
256
+ px = x;
257
+ py = SIDE_MAX - y;
258
+ } else if (face === FACE.B) {
259
+ px = SIDE_MAX - x;
260
+ py = SIDE_MAX - y;
261
+ } else if (face === FACE.R) {
262
+ px = SIDE_MAX - z;
263
+ py = SIDE_MAX - y;
264
+ } else if (face === FACE.L) {
265
+ px = z;
266
+ py = SIDE_MAX - y;
267
+ }
268
+ return face * CUBE_SIZE * CUBE_SIZE + py * CUBE_SIZE + px;
269
+ }
270
+ function getCubeFromStickerIndex(index) {
271
+ const face = Math.floor(index / (CUBE_SIZE * CUBE_SIZE));
272
+ const f = index - face * (CUBE_SIZE * CUBE_SIZE);
273
+ const py = Math.floor(f / CUBE_SIZE);
274
+ const px = f % CUBE_SIZE;
275
+ let [x, y, z] = [0, 0, 0];
276
+ if (face === FACE.U) {
277
+ x = px;
278
+ z = py;
279
+ } else if (face === FACE.D) {
280
+ x = px;
281
+ z = SIDE_MAX - py;
282
+ } else if (face === FACE.F) {
283
+ x = px;
284
+ y = SIDE_MAX - py;
285
+ } else if (face === FACE.B) {
286
+ x = SIDE_MAX - px;
287
+ y = SIDE_MAX - py;
288
+ } else if (face === FACE.R) {
289
+ z = SIDE_MAX - px;
290
+ y = SIDE_MAX - py;
291
+ } else if (face === FACE.L) {
292
+ z = px;
293
+ y = SIDE_MAX - py;
294
+ }
295
+ return [x, y, z, face];
296
+ }
297
+ function getRandomTwistList(steps = 0) {
298
+ const t = steps === 0 ? Math.floor(Math.random() * (30 - 15 + 1)) + 15 : steps;
299
+ const len = SINGLE_TWIST_LIST.length;
300
+ const isOffsetting = (a, b) => {
301
+ return a !== b && (a + "'").substring(0, 2) === (b + "'").substring(0, 2);
302
+ };
303
+ const list = [];
304
+ let prev = "";
305
+ for (let i = 0; i < t; i++) {
306
+ let s;
307
+ while (isOffsetting(s = SINGLE_TWIST_LIST[Math.floor(Math.random() * len)], prev)) ;
308
+ list.push(s);
309
+ prev = s;
310
+ }
311
+ return list;
312
+ }
313
+ var SIDE_FACES = Object.freeze([
314
+ [1, 2, 4, 5],
315
+ [2, 0, 5, 3],
316
+ [0, 1, 3, 4],
317
+ [2, 1, 5, 4],
318
+ [0, 2, 3, 5],
319
+ [1, 0, 4, 3]
320
+ ]);
321
+ function getInitialState(up, front) {
322
+ const down = (up + 3) % 6;
323
+ const side = SIDE_FACES[up];
324
+ const state = new Array(CUBE_SIZE * CUBE_SIZE).fill(up);
325
+ for (let i = 0; i < 4; i++) {
326
+ if (i == 2) {
327
+ const downs = [...Array(CUBE_SIZE * CUBE_SIZE)].fill(down);
328
+ state.push(...downs);
329
+ }
330
+ const sides = [...Array(CUBE_SIZE * CUBE_SIZE)].fill(side[(front + i) % 4]);
331
+ state.push(...sides);
332
+ }
333
+ return state;
334
+ }
335
+ function isSameArrays(arr1, arr2) {
336
+ if (arr1.length !== arr2.length) return false;
337
+ return !arr1.some((v, i) => v !== arr2[i]);
338
+ }
339
+ var GOAL_STATE_LIST = [];
340
+ for (let up = 0; up < 6; up++) {
341
+ for (let front = 0; front < 4; front++) {
342
+ GOAL_STATE_LIST.push(getInitialState(up, front));
343
+ }
344
+ }
345
+ Object.freeze(GOAL_STATE_LIST);
346
+ function MatchGoalState(state) {
347
+ return GOAL_STATE_LIST.some((s) => isSameArrays(state, s));
348
+ }
349
+ var Cube = class {
350
+ type;
351
+ position;
352
+ _stickers;
353
+ _initialPosition;
354
+ constructor(x, y, z) {
355
+ this._stickers = [];
356
+ this._initialPosition = { x, y, z };
357
+ this.position = { x, y, z };
358
+ let faces = 0;
359
+ if (x === SIDE_MAX) faces++;
360
+ if (x === SIDE_MIN) faces++;
361
+ if (y === SIDE_MAX) faces++;
362
+ if (y === SIDE_MIN) faces++;
363
+ if (z === SIDE_MAX) faces++;
364
+ if (z === SIDE_MIN) faces++;
365
+ this.type = CUBETYPE_LIST[faces];
366
+ }
367
+ getStickers() {
368
+ return this._stickers;
369
+ }
370
+ init() {
371
+ const { x, y, z } = this.position;
372
+ const angles = CUBE_ANGLES[y][z][x];
373
+ this._stickers = [];
374
+ if (this.type === CUBE.CENTER) {
375
+ this._stickers = [{ face: FACE.U, color: STICKER_COLOR.PLAIN }];
376
+ } else if (this.type === CUBE.EDGE) {
377
+ this._stickers = [
378
+ { face: FACE.U, color: STICKER_COLOR.PLAIN },
379
+ { face: FACE.B, color: STICKER_COLOR.PLAIN }
380
+ ];
381
+ } else if (this.type === CUBE.CORNER) {
382
+ this._stickers = [
383
+ { face: FACE.U, color: STICKER_COLOR.PLAIN },
384
+ { face: FACE.B, color: STICKER_COLOR.PLAIN },
385
+ { face: FACE.L, color: STICKER_COLOR.PLAIN }
386
+ ];
387
+ }
388
+ this.rotateStickerFace(angles, false, true);
389
+ }
390
+ reset() {
391
+ const Faces = [FACE.U, FACE.B, FACE.L];
392
+ const { x, y, z } = this._initialPosition;
393
+ this.position = { x, y, z };
394
+ const angles = CUBE_ANGLES[y][z][x];
395
+ for (let i = 0; i < this._stickers.length; i++) {
396
+ this._stickers[i].face = Faces[i];
397
+ this._stickers[i].color = STICKER_COLOR.PLAIN;
398
+ }
399
+ this.rotateStickerFace(angles, false, true);
400
+ }
401
+ rotateStickerFace(twists, reverse = false, init = false) {
402
+ const rotateMap = [
403
+ /* x */
404
+ [FACE.U, FACE.F, FACE.D, FACE.B],
405
+ /* y */
406
+ [FACE.F, FACE.R, FACE.B, FACE.L],
407
+ /* z */
408
+ [FACE.U, FACE.L, FACE.D, FACE.R]
409
+ ];
410
+ function getNext(face, axis_index, twist) {
411
+ const { axis, steps } = TWIST_RULE[twist];
412
+ const map = rotateMap[axis_index];
413
+ const i = map.indexOf(face);
414
+ if (i < 0) return face;
415
+ const angle = axis[axis_index];
416
+ const i2 = (i + 4 + (reverse ? -1 : 1) * angle * steps) % 4;
417
+ return map[i2];
418
+ }
419
+ for (const sticker of this._stickers) {
420
+ for (const r of twists) {
421
+ sticker.face = getNext(sticker.face, 0, r);
422
+ sticker.face = getNext(sticker.face, 1, r);
423
+ sticker.face = getNext(sticker.face, 2, r);
424
+ }
425
+ if (init && sticker.color === STICKER_COLOR.PLAIN) {
426
+ sticker.color = sticker.face;
427
+ }
428
+ }
429
+ }
430
+ };
431
+ var ArcanumCube = class {
432
+ /** output debug information to console */
433
+ debug;
434
+ /** history of twisting */
435
+ _history;
436
+ /** cube objects matrix */
437
+ _matrix;
438
+ constructor(options) {
439
+ this.debug = false;
440
+ this._history = [];
441
+ this._matrix = [];
442
+ if (options) {
443
+ if (options.debug != null) {
444
+ this.debug = options.debug;
445
+ }
446
+ }
447
+ }
448
+ init() {
449
+ this._matrix = [];
450
+ const yarray = [];
451
+ for (let y = SIDE_MIN; y <= SIDE_MAX; y++) {
452
+ const zarray = [];
453
+ for (let z = SIDE_MIN; z <= SIDE_MAX; z++) {
454
+ const xarray = [];
455
+ for (let x = SIDE_MIN; x <= SIDE_MAX; x++) {
456
+ const cube = new Cube(x, y, z);
457
+ cube.init();
458
+ xarray.push(cube);
459
+ }
460
+ zarray.push(xarray);
461
+ }
462
+ yarray.push(zarray);
463
+ }
464
+ this._matrix = yarray;
465
+ }
466
+ reset() {
467
+ const list = [];
468
+ for (let y = SIDE_MIN; y <= SIDE_MAX; y++) {
469
+ for (let z = SIDE_MIN; z <= SIDE_MAX; z++) {
470
+ for (let x = SIDE_MIN; x <= SIDE_MAX; x++) {
471
+ const cube = this._matrix[y][z][x];
472
+ cube.reset();
473
+ list.push(cube);
474
+ }
475
+ }
476
+ }
477
+ list.forEach((cube) => {
478
+ const n = cube.position;
479
+ this._matrix[n.y][n.z][n.x] = cube;
480
+ });
481
+ this._history = [];
482
+ }
483
+ // twist randomly several steps
484
+ scramble(steps) {
485
+ const list = getRandomTwistList(steps);
486
+ if (this.debug) console.log("Scramble: " + list.join(", "));
487
+ this.twist(list, false);
488
+ }
489
+ undo(steps = 1) {
490
+ const list = this.getUndoList(steps);
491
+ this.twist(list, true);
492
+ }
493
+ isSolved() {
494
+ return MatchGoalState(this.getStickerColors());
495
+ }
496
+ getHistory() {
497
+ return this._history;
498
+ }
499
+ getUndoList(steps = 1) {
500
+ let t = steps;
501
+ if (t < 0) t = 0;
502
+ if (t > this._history.length) t = this._history.length;
503
+ return this._history.slice(-t).reverse();
504
+ }
505
+ twist(twist, reverse = false) {
506
+ if (Array.isArray(twist)) {
507
+ if (twist.length == 0) return;
508
+ for (const c of twist) {
509
+ this._twist(c, reverse);
510
+ }
511
+ } else {
512
+ this._twist(twist, reverse);
513
+ }
514
+ }
515
+ _twist(twist, reverse) {
516
+ this.rotateMatrix(twist, reverse);
517
+ if (this.debug) {
518
+ this.dumpStickers();
519
+ }
520
+ if (reverse) {
521
+ this._history.pop();
522
+ } else {
523
+ this._history.push(twist);
524
+ }
525
+ if (this.debug) console.log(this._history.join(" "));
526
+ }
527
+ rotateMatrix(twist, reverse = false) {
528
+ const rule = TWIST_RULE[twist];
529
+ const axis = rule.axis;
530
+ const map = new Array(3);
531
+ for (const l of rule.levels) {
532
+ let i = axis.indexOf(-1);
533
+ if (i === -1) i = axis.indexOf(1);
534
+ const s = (reverse ? -1 : 1) * axis[i];
535
+ map[i] = Array(8).fill(l);
536
+ map[(i + s + 3) % 3] = [0, 1, 2, 2, 2, 1, 0, 0];
537
+ map[(i - s + 3) % 3] = [0, 0, 0, 1, 2, 2, 2, 1];
538
+ const [x, y, z] = map;
539
+ const tmp = [];
540
+ for (let i2 = 0; i2 < 8; i2++) {
541
+ const cube = this._matrix[y[i2]][z[i2]][x[i2]];
542
+ cube.rotateStickerFace([twist], reverse);
543
+ tmp.push(cube);
544
+ }
545
+ for (let i2 = 0; i2 < 8; i2++) {
546
+ const i22 = (i2 + rule.steps * 2) % 8;
547
+ tmp[i2].position = { x: x[i22], y: y[i22], z: z[i22] };
548
+ this._matrix[y[i22]][z[i22]][x[i22]] = tmp[i2];
549
+ }
550
+ }
551
+ }
552
+ getStickerColors() {
553
+ const list = new Array(CUBE_SIZE * CUBE_SIZE * 6);
554
+ for (let y = SIDE_MIN; y <= SIDE_MAX; y++) {
555
+ for (let z = SIDE_MIN; z <= SIDE_MAX; z++) {
556
+ for (let x = SIDE_MIN; x <= SIDE_MAX; x++) {
557
+ const cube = this._matrix[y][z][x];
558
+ const stickers = cube.getStickers();
559
+ for (const sticker of stickers) {
560
+ const index = getStickerIndex(x, y, z, sticker.face);
561
+ list[index] = sticker.color;
562
+ }
563
+ }
564
+ }
565
+ }
566
+ return list;
567
+ }
568
+ dumpStickers() {
569
+ const list = this.getStickerColors();
570
+ const STYLE = "background-color:black; padding:1px 1px;";
571
+ const Col2Str = {
572
+ [STICKER_COLOR.UP]: "color:white; " + STYLE,
573
+ [STICKER_COLOR.FRONT]: "color:#00d800; " + STYLE,
574
+ [STICKER_COLOR.RIGHT]: "color:#d80000; " + STYLE,
575
+ [STICKER_COLOR.DOWN]: "color:yellow; " + STYLE,
576
+ [STICKER_COLOR.BACK]: "color:#0000d8; " + STYLE,
577
+ [STICKER_COLOR.LEFT]: "color:#ff8000; " + STYLE
578
+ };
579
+ const RESET = "background-color:none; padding:0px 0px;";
580
+ const result = [];
581
+ const attrs = [];
582
+ const getLine = (faces) => {
583
+ const line = [];
584
+ for (let py = 0; py < 3; py++) {
585
+ for (const f of faces) {
586
+ if (f === -1) {
587
+ line.push(" ");
588
+ } else {
589
+ line.push("%c\u25A0 %c\u25A0 %c\u25A0%c ");
590
+ const index = f * CUBE_SIZE * CUBE_SIZE + py * CUBE_SIZE;
591
+ attrs.push(Col2Str[list[index + 0]]);
592
+ attrs.push(Col2Str[list[index + 1]]);
593
+ attrs.push(Col2Str[list[index + 2]]);
594
+ attrs.push(RESET);
595
+ }
596
+ }
597
+ line.push("\n");
598
+ }
599
+ line.push("\n");
600
+ result.push(line.join(""));
601
+ };
602
+ getLine([-1, FACE.U]);
603
+ getLine([FACE.L, FACE.F, FACE.R, FACE.B]);
604
+ getLine([-1, FACE.D]);
605
+ console.log(result.join("\n"), ...attrs);
606
+ }
607
+ };
608
+ var STICKER_PERMUTATION_GROUP_MAP = makeStickerPermutationGroupMap();
609
+ function makeStickerPermutationGroupMap() {
610
+ const result = {};
611
+ TWIST_LIST.forEach((twist) => {
612
+ const tmp = getCubePermutationGroup(twist).stickers;
613
+ result[twist] = [tmp.before, tmp.after];
614
+ });
615
+ return result;
616
+ }
617
+ function getNextStickerColors(stickers, twist) {
618
+ const result = [...stickers];
619
+ const [bef, aft] = STICKER_PERMUTATION_GROUP_MAP[twist];
620
+ for (let i = 0; i < bef.length; i++) {
621
+ result[aft[i]] = stickers[bef[i]];
622
+ }
623
+ return result;
624
+ }
625
+ function getArrayForTensor(stickers) {
626
+ const array = [...Array(3)].map(
627
+ () => [...Array(3)].map(() => Array(6 * 6).fill(0))
628
+ );
629
+ for (let i = 0; i < stickers.length; i++) {
630
+ const face = Math.floor(i / (CUBE_SIZE * CUBE_SIZE));
631
+ const c = i - face * (CUBE_SIZE * CUBE_SIZE);
632
+ const row = Math.floor(c / CUBE_SIZE);
633
+ const column = c - row * CUBE_SIZE;
634
+ const color = stickers[i];
635
+ array[row][column][color * 6 + face] = 1;
636
+ }
637
+ return array;
638
+ }
639
+ function getCubePermutationGroup(twist, reverse = false) {
640
+ const rule = TWIST_RULE[twist];
641
+ const axis = rule.axis;
642
+ const result = { before: [], after: [], stickers: { before: [], after: [] } };
643
+ const map = new Array(3);
644
+ for (const l of rule.levels) {
645
+ let i = axis.indexOf(-1);
646
+ if (i === -1) i = axis.indexOf(1);
647
+ const s = (reverse ? -1 : 1) * axis[i];
648
+ map[i] = Array(8).fill(l);
649
+ map[(i + s + 3) % 3] = [0, 1, 2, 2, 2, 1, 0, 0];
650
+ map[(i - s + 3) % 3] = [0, 0, 0, 1, 2, 2, 2, 1];
651
+ const [x, y, z] = map;
652
+ for (let i2 = 0; i2 < 8; i2++) {
653
+ const i22 = (i2 + rule.steps * 2) % 8;
654
+ result.before.push([x[i2], y[i2], z[i2]]);
655
+ result.after.push([x[i22], y[i22], z[i22]]);
656
+ const list = getStickerPermutationGroup(
657
+ [x[i2], y[i2], z[i2]],
658
+ [x[i22], y[i22], z[i22]],
659
+ [twist],
660
+ reverse
661
+ );
662
+ result.stickers.before.push(...list.before);
663
+ result.stickers.after.push(...list.after);
664
+ }
665
+ }
666
+ return result;
667
+ }
668
+ function getStickerPermutationGroup(position, position2, twists, reverse = false) {
669
+ const rotateMap = [
670
+ /* x */
671
+ [FACE.U, FACE.F, FACE.D, FACE.B],
672
+ /* y */
673
+ [FACE.F, FACE.R, FACE.B, FACE.L],
674
+ /* z */
675
+ [FACE.U, FACE.L, FACE.D, FACE.R]
676
+ ];
677
+ function getNext(face, axis_index, twist) {
678
+ const { axis, steps } = TWIST_RULE[twist];
679
+ const map = rotateMap[axis_index];
680
+ const i = map.indexOf(face);
681
+ if (i < 0) return face;
682
+ const angle = axis[axis_index];
683
+ const i2 = (i + 4 + (reverse ? -1 : 1) * angle * steps) % 4;
684
+ return map[i2];
685
+ }
686
+ const result = { before: [], after: [] };
687
+ const [x, y, z] = position;
688
+ const [x2, y2, z2] = position2;
689
+ const faces = [];
690
+ if (x === SIDE_MAX) faces.push(FACE.R);
691
+ if (x === SIDE_MIN) faces.push(FACE.L);
692
+ if (y === SIDE_MAX) faces.push(FACE.U);
693
+ if (y === SIDE_MIN) faces.push(FACE.D);
694
+ if (z === SIDE_MAX) faces.push(FACE.F);
695
+ if (z === SIDE_MIN) faces.push(FACE.B);
696
+ for (const face of faces) {
697
+ let f = face;
698
+ result.before.push(getStickerIndex(x, y, z, f));
699
+ for (const t of twists) {
700
+ f = getNext(f, 0, t);
701
+ f = getNext(f, 1, t);
702
+ f = getNext(f, 2, t);
703
+ }
704
+ result.after.push(getStickerIndex(x2, y2, z2, f));
705
+ }
706
+ return result;
707
+ }
708
+ // Annotate the CommonJS export names for ESM import in node:
709
+ 0 && (module.exports = {
710
+ ArcanumCube,
711
+ CUBE,
712
+ CUBE_ANGLES,
713
+ CUBE_SIZE,
714
+ Cube,
715
+ DOUBLE_TWIST_LIST,
716
+ FACE,
717
+ MatchGoalState,
718
+ SIDE_MAX,
719
+ SIDE_MIDDLE,
720
+ SIDE_MIN,
721
+ SINGLE_TWIST_LIST,
722
+ STICKER_COLOR,
723
+ TWIST,
724
+ TWIST_LIST,
725
+ TWIST_RULE,
726
+ getArrayForTensor,
727
+ getCubeFromStickerIndex,
728
+ getCubePermutationGroup,
729
+ getNextStickerColors,
730
+ getRandomTwistList,
731
+ getStickerIndex,
732
+ getStickerPermutationGroup
733
+ });