commit a4598b740fe4b8350b7d09a575c793113c8fde2b
parent 3ab2f98170908277f70191846e84e5dde185a056
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date: Sat, 13 Apr 2024 15:57:23 +0200
Some renaming, moved stuff around
Diffstat:
14 files changed, 97 insertions(+), 97 deletions(-)
diff --git a/README.md b/README.md
@@ -3,3 +3,59 @@
A simple set of basic routines for working with a 3x3x3 Rubik's Cube.
Work in progress.
+
+## How to use CubeCore
+
+TODO
+
+## The cube
+
+Each piece is represented by an (unsigned) 8-bit integer. The 4
+least-significant bits determine which piece it is, the other 4 determine
+the orientation.
+
+Edges are numbered as follows (see also cube.c):
+UF=0 UB=1 DB=2 DF=3 UR=4 UL=5 DL=6 DR=7 FR=8 FL=9 BL=10 BR=11
+
+Corners are numbered as follows:
+UFR=0 UBL=1 DFL=2 DBR=3 UFL=4 UBR=5 DFR=6 DBL=7
+
+The orientation of the edges is with respect to F/B, the orientation of
+corners is with respect to U/D.
+
+The permutation of the center pieces is not stored. This means that the
+cube is assumed to be in a fixed orientation.
+
+## I/O format
+
+Reading and writing is not done directly via stdin / stdout, but via an
+array of char (called buf in the prototypes below).
+
+Multiple representations of the cube as text are supported:
+
+- H48: a human-readable format.
+ Each edge is represented by two letters denoting the sides it
+ belongs to and one number denoting its orientation (0 oriented, 1
+ mis-oriented). Similarly, each corner is represented by three letters and
+ a number (0 oriented, 1 twisted clockwise, 2 twisted counter-clockwise).
+
+ The solved cube looks like this:
+
+ UF0 UB0 DB0 DF0 UR0 UL0 DL0 DR0 FR0 FL0 BL0 BR0
+ UFR0 UBL0 DFL0 DBR0 UFL0 UBR0 DFR0 DBL0
+
+ The cube after the moves R'U'F looks like this:
+
+ FL1 BR0 DB0 UR1 UF0 UB0 DL0 FR0 UL1 DF1 BL0 DR0
+ UBL1 DBR1 UFR2 DFR2 DFL2 UBL2 UFL2 DBL0
+
+ Whitespace (including newlines) between pieces is ignored when reading the
+ cube. A single whitespace character is added between pieces when writing.
+
+- SRC: format used to generate code for internal use.
+ If OUT is the output in SRC format, one can use `cube_t cube = OUT` to
+ declare a new cube object.
+
+- LST: a format for internal use and generating code.
+ The cube is printed as a comma-separated list of 20 integers, as they appear
+ in cube_t. Corners come first, followed by edge (unlike H48).
diff --git a/cube.c b/cube.c
@@ -35,12 +35,12 @@ _static uint8_t readco(char *);
_static uint8_t readcp(char *);
_static uint8_t readeo(char *);
_static uint8_t readep(char *);
-_static cube_t readcube_H48(char *);
+_static cube_t read_H48(char *);
_static uint8_t readpiece_LST(char **);
-_static cube_t readcube_LST(char *);
+_static cube_t read_LST(char *);
_static int writepiece_LST(uint8_t, char *);
-_static void writecube_H48(cube_t, char *);
-_static void writecube_LST(cube_t, char *);
+_static void write_H48(cube_t, char *);
+_static void write_LST(cube_t, char *);
_static uint8_t readmove(char);
_static uint8_t readmodifier(char);
_static uint8_t readtrans(char *);
@@ -322,14 +322,14 @@ cube_coord_eo(cube_t c)
}
cube_t
-readcube(char *format, char *buf)
+cube_read(char *format, char *buf)
{
cube_t cube;
if (!strcmp(format, "H48")) {
- cube = readcube_H48(buf);
+ cube = read_H48(buf);
} else if (!strcmp(format, "LST")) {
- cube = readcube_LST(buf);
+ cube = read_LST(buf);
} else {
DBG_LOG("Cannot read cube in the given format\n");
cube = zero;
@@ -339,29 +339,29 @@ readcube(char *format, char *buf)
}
void
-writecube(char *format, cube_t cube, char *buf)
+cube_write(char *format, cube_t cube, char *buf)
{
char *errormsg;
size_t len;
if (!cube_consistent(cube)) {
errormsg = "ERROR: cannot write inconsistent cube";
- goto writecube_error;
+ goto write_error;
}
if (!strcmp(format, "H48")) {
- writecube_H48(cube, buf);
+ write_H48(cube, buf);
} else if (!strcmp(format, "LST")) {
- writecube_LST(cube, buf);
+ write_LST(cube, buf);
} else {
errormsg = "ERROR: cannot write cube in the given format";
- goto writecube_error;
+ goto write_error;
}
return;
-writecube_error:
- DBG_LOG("writecube error, see stdout for details\n");
+write_error:
+ DBG_LOG("cube_write error, see stdout for details\n");
len = strlen(errormsg);
memcpy(buf, errormsg, len);
buf[len] = '\n';
@@ -435,7 +435,7 @@ readep(char *str)
}
_static cube_t
-readcube_H48(char *buf)
+read_H48(char *buf)
{
int i;
uint8_t piece, orient;
@@ -488,7 +488,7 @@ readpiece_LST(char **b)
}
_static cube_t
-readcube_LST(char *buf)
+read_LST(char *buf)
{
int i;
cube_t ret = {0};
@@ -526,7 +526,7 @@ writepiece_LST(uint8_t piece, char *buf)
}
_static void
-writecube_H48(cube_t cube, char *buf)
+write_H48(cube_t cube, char *buf)
{
uint8_t piece, perm, orient;
int i;
@@ -555,7 +555,7 @@ writecube_H48(cube_t cube, char *buf)
}
_static void
-writecube_LST(cube_t cube, char *buf)
+write_LST(cube_t cube, char *buf)
{
int i, ptr;
uint8_t piece;
diff --git a/cube.h b/cube.h
@@ -1,23 +1,3 @@
-/******************************************************************************
-Cube type definition
-
-Each piece is represented by an (unsigned) 8-bit integer. The 4
-least-significant bits determine which piece it is, the other 4 determine
-the orientation.
-
-Edges are numbered as follows (see also cube.c):
-UF=0 UB=1 DB=2 DF=3 UR=4 UL=5 DL=6 DR=7 FR=8 FL=9 BL=10 BR=11
-
-Corners are numbered as follows:
-UFR=0 UBL=1 DFL=2 DBR=3 UFL=4 UBR=5 DFR=6 DBL=7
-
-The orientation of the edges is with respect to F/B, the orientation of
-corners is with respect to U/D.
-
-The permutation of the center pieces is not stored. This means that the
-cube is assumed to be in a fixed orientation.
-******************************************************************************/
-
typedef struct {
uint8_t corner[8];
uint8_t edge[12];
@@ -36,41 +16,5 @@ cube_t cube_inverse(cube_t);
int64_t cube_coord_co(cube_t);
int64_t cube_coord_eo(cube_t);
-/******************************************************************************
-Read / write utilities
-
-Reading and writing is not done directly via stdin / stdout, but via an
-array of char (called buf in the prototypes below).
-
-Multiple representations of the cube as text are supported:
-
-- H48: a human-readable format.
- Each edge is represented by two letters denoting the sides it
- belongs to and one number denoting its orientation (0 oriented, 1
- mis-oriented). Similarly, each corner is represented by three letters and
- a number (0 oriented, 1 twisted clockwise, 2 twisted counter-clockwise).
-
- The solved cube looks like this:
-
- UF0 UB0 DB0 DF0 UR0 UL0 DL0 DR0 FR0 FL0 BL0 BR0
- UFR0 UBL0 DFL0 DBR0 UFL0 UBR0 DFR0 DBL0
-
- The cube after the moves R'U'F looks like this:
-
- FL1 BR0 DB0 UR1 UF0 UB0 DL0 FR0 UL1 DF1 BL0 DR0
- UBL1 DBR1 UFR2 DFR2 DFL2 UBL2 UFL2 DBL0
-
- Whitespace (including newlines) between pieces is ignored when reading the
- cube. A single whitespace character is added between pieces when writing.
-
-- SRC: format used to generate code for internal use.
- If OUT is the output in SRC format, one can use `cube_t cube = OUT` to
- declare a new cube object.
-
-- LST: a format for internal use and generating code.
- The cube is printed as a comma-separated list of 20 integers, as they appear
- in cube_t. Corners come first, followed by edge (unlike H48).
-******************************************************************************/
-
-cube_t readcube(char *format, char *buf);
-void writecube(char *format, cube_t cube, char *buf);
+cube_t cube_read(char *format, char *buf);
+void cube_write(char *format, cube_t cube, char *buf);
diff --git a/test/020_io_H48_read_write/io_H48_tests.c b/test/020_io_H48_read_write/io_H48_tests.c
@@ -9,14 +9,14 @@ int main(void) {
while (*aux != '\n')
aux++;
- cube = readcube("H48", str);
+ cube = cube_read("H48", str);
if (cube_error(cube)) {
printf("Error reading cube\n");
} else if (!cube_solvable(cube)) {
printf("Cube is not solvable\n");
} else {
- writecube("H48", cube, str);
+ cube_write("H48", cube, str);
printf("%s\n", str);
}
diff --git a/test/023_io_LST_write/io_LST_tests.c b/test/023_io_LST_write/io_LST_tests.c
@@ -9,14 +9,14 @@ int main(void) {
while (*aux != '\n')
aux++;
- cube = readcube("H48", str);
+ cube = cube_read("H48", str);
if (cube_error(cube)) {
printf("Error reading cube\n");
} else if (!cube_solvable(cube)) {
printf("Cube is not solvable\n");
} else {
- writecube("LST", cube, str);
+ cube_write("LST", cube, str);
printf("%s\n", str);
}
diff --git a/test/024_io_LST_read/io_LST_tests.c b/test/024_io_LST_read/io_LST_tests.c
@@ -9,14 +9,14 @@ int main(void) {
while (*aux != '\n')
aux++;
- cube = readcube("LST", str);
+ cube = cube_read("LST", str);
if (cube_error(cube)) {
printf("Error reading cube\n");
} else if (!cube_solvable(cube)) {
printf("Cube is not solvable\n");
} else {
- writecube("H48", cube, str);
+ cube_write("H48", cube, str);
printf("%s\n", str);
}
diff --git a/test/030_move/move_tests.c b/test/030_move/move_tests.c
@@ -8,7 +8,7 @@ int main(void) {
fgets(movestr, STRLENMAX, stdin);
fgets(cubestr, STRLENMAX, stdin);
- cube = readcube("H48", cubestr);
+ cube = cube_read("H48", cubestr);
cube = applymoves(cube, movestr);
@@ -17,7 +17,7 @@ int main(void) {
} else if (!cube_solvable(cube)) {
printf("Moved cube is not solvable\n");
} else {
- writecube("H48", cube, cubestr);
+ cube_write("H48", cube, cubestr);
printf("%s\n", cubestr);
}
diff --git a/test/040_inverse_cube/inverse_tests.c b/test/040_inverse_cube/inverse_tests.c
@@ -5,7 +5,7 @@ int main(void) {
cube_t cube, inv;
fgets(str, STRLENMAX, stdin);
- cube = readcube("H48", str);
+ cube = cube_read("H48", str);
inv = cube_inverse(cube);
if (cube_error(inv)) {
@@ -13,7 +13,7 @@ int main(void) {
} else if (!cube_solvable(inv)) {
printf("Inverted cube is not solvable\n");
} else {
- writecube("H48", inv, str);
+ cube_write("H48", inv, str);
printf("%s\n", str);
}
diff --git a/test/050_compose/compose_tests.c b/test/050_compose/compose_tests.c
@@ -5,9 +5,9 @@ int main(void) {
cube_t c1, c2, c3;
fgets(str, STRLENMAX, stdin);
- c1 = readcube("H48", str);
+ c1 = cube_read("H48", str);
fgets(str, STRLENMAX, stdin);
- c2 = readcube("H48", str);
+ c2 = cube_read("H48", str);
c3 = cube_compose(c1, c2);
@@ -16,7 +16,7 @@ int main(void) {
} else if (!cube_solvable(c3)) {
printf("Composed cube is not solvable\n");
} else {
- writecube("H48", c3, str);
+ cube_write("H48", c3, str);
printf("%s\n", str);
}
diff --git a/test/060_transform/transform_tests.c b/test/060_transform/transform_tests.c
@@ -8,7 +8,7 @@ int main(void) {
fgets(transtr, STRLENMAX, stdin);
fgets(cubestr, STRLENMAX, stdin);
- cube = readcube("H48", cubestr);
+ cube = cube_read("H48", cubestr);
cube = applytrans(cube, transtr);
@@ -17,7 +17,7 @@ int main(void) {
} else if (!cube_solvable(cube)) {
printf("Transformed cube is not solvable\n");
} else {
- writecube("H48", cube, cubestr);
+ cube_write("H48", cube, cubestr);
printf("%s\n", cubestr);
}
diff --git a/test/071_coord_eo/coord_eo_tests.c b/test/071_coord_eo/coord_eo_tests.c
@@ -6,7 +6,7 @@ int main(void) {
int64_t result;
fgets(str, STRLENMAX, stdin);
- cube = readcube("H48", str);
+ cube = cube_read("H48", str);
result = cube_coord_eo(cube);
diff --git a/test/072_coord_co/coord_co_tests.c b/test/072_coord_co/coord_co_tests.c
@@ -6,7 +6,7 @@ int main(void) {
int64_t result;
fgets(str, STRLENMAX, stdin);
- cube = readcube("H48", str);
+ cube = cube_read("H48", str);
result = cube_coord_co(cube);
diff --git a/utils/h48_to_lst.c b/utils/h48_to_lst.c
@@ -11,8 +11,8 @@ int main(void) {
cube_t cube;
fgets(str, STRLENMAX, stdin);
- cube = readcube("H48", str);
- writecube("LST", cube, str);
+ cube = cube_read("H48", str);
+ write_cube("LST", cube, str);
fputs(str, stdout);
return 0;
diff --git a/utils/invert.c b/utils/invert.c
@@ -11,8 +11,8 @@ int main(void) {
cube_t cube;
fgets(str, STRLENMAX, stdin);
- cube = readcube("H48", str);
- writecube("H48", inverse(cube), str);
+ cube = cube_read("H48", str);
+ cube_write("H48", cube_inverse(cube), str);
fputs(str, stdout);
return 0;