/*前の記事の続き*/
void operate(struct node *cube) /*各ノードで状態遷移を行う*/
{
struct node *nextcube;
char i, k=0;
if(cube->opecolor!='o'){
nextcube=cube->next[k++];
for(i=0;i<D;i++){ /*orange面を右回転*/
surface[0][i][2]=cube->surface[3][i][2];
nextcube->surface[2][i][2]=cube->surface[0][i][2];
nextcube->surface[5][i][2]=cube->surface[2][i][2];
nextcube->surface[3][i][2]=cube->surface[5][i][2];
}
Rrot(nextcube, cube, 4);
nextcube->ope=1; /*右回転を1とする*/
nextcube->opecolor='o';
nextcube=cube->next[k++];
for(i=0;i<D;i++){
surface[0][i][2]=cube->surface[5][i][2];
nextcube->surface[2][i][2]=cube->surface[3][i][2];
nextcube->surface[5][i][2]=cube->surface[0][i][2];
nextcube->surface[3][i][2]=cube->surface[2][i][2];
}
rot(nextcube, cube, 4);
nextcube->ope=0; /*180度回転を0とする*/
nextcube->opecolor='o';
nextcube=cube->next[k++];
for(i=0;i<D;i++){
surface[0][i][2]=cube->surface[2][i][2];
nextcube->surface[2][i][2]=cube->surface[5][i][2];
nextcube->surface[5][i][2]=cube->surface[3][i][2];
nextcube->surface[3][i][2]=cube->surface[0][i][2];
}
Lrot(nextcube, cube, 4);
nextcube->ope=-1; /*左回転を-1とする*/
nextcube->opecolor='o';
}
if(cube->opecolor!='r'){
nextcube=cube->next[k++];
for(i=0;i<D;i++){
surface[0][i][0]=cube->surface[3][i][0];
nextcube->surface[2][i][0]=cube->surface[0][i][0];
nextcube->surface[5][i][0]=cube->surface[2][i][0];
nextcube->surface[3][i][0]=cube->surface[5][i][0];
}
Lrot(nextcube, cube, 1);
nextcube->ope=-1;
nextcube->opecolor='r';
nextcube=cube->next[k++];
for(i=0;i<D;i++){
surface[0][i][0]=cube->surface[5][i][0];
nextcube->surface[2][i][0]=cube->surface[3][i][0];
nextcube->surface[5][i][0]=cube->surface[0][i][0];
nextcube->surface[3][i][0]=cube->surface[2][i][0];
}
rot(nextcube, cube, 1);
nextcube->ope=0;
nextcube->opecolor='r';
nextcube=cube->next[k++];
for(i=0;i<D;i++){
surface[0][i][0]=cube->surface[2][i][0];
nextcube->surface[2][i][0]=cube->surface[5][i][0];
nextcube->surface[5][i][0]=cube->surface[3][i][0];
nextcube->surface[3][i][0]=cube->surface[0][i][0];
}
Rrot(nextcube, cube, 1);
nextcube->ope=1;
nextcube->opecolor='r';
}
if(cube->opecolor!='b'){
nextcube=cube->next[k++];
for(i=0;i<D;i++){
surface[0][2][D-1-i]=cube->surface[1][D-1-i][0];
nextcube->surface[4][i][2]=cube->surface[0][2][D-1-i];
nextcube->surface[5][0][i]=cube->surface[4][i][2];
nextcube->surface[1][D-1-i][0]=cube->surface[5][0][i];
}
Rrot(nextcube, cube, 3);
nextcube->ope=1;
nextcube->opecolor='b';
nextcube=cube->next[k++];
for(i=0;i<D;i++){
surface[0][2][D-1-i]=cube->surface[5][0][i];
nextcube->surface[4][i][2]=cube->surface[1][D-1-i][0];
nextcube->surface[5][0][i]=cube->surface[0][2][D-1-i];
nextcube->surface[1][D-1-i][0]=cube->surface[4][i][2];
}
rot(nextcube, cube, 3);
nextcube->ope=0;
nextcube->opecolor='b';
nextcube=cube->next[k++];
for(i=0;i<D;i++){
surface[0][2][D-1-i]=cube->surface[4][i][2];
nextcube->surface[4][i][2]=cube->surface[5][0][i];
nextcube->surface[5][0][i]=cube->surface[1][D-1-i][0];
nextcube->surface[1][D-1-i][0]=cube->surface[0][2][D-1-i];
}
Lrot(nextcube, cube, 3);
nextcube->ope=-1;
nextcube->opecolor='b';
}
if(cube->opecolor!='w'){
nextcube=cube->next[k++];
for(i=0;i<D;i++){
surface[0][0][D-1-i]=cube->surface[1][D-1-i][2];
nextcube->surface[4][i][0]=cube->surface[0][0][D-1-i];
nextcube->surface[5][2][i]=cube->surface[4][i][0];
nextcube->surface[1][D-1-i][2]=cube->surface[5][2][i];
}
Lrot(nextcube, cube, 2);
nextcube->ope=-1;
nextcube->opecolor='w';
nextcube=cube->next[k++];
for(i=0;i<D;i++){
surface[0][0][D-1-i]=cube->surface[5][2][i];
nextcube->surface[4][i][0]=cube->surface[1][D-1-i][2];
nextcube->surface[5][2][i]=cube->surface[0][0][D-1-i];
nextcube->surface[1][D-1-i][2]=cube->surface[4][i][0];
}
rot(nextcube, cube, 2);
nextcube->ope=0;
nextcube->opecolor='w';
nextcube=cube->next[k++];
for(i=0;i<D;i++){
surface[0][0][D-1-i]=cube->surface[4][i][0];
nextcube->surface[4][i][0]=cube->surface[5][2][i];
nextcube->surface[5][2][i]=cube->surface[1][D-1-i][2];
nextcube->surface[1][D-1-i][2]=cube->surface[0][0][D-1-i];
}
Rrot(nextcube, cube, 2);
nextcube->ope=1;
nextcube->opecolor='w';
}
if(cube->opecolor!='g'){
nextcube=cube->next[k++];
for(i=0;i<D;i++){
surface[4][0][i]=cube->surface[3][2][D-1-i];
nextcube->surface[2][0][i]=cube->surface[4][0][i];
nextcube->surface[1][0][i]=cube->surface[2][0][i];
nextcube->surface[3][2][D-1-i]=cube->surface[1][0][i];
}
Rrot(nextcube, cube, 5);
nextcube->ope=1;
nextcube->opecolor='g';
nextcube=cube->next[k++];
for(i=0;i<D;i++){
surface[4][0][i]=cube->surface[1][0][i];
nextcube->surface[2][0][i]=cube->surface[3][2][D-1-i];
nextcube->surface[1][0][i]=cube->surface[4][0][i];
nextcube->surface[3][2][D-1-i]=cube->surface[2][0][i];
}
rot(nextcube, cube, 5);
nextcube->ope=0;
nextcube->opecolor='g';
nextcube=cube->next[k++];
for(i=0;i<D;i++){
surface[4][0][i]=cube->surface[2][0][i];
nextcube->surface[2][0][i]=cube->surface[1][0][i];
nextcube->surface[1][0][i]=cube->surface[3][2][D-1-i];
nextcube->surface[3][2][D-1-i]=cube->surface[4][0][i];
}
Lrot(nextcube, cube, 5);
nextcube->ope=-1;
nextcube->opecolor='g';
}
if(cube->opecolor!='y'){
nextcube=cube->next[k++];
for(i=0;i<D;i++){
surface[4][2][i]=cube->surface[3][0][D-1-i];
nextcube->surface[2][2][i]=cube->surface[4][2][i];
nextcube->surface[1][2][i]=cube->surface[2][2][i];
nextcube->surface[3][0][D-1-i]=cube->surface[1][2][i];
}
Lrot(nextcube, cube, 0);
nextcube->ope=-1;
nextcube->opecolor='y';
nextcube=cube->next[k++];
for(i=0;i<D;i++){
surface[4][2][i]=cube->surface[1][2][i];
nextcube->surface[2][2][i]=cube->surface[3][0][D-1-i];
nextcube->surface[1][2][i]=cube->surface[4][2][i];
nextcube->surface[3][0][D-1-i]=cube->surface[2][2][i];
}
rot(nextcube, cube, 0);
nextcube->ope=0;
nextcube->opecolor='y';
nextcube=cube->next[k];
for(i=0;i<D;i++){
surface[4][2][i]=cube->surface[2][2][i];
nextcube->surface[2][2][i]=cube->surface[1][2][i];
nextcube->surface[1][2][i]=cube->surface[3][0][D-1-i];
nextcube->surface[3][0][D-1-i]=cube->surface[4][2][i];
}
Rrot(nextcube, cube, 0);
nextcube->ope=1;
nextcube->opecolor='y';
}
}
void Lrot(struct node *next, struct node *original, char s)
{
char i,j;
for(i=0;i<D;i++)
surface[s][i][j]=original->surface[s][j][D-1-i]; /*左回転*/
}
void Rrot(struct node *next, struct node *original, char s)
{
char i, j;
for(i=0;i<D;i++)
surface[s][i][j]=original->surface[s][D-1-j][i]; /*右回転*/
}
void rot(struct node *next, struct node *original, char s)
{
char i,j;
for(i=0;i<D;i++)
surface[s][i][j]=original->surface[s][D-i-1][D-1-j]; /*180度回転*/
}
/*まだ続く*/