Ignore:
Timestamp:
Aug 20, 2008, 11:14:29 PM (15 years ago)
Author:
kali
Message:
  • two function to compute pixels shown on front and back face
File:
1 edited

Legend:

Unmodified
Added
Removed
  • research/2008-rubik/rubikutils/rubik.c

    r2739 r2740  
    3030#define  CORNER_BDL                         22
    3131#define  CORNER_RDB                         23
    32 
    3332
    3433#define  EDGE_UF                             0
     
    8584                                            "RF", "LF", "RB", "LB"};
    8685
     86static int              edge_cubie_color[] = {
     87                            FACE_U, FACE_U, FACE_U, FACE_U,
     88                            FACE_D, FACE_D, FACE_D, FACE_D,
     89                            FACE_F, FACE_F, FACE_B, FACE_B,
     90                            FACE_F, FACE_R, FACE_B, FACE_L,
     91                            FACE_F, FACE_R, FACE_B, FACE_L,
     92                            FACE_R, FACE_L, FACE_R, FACE_L
     93                                };
     94
    8795static char            *corner_cubie_str[] = {"UFR", "URB", "UBL", "ULF",
    8896                                              "DRF", "DFL", "DLB", "DBR",
     
    9199                                              "RUF", "BUR", "LUB", "FUL",
    92100                                              "FDR", "LDF", "BDL", "RDB"};
     101
     102static int              corner_cubie_color[] = {
     103                            FACE_U, FACE_U, FACE_U, FACE_U,
     104                            FACE_D, FACE_D, FACE_D, FACE_D,
     105                            FACE_F, FACE_R, FACE_B, FACE_L,
     106                            FACE_R, FACE_F, FACE_L, FACE_B,
     107                            FACE_R, FACE_B, FACE_L, FACE_F,
     108                            FACE_F, FACE_L, FACE_B, FACE_R};
    93109
    94110/* ========================================================================= */
     
    194210
    195211/* ========================================================================= */
    196    int  cube_compare(Cube  *cube0, Cube  *cube1)
    197 /* ------------------------------------------------------------------------- */
    198 
    199 {
    200 int           ii;
    201 
    202 for (ii = 0; ii < 6; ii++)
    203     {
    204     if (cube0->centers[ii] < cube1->centers[ii])
    205        return -1;
    206     else if (cube0->centers[ii] > cube1->centers[ii])
    207        return 1;
    208     }
    209 
    210 for (ii = 0; ii < 24; ii++)
    211     {
    212     if (cube0->edges[ii] < cube1->edges[ii])
    213        return -1;
    214     else if (cube0->edges[ii] > cube1->edges[ii])
    215        return 1;
    216     }
    217 
    218 for (ii = 0; ii < 24; ii++)
    219     {
    220     if (cube0->corners[ii] < cube1->corners[ii])
    221        return -1;
    222     else if (cube0->corners[ii] > cube1->corners[ii])
    223        return 1;
    224     }
    225 
    226 return 0;
    227 }
    228 
    229 #if 0
    230 /* ========================================================================= */
    231    void  cube_compose(Cube  *in_cube0, Cube  *in_cube1, Cube  *out_cube)
    232 /* ------------------------------------------------------------------------- */
    233 
    234 {
    235 perm_n_compose(6, in_cube0->centers, in_cube1->centers, out_cube->centers);
    236 perm_n_compose(24, in_cube0->edges, in_cube1->edges, out_cube->edges);
    237 perm_n_compose(24, in_cube0->corners, in_cube1->corners, out_cube->corners);
    238 
    239 return;
    240 }
    241 #endif
    242 
    243 /* ========================================================================= */
    244212   int  perm_n_check(int  nn, int  array_in[])
    245213/* ------------------------------------------------------------------------- */
     
    563531}
    564532
    565 
    566 
    567 /* ========================================================================= */
    568    void  pretty_print_unsigned_int(unsigned int  nn)
    569 /* ------------------------------------------------------------------------- */
    570 
    571 {
    572 int                     digits[4], ii, started;
    573 
    574 
    575 for (ii = 0; ii < 4; ii++)
    576     {
    577     digits[ii] = nn % 1000;
    578     nn /= 1000;
    579     }
    580 
    581 started = 0;
    582 
    583 for (ii = 3; ii >= 0; ii--)
    584     {
    585     if (started)
    586        {
    587        if (digits[ii] >= 100)
    588           printf("%3d", digits[ii]);
    589        else if (digits[ii] >= 10)
    590                printf("0%2d", digits[ii]);
    591        else
    592           printf("00%1d", digits[ii]);
    593        }
    594     else
    595        {
    596        if (digits[ii] >= 100)
    597           {
    598           printf("%3d", digits[ii]);
    599           started = 1;
    600           }
    601        else if (digits[ii] >= 10)
    602                {
    603                printf(" %2d", digits[ii]);
    604                started = 1;
    605                }
    606        else if ((digits[ii] >= 1) || (ii == 0))
    607                {
    608                printf("  %1d", digits[ii]);
    609                started = 1;
    610                }
    611        else
    612           printf("   ");
    613        }
    614 
    615     if (ii > 0)
    616        printf("%c", started ? ',' : ' ');
    617     }
    618 
    619 return;
    620 }
    621 
     533/* ========================================================================= */
     534   int  compute_pixels_front(Cube  *p_cube, int pixels[9])
     535/* ------------------------------------------------------------------------- */
     536
     537{
     538    pixels[0] = corner_cubie_color[p_cube->corners[CORNER_FUL]];
     539    pixels[1] = edge_cubie_color[p_cube->edges[EDGE_FU]];
     540    pixels[2] = corner_cubie_color[p_cube->corners[CORNER_FRU]];
     541
     542    pixels[3] = edge_cubie_color[p_cube->edges[EDGE_FL]];
     543    pixels[4] = p_cube->centers[FACE_F];
     544    pixels[5] = edge_cubie_color[p_cube->edges[EDGE_FR]];
     545
     546    pixels[6] = corner_cubie_color[p_cube->corners[CORNER_FLD]];
     547    pixels[7] = edge_cubie_color[p_cube->edges[EDGE_FD]];
     548    pixels[8] = corner_cubie_color[p_cube->corners[CORNER_FDR]];
     549}
     550
     551
     552/* ========================================================================= */
     553   int  compute_pixels_back(Cube  *p_cube, int pixels[9])
     554/* ------------------------------------------------------------------------- */
     555
     556{
     557    pixels[0] = corner_cubie_color[p_cube->corners[CORNER_BUR]];
     558    pixels[1] = edge_cubie_color[p_cube->edges[EDGE_BU]];
     559    pixels[2] = corner_cubie_color[p_cube->corners[CORNER_BLU]];
     560
     561    pixels[3] = edge_cubie_color[p_cube->edges[EDGE_BR]];
     562    pixels[4] = p_cube->centers[FACE_B];
     563    pixels[5] = edge_cubie_color[p_cube->edges[EDGE_BL]];
     564
     565    pixels[6] = corner_cubie_color[p_cube->corners[CORNER_BRD]];
     566    pixels[7] = edge_cubie_color[p_cube->edges[EDGE_BD]];
     567    pixels[8] = corner_cubie_color[p_cube->corners[CORNER_BDL]];
     568}
    622569
    623570/* ========================================================================= */
     
    628575Cube                    cube_struct;
    629576int                     stat;
     577int                     i;
     578int                     pixels[9];
    630579
    631580while (1)
    632581      {
    633582      stat = user_enters_cube(&cube_struct);
    634       if (stat < 0)
     583      if (stat != 0)
    635584         break;
     585    printf("cube looks fine\n");
     586compute_pixels_front(&cube_struct, pixels);
     587for(i = 0; i<9; i++)
     588    printf("%d", pixels[i]);
     589    printf("\n");
     590compute_pixels_back(&cube_struct, pixels);
     591for(i = 0; i<9; i++)
     592    printf("%d", pixels[i]);
     593    printf("\n");
    636594    }
    637595exit(EXIT_SUCCESS);
Note: See TracChangeset for help on using the changeset viewer.