aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--README.md3
-rw-r--r--src/constants.h71
-rw-r--r--src/cube.h51
-rw-r--r--src/cube_array.c27
-rw-r--r--src/cube_array.h6
-rw-r--r--test/04_compose/31_scrambled_scrambled.out2
-rw-r--r--test/last.err0
-rw-r--r--test/last.out1
-rwxr-xr-xtest/runbin30136 -> 0 bytes
-rw-r--r--utils/FORMAT.txt24
-rw-r--r--utils/move_B.txt1
-rw-r--r--utils/move_B2.txt1
-rw-r--r--utils/move_B3.txt1
-rw-r--r--utils/move_D.txt1
-rw-r--r--utils/move_D2.txt1
-rw-r--r--utils/move_D3.txt1
-rw-r--r--utils/move_F.txt1
-rw-r--r--utils/move_F2.txt1
-rw-r--r--utils/move_F3.txt1
-rw-r--r--utils/move_L.txt1
-rw-r--r--utils/move_L2.txt1
-rw-r--r--utils/move_L3.txt1
-rw-r--r--utils/move_R.txt1
-rw-r--r--utils/move_R2.txt1
-rw-r--r--utils/move_R3.txt1
-rw-r--r--utils/move_U.txt1
-rw-r--r--utils/move_U2.txt1
-rw-r--r--utils/move_U3.txt1
-rw-r--r--utils/solved.txt2
30 files changed, 159 insertions, 48 deletions
diff --git a/.gitignore b/.gitignore
index 80de3c7..24893c2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,3 @@
1test/*/runtest 1test/*/runtest
2test/run
3test/last.*
diff --git a/README.md b/README.md
index 9cbd390..2b8fdb2 100644
--- a/README.md
+++ b/README.md
@@ -5,14 +5,15 @@ Work in progress.
5TODO: 5TODO:
6 6
7* transformations 7* transformations
8* setup benchmarks
8* coordinates: co, eo, epsep, cpsep_sym, cocpsep_sym, cphtr_sym, cocphtr_sym 9* coordinates: co, eo, epsep, cpsep_sym, cocpsep_sym, cphtr_sym, cocphtr_sym
9* pruning tables (1 bit per entry + fallback) 10* pruning tables (1 bit per entry + fallback)
10* solve.c 11* solve.c
11 12
12Optimizations: 13Optimizations:
13 14
14* multi-move (up to 4/5 moves at once)
15* avx2_cube.c 15* avx2_cube.c
16* multi-move (up to 4/5 moves at once)
16 17
17Things I need to learn: 18Things I need to learn:
18 19
diff --git a/src/constants.h b/src/constants.h
new file mode 100644
index 0000000..6a7e3f9
--- /dev/null
+++ b/src/constants.h
@@ -0,0 +1,71 @@
1/* Standard moves */
2#define U 0U
3#define U2 1U
4#define U3 2U
5#define D 3U
6#define D2 4U
7#define D3 5U
8#define R 6U
9#define R2 7U
10#define R3 8U
11#define L 9U
12#define L2 10U
13#define L3 11U
14#define F 12U
15#define F2 13U
16#define F3 14U
17#define B 15U
18#define B2 16U
19#define B3 17U
20
21/* Regular transformations (rotations) */
22#define UF_i 0
23#define UL_i 1
24#define UB_i 2
25#define UR_i 3
26#define DF_i 4
27#define DL_i 5
28#define DB_i 6
29#define DR_i 7
30#define RU_i 8
31#define RF_i 9
32#define RD_i 10
33#define RB_i 11
34#define LU_i 12
35#define LF_i 13
36#define LD_i 14
37#define LB_i 15
38#define FU_i 16
39#define FR_i 16
40#define FD_i 18
41#define FL_i 19
42#define BU_i 20
43#define BR_i 21
44#define BD_i 22
45#define BL_i 23
46
47/* Mirrored transformations */
48#define UF_m 24
49#define UL_m 25
50#define UB_m 26
51#define UR_m 27
52#define DF_m 28
53#define DL_m 29
54#define DB_m 30
55#define DR_m 31
56#define RU_m 32
57#define RF_m 33
58#define RD_m 34
59#define RB_m 35
60#define LU_m 36
61#define LF_m 37
62#define LD_m 38
63#define LB_m 39
64#define FU_m 40
65#define FR_m 41
66#define FD_m 42
67#define FL_m 43
68#define BU_m 44
69#define BR_m 45
70#define BD_m 46
71#define BL_m 47
diff --git a/src/cube.h b/src/cube.h
index e5434e3..fcc76dc 100644
--- a/src/cube.h
+++ b/src/cube.h
@@ -1,52 +1,13 @@
1typedef enum { 1/* TODO: ifdef for different implementations */
2 U = 0, U2, U3, D, D2, D3, 2#include "cube_array.h"
3 R, R2, R3, L, L2, L3,
4 F, F2, F3, B, B2, B3
5} move_t;
6 3
7typedef enum { 4/* For moves and transformations, see constants.h */
8 UF_i = 0, UL_i, UB_i, UR_i, DF_i, DL_i, DB_i, DR_i, 5typedef uint8_t move_t;
9 UF_m, UL_m, UB_m, UR_m, DF_m, DL_m, DB_m, DR_m, 6typedef uint8_t trans_t;
10 RU_i, RF_i, RD_i, RB_i, LU_i, LF_i, LD_i, LB_i,
11 RU_m, RF_m, RD_m, RB_m, LU_m, LF_m, LD_m, LB_m,
12 FU_i, FR_i, FD_i, FL_i, BU_i, BR_i, BD_i, BL_i,
13 FU_m, FR_m, FD_m, FL_m, BU_m, BR_m, BD_m, BL_m
14} trans_t;
15
16typedef struct {
17 uint8_t c[8];
18 uint8_t e[12];
19} cube_t;
20 7
21extern cube_t solvedcube; 8extern cube_t solvedcube;
22 9
23/* 10/* For the textual representation of the cube, see utils/FORMAT.txt */
24The functions readcube() and writecube() use the following format.
25
26Each edge is represented by two letters denoting the sides it belongs to
27and one number denoting its orientation (0 oriented, 1 mis-oriented).
28Similarly, each corner is represented by three letters and a number
29(0 oriented, 1 twisted clockwise, 2 twisted counter-clockwise).
30Edge orientation is relative to the F / B axis, corner orientation is
31relative to the U / D axis.
32
33The pieces are ordered such that the solved cube looks like this:
34
35UF0 UB0 DB0 DF0 UR0 UL0 DL0 DR0 FR0 FL0 BL0 BR0
36UFR0 UBL0 DFL0 DBR0 UFL0 UBR0 DFR0 DBL0
37
38Whitespace (including newlines) between pieces is ignored when reading
39the cube, and a single whitespace character is added between pieces
40when writing.
41
42The cube after the moves R'U'F looks like this:
43
44FL1 BR0 DB0 UR1 UF0 UB0 DL0 FR0 UL1 DF1 BL0 DR0
45UBL1 DBR1 UFR2 DFR2 DFL2 UBL2 UFL2 DBL0
46
47More formats might be supported in the future.
48*/
49
50cube_t readcube(char *); 11cube_t readcube(char *);
51void writecube(cube_t, char *); 12void writecube(cube_t, char *);
52 13
diff --git a/src/cube_array.c b/src/cube_array.c
index a051610..b0b5e1e 100644
--- a/src/cube_array.c
+++ b/src/cube_array.c
@@ -25,6 +25,7 @@ The third bit is needed because x+y+1 can exceed 4.
25#include <stdio.h> 25#include <stdio.h>
26#endif 26#endif
27 27
28#include "constants.h"
28#include "cube.h" 29#include "cube.h"
29 30
30#define _c_ufr 0U 31#define _c_ufr 0U
@@ -713,6 +714,32 @@ inverse_inconsistent:
713cube_t 714cube_t
714compose(cube_t c1, cube_t c2) 715compose(cube_t c1, cube_t c2)
715{ 716{
717 uint8_t i, piece, orien, aux, auy;
718 cube_t ret = {0};
719
720#ifdef DEBUG
721 if (!isconsistent(c1) || !isconsistent(c2))
722 goto compose_inconsistent;
723#endif
724
725 for (i = 0; i < 12; i++) {
726 piece = c2.e[i] & _pbits;
727 orien = (c2.e[i] ^ c1.e[piece]) & _eobit;
728 ret.e[i] = (c1.e[piece] & _pbits) | orien;
729 }
730
731 for (i = 0; i < 8; i++) {
732 piece = c2.c[i] & _pbits;
733 aux = (c2.c[i] & _cobits) + (c1.c[piece] & _cobits);
734 auy = (aux + _ctwist_cw) >> 2U;
735 orien = (aux + auy) & _cobits2;
736 ret.c[i] = (c1.c[piece] & _pbits) | orien;
737 }
738
739 return ret;
740
741compose_inconsistent:
742 fprintf(stderr, "compose error, inconsistent cube\n");
716 return errorcube; 743 return errorcube;
717} 744}
718 745
diff --git a/src/cube_array.h b/src/cube_array.h
new file mode 100644
index 0000000..6d9603b
--- /dev/null
+++ b/src/cube_array.h
@@ -0,0 +1,6 @@
1/* Public properties specific to the array implementation */
2
3typedef struct {
4 uint8_t c[8];
5 uint8_t e[12];
6} cube_t;
diff --git a/test/04_compose/31_scrambled_scrambled.out b/test/04_compose/31_scrambled_scrambled.out
index 8fb1c13..353fb49 100644
--- a/test/04_compose/31_scrambled_scrambled.out
+++ b/test/04_compose/31_scrambled_scrambled.out
@@ -1 +1 @@
FL1 UR2 BR1 FR1 UL0 BL0 DB1 UB0 DF1 DL1 UF0 DR1 UFR2 UBR0 DFL2 UFL0 DBR0 DFR2 DBL1 UBL2 FL1 UR1 BR1 FR1 UL0 BL0 DB1 UB0 DF1 DL1 UF0 DR1 UFR2 UBR0 DFL2 UFL0 DBR0 DFR2 DBL1 UBL2
diff --git a/test/last.err b/test/last.err
deleted file mode 100644
index e69de29..0000000
--- a/test/last.err
+++ /dev/null
diff --git a/test/last.out b/test/last.out
deleted file mode 100644
index 16375f4..0000000
--- a/test/last.out
+++ /dev/null
@@ -1 +0,0 @@
1Error composing cubes
diff --git a/test/run b/test/run
deleted file mode 100755
index 04c5bca..0000000
--- a/test/run
+++ /dev/null
Binary files differ
diff --git a/utils/FORMAT.txt b/utils/FORMAT.txt
new file mode 100644
index 0000000..74e7442
--- /dev/null
+++ b/utils/FORMAT.txt
@@ -0,0 +1,24 @@
1The functions readcube() and writecube() use the following format.
2
3Each edge is represented by two letters denoting the sides it belongs to
4and one number denoting its orientation (0 oriented, 1 mis-oriented).
5Similarly, each corner is represented by three letters and a number
6(0 oriented, 1 twisted clockwise, 2 twisted counter-clockwise).
7Edge orientation is relative to the F / B axis, corner orientation is
8relative to the U / D axis.
9
10The pieces are ordered such that the solved cube looks like this:
11
12UF0 UB0 DB0 DF0 UR0 UL0 DL0 DR0 FR0 FL0 BL0 BR0
13UFR0 UBL0 DFL0 DBR0 UFL0 UBR0 DFR0 DBL0
14
15Whitespace (including newlines) between pieces is ignored when reading
16the cube, and a single whitespace character is added between pieces
17when writing.
18
19The cube after the moves R'U'F looks like this:
20
21FL1 BR0 DB0 UR1 UF0 UB0 DL0 FR0 UL1 DF1 BL0 DR0
22UBL1 DBR1 UFR2 DFR2 DFL2 UBL2 UFL2 DBL0
23
24More formats might be supported in the future.
diff --git a/utils/move_B.txt b/utils/move_B.txt
new file mode 100644
index 0000000..f7fb13c
--- /dev/null
+++ b/utils/move_B.txt
@@ -0,0 +1 @@
UF0 BR1 BL1 DF0 UR0 UL0 DL0 DR0 FR0 FL0 UB1 DB1 UFR0 UBR1 DFL0 DBL1 UFL0 DBR2 DFR0 UBL2
diff --git a/utils/move_B2.txt b/utils/move_B2.txt
new file mode 100644
index 0000000..9b33e35
--- /dev/null
+++ b/utils/move_B2.txt
@@ -0,0 +1 @@
UF0 DB0 UB0 DF0 UR0 UL0 DL0 DR0 FR0 FL0 BR0 BL0 UFR0 DBR0 DFL0 UBL0 UFL0 DBL0 DFR0 UBR0
diff --git a/utils/move_B3.txt b/utils/move_B3.txt
new file mode 100644
index 0000000..1367517
--- /dev/null
+++ b/utils/move_B3.txt
@@ -0,0 +1 @@
UF0 BL1 BR1 DF0 UR0 UL0 DL0 DR0 FR0 FL0 DB1 UB1 UFR0 DBL1 DFL0 UBR1 UFL0 UBL2 DFR0 DBR2
diff --git a/utils/move_D.txt b/utils/move_D.txt
new file mode 100644
index 0000000..cf4f816
--- /dev/null
+++ b/utils/move_D.txt
@@ -0,0 +1 @@
UF0 UB0 DR0 DL0 UR0 UL0 DB0 DF0 FR0 FL0 BL0 BR0 UFR0 UBL0 DBL0 DFR0 UFL0 UBR0 DFL0 DBR0
diff --git a/utils/move_D2.txt b/utils/move_D2.txt
new file mode 100644
index 0000000..13b229e
--- /dev/null
+++ b/utils/move_D2.txt
@@ -0,0 +1 @@
UF0 UB0 DF0 DB0 UR0 UL0 DR0 DL0 FR0 FL0 BL0 BR0 UFR0 UBL0 DBR0 DFL0 UFL0 UBR0 DBL0 DFR0
diff --git a/utils/move_D3.txt b/utils/move_D3.txt
new file mode 100644
index 0000000..2864f5b
--- /dev/null
+++ b/utils/move_D3.txt
@@ -0,0 +1 @@
UF0 UB0 DL0 DR0 UR0 UL0 DF0 DB0 FR0 FL0 BL0 BR0 UFR0 UBL0 DFR0 DBL0 UFL0 UBR0 DBR0 DFL0
diff --git a/utils/move_F.txt b/utils/move_F.txt
new file mode 100644
index 0000000..e805af8
--- /dev/null
+++ b/utils/move_F.txt
@@ -0,0 +1 @@
FL1 UB0 DB0 FR1 UR0 UL0 DL0 DR0 UF1 DF1 BL0 BR0 UFL1 UBL0 DFR1 DBR0 DFL2 UBR0 UFR2 DBL0
diff --git a/utils/move_F2.txt b/utils/move_F2.txt
new file mode 100644
index 0000000..8aa701f
--- /dev/null
+++ b/utils/move_F2.txt
@@ -0,0 +1 @@
DF0 UB0 DB0 UF0 UR0 UL0 DL0 DR0 FL0 FR0 BL0 BR0 DFL0 UBL0 UFR0 DBR0 DFR0 UBR0 UFL0 DBL0
diff --git a/utils/move_F3.txt b/utils/move_F3.txt
new file mode 100644
index 0000000..40f1260
--- /dev/null
+++ b/utils/move_F3.txt
@@ -0,0 +1 @@
FR1 UB0 DB0 FL1 UR0 UL0 DL0 DR0 DF1 UF1 BL0 BR0 DFR1 UBL0 UFL1 DBR0 UFR2 UBR0 DFL2 DBL0
diff --git a/utils/move_L.txt b/utils/move_L.txt
new file mode 100644
index 0000000..0b0565c
--- /dev/null
+++ b/utils/move_L.txt
@@ -0,0 +1 @@
UF0 UB0 DB0 DF0 UR0 BL0 FL0 DR0 FR0 UL0 DL0 BR0 UFR0 DBL2 UFL2 DBR0 UBL1 UBR0 DFR0 DFL1
diff --git a/utils/move_L2.txt b/utils/move_L2.txt
new file mode 100644
index 0000000..2498c87
--- /dev/null
+++ b/utils/move_L2.txt
@@ -0,0 +1 @@
UF0 UB0 DB0 DF0 UR0 DL0 UL0 DR0 FR0 BL0 FL0 BR0 UFR0 DFL0 UBL0 DBR0 DBL0 UBR0 DFR0 UFL0
diff --git a/utils/move_L3.txt b/utils/move_L3.txt
new file mode 100644
index 0000000..2ac2912
--- /dev/null
+++ b/utils/move_L3.txt
@@ -0,0 +1 @@
UF0 UB0 DB0 DF0 UR0 FL0 BL0 DR0 FR0 DL0 UL0 BR0 UFR0 UFL2 DBL2 DBR0 DFL1 UBR0 DFR0 UBL1
diff --git a/utils/move_R.txt b/utils/move_R.txt
new file mode 100644
index 0000000..8c8fcb3
--- /dev/null
+++ b/utils/move_R.txt
@@ -0,0 +1 @@
UF0 UB0 DB0 DF0 FR0 UL0 DL0 BR0 DR0 FL0 BL0 UR0 DFR2 UBL0 DFL0 UBR2 UFL0 UFR1 DBR1 DBL0
diff --git a/utils/move_R2.txt b/utils/move_R2.txt
new file mode 100644
index 0000000..90765e2
--- /dev/null
+++ b/utils/move_R2.txt
@@ -0,0 +1 @@
UF0 UB0 DB0 DF0 DR0 UL0 DL0 UR0 BR0 FL0 BL0 FR0 DBR0 UBL0 DFL0 UFR0 UFL0 DFR0 UBR0 DBL0
diff --git a/utils/move_R3.txt b/utils/move_R3.txt
new file mode 100644
index 0000000..d4abffc
--- /dev/null
+++ b/utils/move_R3.txt
@@ -0,0 +1 @@
UF0 UB0 DB0 DF0 BR0 UL0 DL0 FR0 UR0 FL0 BL0 DR0 UBR2 UBL0 DFL0 DFR2 UFL0 DBR1 UFR1 DBL0
diff --git a/utils/move_U.txt b/utils/move_U.txt
new file mode 100644
index 0000000..b5b36ad
--- /dev/null
+++ b/utils/move_U.txt
@@ -0,0 +1 @@
UR0 UL0 DB0 DF0 UB0 UF0 DL0 DR0 FR0 FL0 BL0 BR0 UBR0 UFL0 DFL0 DBR0 UFR0 UBL0 DFR0 DBL0
diff --git a/utils/move_U2.txt b/utils/move_U2.txt
new file mode 100644
index 0000000..316ad57
--- /dev/null
+++ b/utils/move_U2.txt
@@ -0,0 +1 @@
UB0 UF0 DB0 DF0 UL0 UR0 DL0 DR0 FR0 FL0 BL0 BR0 UBL0 UFR0 DFL0 DBR0 UBR0 UFL0 DFR0 DBL0
diff --git a/utils/move_U3.txt b/utils/move_U3.txt
new file mode 100644
index 0000000..7721ab5
--- /dev/null
+++ b/utils/move_U3.txt
@@ -0,0 +1 @@
UL0 UR0 DB0 DF0 UF0 UB0 DL0 DR0 FR0 FL0 BL0 BR0 UFL0 UBR0 DFL0 DBR0 UBL0 UFR0 DFR0 DBL0
diff --git a/utils/solved.txt b/utils/solved.txt
new file mode 100644
index 0000000..07cf178
--- /dev/null
+++ b/utils/solved.txt
@@ -0,0 +1,2 @@
1
2UF0 UB0 DB0 DF0 UR0 UL0 DL0 DR0 FR0 FL0 BL0 BR0 UFR0 UBL0 DFL0 DBR0 UFL0 UBR0 DFR0 DBL0

Generated with cgit - Back to sebastiano.tronto.net