Browse Source

- two function to compute pixels shown on front and back face

git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/research@2740 92316355-f0b4-4df1-b90c-862c8a59935f
master
kali 16 years ago
parent
commit
96332a20d1
1 changed files with 54 additions and 96 deletions
  1. +54
    -96
      2008-rubik/rubikutils/rubik.c

+ 54
- 96
2008-rubik/rubikutils/rubik.c View File

@@ -30,7 +30,6 @@
#define CORNER_BDL 22
#define CORNER_RDB 23


#define EDGE_UF 0
#define EDGE_UR 1
#define EDGE_UB 2
@@ -84,6 +83,15 @@ static char *edge_cubie_str[] = {"UF", "UR", "UB", "UL",
"FD", "RD", "BD", "LD",
"RF", "LF", "RB", "LB"};

static int edge_cubie_color[] = {
FACE_U, FACE_U, FACE_U, FACE_U,
FACE_D, FACE_D, FACE_D, FACE_D,
FACE_F, FACE_F, FACE_B, FACE_B,
FACE_F, FACE_R, FACE_B, FACE_L,
FACE_F, FACE_R, FACE_B, FACE_L,
FACE_R, FACE_L, FACE_R, FACE_L
};

static char *corner_cubie_str[] = {"UFR", "URB", "UBL", "ULF",
"DRF", "DFL", "DLB", "DBR",
"FRU", "RBU", "BLU", "LFU",
@@ -91,6 +99,14 @@ static char *corner_cubie_str[] = {"UFR", "URB", "UBL", "ULF",
"RUF", "BUR", "LUB", "FUL",
"FDR", "LDF", "BDL", "RDB"};

static int corner_cubie_color[] = {
FACE_U, FACE_U, FACE_U, FACE_U,
FACE_D, FACE_D, FACE_D, FACE_D,
FACE_F, FACE_R, FACE_B, FACE_L,
FACE_R, FACE_F, FACE_L, FACE_B,
FACE_R, FACE_B, FACE_L, FACE_F,
FACE_F, FACE_L, FACE_B, FACE_R};

/* ========================================================================= */
void two_cycle(int array[], int ind0, int ind1)
/* ------------------------------------------------------------------------- */
@@ -192,54 +208,6 @@ perm_n_init(24, p_cube->corners);
return;
}

/* ========================================================================= */
int cube_compare(Cube *cube0, Cube *cube1)
/* ------------------------------------------------------------------------- */

{
int ii;

for (ii = 0; ii < 6; ii++)
{
if (cube0->centers[ii] < cube1->centers[ii])
return -1;
else if (cube0->centers[ii] > cube1->centers[ii])
return 1;
}

for (ii = 0; ii < 24; ii++)
{
if (cube0->edges[ii] < cube1->edges[ii])
return -1;
else if (cube0->edges[ii] > cube1->edges[ii])
return 1;
}

for (ii = 0; ii < 24; ii++)
{
if (cube0->corners[ii] < cube1->corners[ii])
return -1;
else if (cube0->corners[ii] > cube1->corners[ii])
return 1;
}

return 0;
}

#if 0
/* ========================================================================= */
void cube_compose(Cube *in_cube0, Cube *in_cube1, Cube *out_cube)
/* ------------------------------------------------------------------------- */

{
perm_n_compose(6, in_cube0->centers, in_cube1->centers, out_cube->centers);
perm_n_compose(24, in_cube0->edges, in_cube1->edges, out_cube->edges);
perm_n_compose(24, in_cube0->corners, in_cube1->corners, out_cube->corners);

return;
}
#endif

/* ========================================================================= */
int perm_n_check(int nn, int array_in[])
/* ------------------------------------------------------------------------- */
@@ -562,63 +530,42 @@ while (line_str[0] == '\n') /* ignore blank lines */
return string_to_cube(line_str, p_cube, 1);
}



/* ========================================================================= */
void pretty_print_unsigned_int(unsigned int nn)
int compute_pixels_front(Cube *p_cube, int pixels[9])
/* ------------------------------------------------------------------------- */

{
int digits[4], ii, started;
pixels[0] = corner_cubie_color[p_cube->corners[CORNER_FUL]];
pixels[1] = edge_cubie_color[p_cube->edges[EDGE_FU]];
pixels[2] = corner_cubie_color[p_cube->corners[CORNER_FRU]];

pixels[3] = edge_cubie_color[p_cube->edges[EDGE_FL]];
pixels[4] = p_cube->centers[FACE_F];
pixels[5] = edge_cubie_color[p_cube->edges[EDGE_FR]];

for (ii = 0; ii < 4; ii++)
{
digits[ii] = nn % 1000;
nn /= 1000;
}
pixels[6] = corner_cubie_color[p_cube->corners[CORNER_FLD]];
pixels[7] = edge_cubie_color[p_cube->edges[EDGE_FD]];
pixels[8] = corner_cubie_color[p_cube->corners[CORNER_FDR]];
}

started = 0;

for (ii = 3; ii >= 0; ii--)
{
if (started)
{
if (digits[ii] >= 100)
printf("%3d", digits[ii]);
else if (digits[ii] >= 10)
printf("0%2d", digits[ii]);
else
printf("00%1d", digits[ii]);
}
else
{
if (digits[ii] >= 100)
{
printf("%3d", digits[ii]);
started = 1;
}
else if (digits[ii] >= 10)
{
printf(" %2d", digits[ii]);
started = 1;
}
else if ((digits[ii] >= 1) || (ii == 0))
{
printf(" %1d", digits[ii]);
started = 1;
}
else
printf(" ");
}
/* ========================================================================= */
int compute_pixels_back(Cube *p_cube, int pixels[9])
/* ------------------------------------------------------------------------- */

if (ii > 0)
printf("%c", started ? ',' : ' ');
}
{
pixels[0] = corner_cubie_color[p_cube->corners[CORNER_BUR]];
pixels[1] = edge_cubie_color[p_cube->edges[EDGE_BU]];
pixels[2] = corner_cubie_color[p_cube->corners[CORNER_BLU]];

return;
}
pixels[3] = edge_cubie_color[p_cube->edges[EDGE_BR]];
pixels[4] = p_cube->centers[FACE_B];
pixels[5] = edge_cubie_color[p_cube->edges[EDGE_BL]];

pixels[6] = corner_cubie_color[p_cube->corners[CORNER_BRD]];
pixels[7] = edge_cubie_color[p_cube->edges[EDGE_BD]];
pixels[8] = corner_cubie_color[p_cube->corners[CORNER_BDL]];
}

/* ========================================================================= */
int main(void)
@@ -627,12 +574,23 @@ return;
{
Cube cube_struct;
int stat;
int i;
int pixels[9];

while (1)
{
stat = user_enters_cube(&cube_struct);
if (stat < 0)
if (stat != 0)
break;
printf("cube looks fine\n");
compute_pixels_front(&cube_struct, pixels);
for(i = 0; i<9; i++)
printf("%d", pixels[i]);
printf("\n");
compute_pixels_back(&cube_struct, pixels);
for(i = 0; i<9; i++)
printf("%d", pixels[i]);
printf("\n");
}
exit(EXIT_SUCCESS);



Loading…
Cancel
Save