The code written below performs all the basic turns of the cube (only in the software side.Yet to interface stepper motors.) such as L L' R R' F F' and B B'.
/*
* array format
* E
* A B C D
* F
* */
//colour - number code
//yellow 1
//orange 2
//white 3
//red 4
//blue 5
//green 6
//matrix name - number code
// A 7
// B 8
// C 9
// D 10
// E 11
// F 12
int A[3][3]={{1,1,1},{1,1,1},{1,1,1}};
int B[3][3]={{2,2,2},{2,2,2},{2,2,2}};
int C[3][3]={{3,3,3},{3,3,3},{3,3,3}};
int D[3][3]={{4,4,4},{4,4,4},{4,4,4}};
int E[3][3]={{5,5,5},{5,5,5},{5,5,5}};
int F[3][3]={{6,6,6},{6,6,6},{6,6,6}};
int matrix_name[3][3];
int temp[3][3];
int temp1;
int temp2;
int i;
int j;
int d=0;
int y=2;
char c=0; //used in print_matrix() function;
char f=0; //used to get Y or N in check_cubes_correctness();
int count=0;
int cross_value[4][3];
int edgepair[12];
void get_matrices(int *,char);
void check_cubes_correctness(void);
void print_matrix(int *);//prints out a single matrix
void print_matrices(void);//prints out all 6 matrices
void column_away(int);
void column_toward(int);
void row_right(int);
void row_left(int);
void front_clockwise(void);
void front_anticlockwise(void);
void back_clk(void);
void back_anticlk(void);
void circle_clockwise(char);
void circle_anticlockwise(char);
void change_matrix_name(int,char); //0=>matrix to matrix_name
//1=>matrix_name to matrix
void search_cross_location(void);
void calculate_edgepairs(void);
void solve_for_cross(void);
int main(void)
{
/*
how i solve the cube
1.form plus
2.solve first layer
3.solve for middle layer
4.form top cross
5.make sure corner pieces are in place
6.put them in place
7.end up with solved cube
*/
printf("\n Color - number code\n");
printf("\n yellow 1 \n orange 2 \n white 3 \n red 4 \n blue 5 \n green 6");
get_matrices(A,'A');
get_matrices(B,'B');
get_matrices(C,'C');
get_matrices(D,'D');
get_matrices(E,'E');
get_matrices(F,'F');
check_cubes_correctness();
while(count!=189)
{
check_cubes_correctness();
}
print_matrices();
printf("\n\n\n\n");
column_toward(0);
printf("column toward 0 \n\n");
print_matrices();
column_away(0);
printf("column away 0 \n\n");
print_matrices();
printf("\n\n\n");
column_toward(2);
printf("column toward 2\n\n");
print_matrices();
column_away(2);
printf("column away 2\n\n");
print_matrices();
printf("\n\n\n");
row_right(0);
printf("row right 0 \n\n");
print_matrices();
row_left(0);
printf("row left 0 \n\n");
print_matrices();
printf("\n\n\n");
row_right(2);
printf("row right 2 \n\n");
print_matrices();
row_left(2);
printf("row left 2 \n\n");
print_matrices();
printf("\n\n\n");
front_clockwise();
printf("Front clockwise\n\n");
print_matrices();
front_anticlockwise();
printf("Front anticlockwise\n\n");
print_matrices();
printf("\n\n\n");
while(1)
{
}
}
void get_matrices(int *z,char b)
{
printf("\n Enter matrix %c: \n",b);
//empty the temp matrix
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
temp[i][j]=0;
}
}
//take input and store in temp matrix as characters
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
scanf("%c",&temp[i][j]);
printf("%c",temp[i][j]);
}
}
//copy from temp to appropriate matrix
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
*z=temp[i][j]-48;
z++;
}
}
}
void print_matrix(int *a)
{
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
if(*a==1) c='Y';
if(*a==2) c='O';
if(*a==3) c='W';
if(*a==4) c='R';
if(*a==5) c='B';
if(*a==6) c='G';
printf("%c\t\t",c);
a++;
}
printf("\n");
}
printf("\n\n");
}
void print_matrices(void)
{
printf("Matrix A\n");
print_matrix(A);
printf("Matrix B\n");
print_matrix(B);
printf("Matrix C\n");
print_matrix(C);
printf("Matrix D\n");
print_matrix(D);
printf("Matrix E\n");
print_matrix(E);
printf("Matrix F\n");
print_matrix(F);
}
void check_cubes_correctness(void)
{
//The logic of this function is that when you consider a solved cube in my arrangement,
//side A is full of 1's,
//-||- B ----||-----2's
//-||- C ----||-----3's and so on.
//this function just sums up each od the numbers.
//if the value ends up to be 189,the cube is valid
count=0;
printf("\n\n count = %d \n\n", count);
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
count=count+A[i][j]+B[i][j]+C[i][j]+D[i][j]+E[i][j]+F[i][j];
}
}
printf("\n count = %d \n", count);
if(count==189)
{
printf("\n valid cube\n\n");
}
else
{
printf("\n invalid cube.re-enter values.\n\n");
//add code to rescan all 6 sides again
printf("\n Enter Y or N in \"Caps\" \n");
printf("\n Matrix A \n");
print_matrix(A);
printf(" \n Enter Y for correct N for not correct \n");
scanf("%c",&f);
if(f=='Y')
{
}
if(f=='N')
{
get_matrices(A,'A');
}
printf("\n Matrix B \n");
print_matrix(B);
printf(" \n Enter Y for correct N for not correct \n");
scanf("%c",&f);
if(f=='Y')
{
}
if(f=='N')
{
get_matrices(B,'B');
}
printf("\n Matrix C \n");
print_matrix(C);
printf(" \n Enter Y for correct N for not correct \n");
scanf("%c",&f);
if(f=='Y')
{
}
if(f=='N')
{
get_matrices(C,'C');
}
printf("\n Matrix D \n");
print_matrix(D);
printf(" \n Enter Y for correct N for not correct \n");
scanf("%c",&f);
if(f=='Y')
{
}
if(f=='N')
{
get_matrices(D,'D');
}
printf("\n Matrix E \n");
print_matrix(E);
printf(" \n Enter Y for correct N for not correct \n");
scanf("%c",&f);
if(f=='Y')
{
}
if(f=='N')
{
get_matrices(E,'E');
}
printf("\n Matrix F \n");
print_matrix(F);
printf(" \n Enter Y for correct N for not correct \n");
scanf("%c",&f);
if(f=='Y')
{
}
if(f=='N')
{
get_matrices(F,'F');
}
}
}
void column_away(int j)
{
//stepper turn mechanism
y=2;
for(i=0;i<=2;i++)
{
temp[i][j]=E[i][j];
E[i][j]=B[i][j];
B[i][j]=F[i][j];
}
for(i=0;i<=2;i++)
{
if(j==0)
{
F[y][j]=D[i][j+2];
D[i][j+2]=temp[y][j];
}
if(j==2)
{
F[i][j]=D[y][j-2];
D[y][j-2]=temp[i][j];
}
y=y-1;
}
if(j==2)
{
circle_clockwise('C');
}
if(j==0)
{
circle_anticlockwise('A');
}
}
void column_toward(int j)
{
//stepper turn mechanism
y=2;
for(i=0;i<=2;i++)
{
if(j==0)
{
temp[i][j]=D[y][j+2];
D[y][j+2]=F[i][j];
}
if(j==2)
{
temp[i][j]=D[y][j-2];
D[y][j-2]=F[i][j];
}
y=y-1;
}
for(i=0;i<=2;i++)
{
F[i][j]=B[i][j];
B[i][j]=E[i][j];
E[i][j]=temp[i][j];
}
if(j==2)
{
circle_anticlockwise('C');
}
if(j==0)
{
circle_clockwise('A');
}
}
void row_right(int i)
{
//stepper turn mechanism
for(j=0;j<=2;j++)
{
temp[i][j]=A[i][j];
A[i][j]=D[i][j];
D[i][j]=C[i][j];
C[i][j]=B[i][j];
B[i][j]=temp[i][j];
}
if(i==0)
{
circle_anticlockwise('E');
}
if(i==2)
{
circle_clockwise('F');
}
}
void row_left(int i)
{
//stepper turn mechanism
for(j=0;j<=2;j++)
{
temp[i][j]=A[i][j];
A[i][j]=B[i][j];
B[i][j]=C[i][j];
C[i][j]=D[i][j];
D[i][j]=temp[i][j];
}
if(i==0)
{
circle_clockwise('E');
}
if(i==2)
{
circle_anticlockwise('F');
}
}
void circle_clockwise(char a)
{
change_matrix_name(0,a);
temp1=matrix_name[0][0];
matrix_name[0][0]=matrix_name[2][0];
matrix_name[2][0]=matrix_name[2][2];
matrix_name[2][2]=matrix_name[0][2];
matrix_name[0][2]=temp1;
temp2=matrix_name[0][1];
matrix_name[0][1]=matrix_name[1][0];
matrix_name[1][0]=matrix_name[2][1];
matrix_name[2][1]=matrix_name[1][2];
matrix_name[1][2]=temp2;
change_matrix_name(1,a);
}
void circle_anticlockwise(char a)
{
change_matrix_name(0,a);
temp1=matrix_name[0][0];
matrix_name[0][0]=matrix_name[0][2];
matrix_name[0][2]=matrix_name[2][2];
matrix_name[2][2]=matrix_name[2][0];
matrix_name[2][0]=temp1;
temp2=matrix_name[0][1];
matrix_name[0][1]=matrix_name[1][2];
matrix_name[1][2]=matrix_name[2][1];
matrix_name[2][1]=matrix_name[1][0];
matrix_name[1][0]=temp2;
change_matrix_name(1,a);
}
void change_matrix_name(int b,char a)
{
int *c;
if(a=='A')
{
c=A;
}
if(a=='B')
{
c=B;
}
if(a=='C')
{
c=C;
}
if(a=='D')
{
c=D;
}
if(a=='E')
{
c=E;
}
if(a=='F')
{
c=F;
}
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
if(b==0)
{
matrix_name[i][j]=*c;
c++;
}
if(b==1)
{
*c=matrix_name[i][j];
c++;
}
}
}
}
void front_clockwise(void)
{
//stepper turn mechanism
temp[0][0]=A[0][2];
temp[0][1]=A[1][2];
temp[0][2]=A[2][2];
A[0][2]=F[0][0];
A[1][2]=F[0][1];
A[2][2]=F[0][2];
F[0][0]=C[2][0];
F[0][1]=C[1][0];
F[0][2]=C[0][0];
C[2][0]=E[2][2];
C[1][0]=E[2][1];
C[0][0]=E[2][0];
E[2][2]=temp[0][0];
E[2][1]=temp[0][1];
E[2][0]=temp[0][2];
circle_clockwise('B');
}
void front_anticlockwise(void)
{
//stepper turn mechanism
temp[0][0]=A[0][2];
temp[0][1]=A[1][2];
temp[0][2]=A[2][2];
A[0][2]=E[2][2];
A[1][2]=E[2][1];
A[2][2]=E[2][0];
E[2][2]=C[2][0];
E[2][1]=C[1][0];
E[2][0]=C[0][0];
C[2][0]=F[0][0];
C[1][0]=F[0][1];
C[0][0]=F[0][2];
F[0][0]=temp[0][0];
F[0][1]=temp[0][1];
F[0][2]=temp[0][2];
circle_anticlockwise('B');
}
void search_cross_location(void)
{
// positions to check for are :01 10 12 21
d=0;
for(i=0,j=1;i<=2;i+=2)
{
if(A[i][j]==2)
{
cross_value[d][0]=7;
cross_value[d][1]=i;
cross_value[d][2]=j;
d+=1;
}
if(B[i][j]==2)
{
cross_value[d][0]=8;
cross_value[d][1]=i;
cross_value[d][2]=j;
d+=1;
}
if(C[i][j]==2)
{
cross_value[d][0]=9;
cross_value[d][1]=i;
cross_value[d][2]=j;
d+=1;
}
if(D[i][j]==2)
{
cross_value[d][0]=10;
cross_value[d][1]=i;
cross_value[d][2]=j;
d+=1;
}
if(E[i][j]==2)
{
cross_value[d][0]=11;
cross_value[d][1]=i;
cross_value[d][2]=j;
d+=1;
}
if(F[i][j]==2)
{
cross_value[d][0]=12;
cross_value[d][1]=i;
cross_value[d][2]=j;
d+=1;
}
if(d==4)
{
break;
}
}
for(i=1,j=0;j<=2;j+=2)
{
if(A[i][j]==2)
{
cross_value[d][0]=7;
cross_value[d][1]=i;
cross_value[d][2]=j;
d+=1;
}
if(B[i][j]==2)
{
cross_value[d][0]=8;
cross_value[d][1]=i;
cross_value[d][2]=j;
d+=1;
}
if(C[i][j]==2)
{
cross_value[d][0]=9;
cross_value[d][1]=i;
cross_value[d][2]=j;
d+=1;
}
if(D[i][j]==2)
{
cross_value[d][0]=10;
cross_value[d][1]=i;
cross_value[d][2]=j;
d+=1;
}
if(E[i][j]==2)
{
cross_value[d][0]=11;
cross_value[d][1]=i;
cross_value[d][2]=j;
d+=1;
}
if(F[i][j]==2)
{
cross_value[d][0]=12;
cross_value[d][1]=i;
cross_value[d][2]=j;
d+=1;
}
if(d==4)
{
break;
}
}
}
void calculate_edgepairs(void)
{
edgepair[0]=A[1][0]*10+D[1][2];
edgepair[1]=A[0][1]*10+E[1][0];
edgepair[2]=A[1][2]*10+B[1][0];
edgepair[3]=A[2][1]*10+F[1][0];
edgepair[4]=B[0][1]*10+E[2][1];
edgepair[5]=B[1][2]*10+C[1][0];
edgepair[6]=B[2][1]*10+F[0][1];
edgepair[7]=C[0][1]*10+E[1][2];
edgepair[8]=C[1][2]*10+D[1][0];
edgepair[9]=C[2][1]*10+F[1][2];
edgepair[10]=D[0][1]*10+E[0][1];
edgepair[11]=D[2][1]*10+F[2][1];
for(d=0;d<=11;d++)
{
printf("\nEdge pair %d : %d\n",d,edgepair[d]);
}
}
/*
* array format
* E
* A B C D
* F
* */
//colour - number code
//yellow 1
//orange 2
//white 3
//red 4
//blue 5
//green 6
//matrix name - number code
// A 7
// B 8
// C 9
// D 10
// E 11
// F 12
int A[3][3]={{1,1,1},{1,1,1},{1,1,1}};
int B[3][3]={{2,2,2},{2,2,2},{2,2,2}};
int C[3][3]={{3,3,3},{3,3,3},{3,3,3}};
int D[3][3]={{4,4,4},{4,4,4},{4,4,4}};
int E[3][3]={{5,5,5},{5,5,5},{5,5,5}};
int F[3][3]={{6,6,6},{6,6,6},{6,6,6}};
int matrix_name[3][3];
int temp[3][3];
int temp1;
int temp2;
int i;
int j;
int d=0;
int y=2;
char c=0; //used in print_matrix() function;
char f=0; //used to get Y or N in check_cubes_correctness();
int count=0;
int cross_value[4][3];
int edgepair[12];
void get_matrices(int *,char);
void check_cubes_correctness(void);
void print_matrix(int *);//prints out a single matrix
void print_matrices(void);//prints out all 6 matrices
void column_away(int);
void column_toward(int);
void row_right(int);
void row_left(int);
void front_clockwise(void);
void front_anticlockwise(void);
void back_clk(void);
void back_anticlk(void);
void circle_clockwise(char);
void circle_anticlockwise(char);
void change_matrix_name(int,char); //0=>matrix to matrix_name
//1=>matrix_name to matrix
void search_cross_location(void);
void calculate_edgepairs(void);
void solve_for_cross(void);
int main(void)
{
/*
how i solve the cube
1.form plus
2.solve first layer
3.solve for middle layer
4.form top cross
5.make sure corner pieces are in place
6.put them in place
7.end up with solved cube
*/
printf("\n Color - number code\n");
printf("\n yellow 1 \n orange 2 \n white 3 \n red 4 \n blue 5 \n green 6");
get_matrices(A,'A');
get_matrices(B,'B');
get_matrices(C,'C');
get_matrices(D,'D');
get_matrices(E,'E');
get_matrices(F,'F');
check_cubes_correctness();
while(count!=189)
{
check_cubes_correctness();
}
print_matrices();
printf("\n\n\n\n");
column_toward(0);
printf("column toward 0 \n\n");
print_matrices();
column_away(0);
printf("column away 0 \n\n");
print_matrices();
printf("\n\n\n");
column_toward(2);
printf("column toward 2\n\n");
print_matrices();
column_away(2);
printf("column away 2\n\n");
print_matrices();
printf("\n\n\n");
row_right(0);
printf("row right 0 \n\n");
print_matrices();
row_left(0);
printf("row left 0 \n\n");
print_matrices();
printf("\n\n\n");
row_right(2);
printf("row right 2 \n\n");
print_matrices();
row_left(2);
printf("row left 2 \n\n");
print_matrices();
printf("\n\n\n");
front_clockwise();
printf("Front clockwise\n\n");
print_matrices();
front_anticlockwise();
printf("Front anticlockwise\n\n");
print_matrices();
printf("\n\n\n");
while(1)
{
}
void get_matrices(int *z,char b)
{
printf("\n Enter matrix %c: \n",b);
//empty the temp matrix
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
temp[i][j]=0;
}
}
//take input and store in temp matrix as characters
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
scanf("%c",&temp[i][j]);
printf("%c",temp[i][j]);
}
}
//copy from temp to appropriate matrix
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
*z=temp[i][j]-48;
z++;
}
}
}
void print_matrix(int *a)
{
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
if(*a==1) c='Y';
if(*a==2) c='O';
if(*a==3) c='W';
if(*a==4) c='R';
if(*a==5) c='B';
if(*a==6) c='G';
printf("%c\t\t",c);
a++;
}
printf("\n");
}
printf("\n\n");
}
void print_matrices(void)
{
printf("Matrix A\n");
print_matrix(A);
printf("Matrix B\n");
print_matrix(B);
printf("Matrix C\n");
print_matrix(C);
printf("Matrix D\n");
print_matrix(D);
printf("Matrix E\n");
print_matrix(E);
printf("Matrix F\n");
print_matrix(F);
}
void check_cubes_correctness(void)
{
//The logic of this function is that when you consider a solved cube in my arrangement,
//side A is full of 1's,
//-||- B ----||-----2's
//-||- C ----||-----3's and so on.
//this function just sums up each od the numbers.
//if the value ends up to be 189,the cube is valid
count=0;
printf("\n\n count = %d \n\n", count);
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
count=count+A[i][j]+B[i][j]+C[i][j]+D[i][j]+E[i][j]+F[i][j];
}
}
printf("\n count = %d \n", count);
if(count==189)
{
printf("\n valid cube\n\n");
}
else
{
printf("\n invalid cube.re-enter values.\n\n");
//add code to rescan all 6 sides again
printf("\n Enter Y or N in \"Caps\" \n");
printf("\n Matrix A \n");
print_matrix(A);
printf(" \n Enter Y for correct N for not correct \n");
scanf("%c",&f);
if(f=='Y')
{
}
if(f=='N')
{
get_matrices(A,'A');
}
printf("\n Matrix B \n");
print_matrix(B);
printf(" \n Enter Y for correct N for not correct \n");
scanf("%c",&f);
if(f=='Y')
{
}
if(f=='N')
{
get_matrices(B,'B');
}
printf("\n Matrix C \n");
print_matrix(C);
printf(" \n Enter Y for correct N for not correct \n");
scanf("%c",&f);
if(f=='Y')
{
}
if(f=='N')
{
get_matrices(C,'C');
}
printf("\n Matrix D \n");
print_matrix(D);
printf(" \n Enter Y for correct N for not correct \n");
scanf("%c",&f);
if(f=='Y')
{
}
if(f=='N')
{
get_matrices(D,'D');
}
printf("\n Matrix E \n");
print_matrix(E);
printf(" \n Enter Y for correct N for not correct \n");
scanf("%c",&f);
if(f=='Y')
{
}
if(f=='N')
{
get_matrices(E,'E');
}
printf("\n Matrix F \n");
print_matrix(F);
printf(" \n Enter Y for correct N for not correct \n");
scanf("%c",&f);
if(f=='Y')
{
}
if(f=='N')
{
get_matrices(F,'F');
}
}
}
void column_away(int j)
{
//stepper turn mechanism
y=2;
for(i=0;i<=2;i++)
{
temp[i][j]=E[i][j];
E[i][j]=B[i][j];
B[i][j]=F[i][j];
}
for(i=0;i<=2;i++)
{
if(j==0)
{
F[y][j]=D[i][j+2];
D[i][j+2]=temp[y][j];
}
if(j==2)
{
F[i][j]=D[y][j-2];
D[y][j-2]=temp[i][j];
}
y=y-1;
}
if(j==2)
{
circle_clockwise('C');
}
if(j==0)
{
circle_anticlockwise('A');
}
}
void column_toward(int j)
{
//stepper turn mechanism
y=2;
for(i=0;i<=2;i++)
{
if(j==0)
{
temp[i][j]=D[y][j+2];
D[y][j+2]=F[i][j];
}
if(j==2)
{
temp[i][j]=D[y][j-2];
D[y][j-2]=F[i][j];
}
y=y-1;
}
for(i=0;i<=2;i++)
{
F[i][j]=B[i][j];
B[i][j]=E[i][j];
E[i][j]=temp[i][j];
}
if(j==2)
{
circle_anticlockwise('C');
}
if(j==0)
{
circle_clockwise('A');
}
}
void row_right(int i)
{
//stepper turn mechanism
for(j=0;j<=2;j++)
{
temp[i][j]=A[i][j];
A[i][j]=D[i][j];
D[i][j]=C[i][j];
C[i][j]=B[i][j];
B[i][j]=temp[i][j];
}
if(i==0)
{
circle_anticlockwise('E');
}
if(i==2)
{
circle_clockwise('F');
}
}
void row_left(int i)
{
//stepper turn mechanism
for(j=0;j<=2;j++)
{
temp[i][j]=A[i][j];
A[i][j]=B[i][j];
B[i][j]=C[i][j];
C[i][j]=D[i][j];
D[i][j]=temp[i][j];
}
if(i==0)
{
circle_clockwise('E');
}
if(i==2)
{
circle_anticlockwise('F');
}
}
void circle_clockwise(char a)
{
change_matrix_name(0,a);
temp1=matrix_name[0][0];
matrix_name[0][0]=matrix_name[2][0];
matrix_name[2][0]=matrix_name[2][2];
matrix_name[2][2]=matrix_name[0][2];
matrix_name[0][2]=temp1;
temp2=matrix_name[0][1];
matrix_name[0][1]=matrix_name[1][0];
matrix_name[1][0]=matrix_name[2][1];
matrix_name[2][1]=matrix_name[1][2];
matrix_name[1][2]=temp2;
change_matrix_name(1,a);
}
void circle_anticlockwise(char a)
{
change_matrix_name(0,a);
temp1=matrix_name[0][0];
matrix_name[0][0]=matrix_name[0][2];
matrix_name[0][2]=matrix_name[2][2];
matrix_name[2][2]=matrix_name[2][0];
matrix_name[2][0]=temp1;
temp2=matrix_name[0][1];
matrix_name[0][1]=matrix_name[1][2];
matrix_name[1][2]=matrix_name[2][1];
matrix_name[2][1]=matrix_name[1][0];
matrix_name[1][0]=temp2;
change_matrix_name(1,a);
}
void change_matrix_name(int b,char a)
{
int *c;
if(a=='A')
{
c=A;
}
if(a=='B')
{
c=B;
}
if(a=='C')
{
c=C;
}
if(a=='D')
{
c=D;
}
if(a=='E')
{
c=E;
}
if(a=='F')
{
c=F;
}
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
if(b==0)
{
matrix_name[i][j]=*c;
c++;
}
if(b==1)
{
*c=matrix_name[i][j];
c++;
}
}
}
}
void front_clockwise(void)
{
//stepper turn mechanism
temp[0][0]=A[0][2];
temp[0][1]=A[1][2];
temp[0][2]=A[2][2];
A[0][2]=F[0][0];
A[1][2]=F[0][1];
A[2][2]=F[0][2];
F[0][0]=C[2][0];
F[0][1]=C[1][0];
F[0][2]=C[0][0];
C[2][0]=E[2][2];
C[1][0]=E[2][1];
C[0][0]=E[2][0];
E[2][2]=temp[0][0];
E[2][1]=temp[0][1];
E[2][0]=temp[0][2];
circle_clockwise('B');
}
void front_anticlockwise(void)
{
//stepper turn mechanism
temp[0][0]=A[0][2];
temp[0][1]=A[1][2];
temp[0][2]=A[2][2];
A[0][2]=E[2][2];
A[1][2]=E[2][1];
A[2][2]=E[2][0];
E[2][2]=C[2][0];
E[2][1]=C[1][0];
E[2][0]=C[0][0];
C[2][0]=F[0][0];
C[1][0]=F[0][1];
C[0][0]=F[0][2];
F[0][0]=temp[0][0];
F[0][1]=temp[0][1];
F[0][2]=temp[0][2];
circle_anticlockwise('B');
}
void search_cross_location(void)
{
// positions to check for are :01 10 12 21
d=0;
for(i=0,j=1;i<=2;i+=2)
{
if(A[i][j]==2)
{
cross_value[d][0]=7;
cross_value[d][1]=i;
cross_value[d][2]=j;
d+=1;
}
if(B[i][j]==2)
{
cross_value[d][0]=8;
cross_value[d][1]=i;
cross_value[d][2]=j;
d+=1;
}
if(C[i][j]==2)
{
cross_value[d][0]=9;
cross_value[d][1]=i;
cross_value[d][2]=j;
d+=1;
}
if(D[i][j]==2)
{
cross_value[d][0]=10;
cross_value[d][1]=i;
cross_value[d][2]=j;
d+=1;
}
if(E[i][j]==2)
{
cross_value[d][0]=11;
cross_value[d][1]=i;
cross_value[d][2]=j;
d+=1;
}
if(F[i][j]==2)
{
cross_value[d][0]=12;
cross_value[d][1]=i;
cross_value[d][2]=j;
d+=1;
}
if(d==4)
{
break;
}
}
for(i=1,j=0;j<=2;j+=2)
{
if(A[i][j]==2)
{
cross_value[d][0]=7;
cross_value[d][1]=i;
cross_value[d][2]=j;
d+=1;
}
if(B[i][j]==2)
{
cross_value[d][0]=8;
cross_value[d][1]=i;
cross_value[d][2]=j;
d+=1;
}
if(C[i][j]==2)
{
cross_value[d][0]=9;
cross_value[d][1]=i;
cross_value[d][2]=j;
d+=1;
}
if(D[i][j]==2)
{
cross_value[d][0]=10;
cross_value[d][1]=i;
cross_value[d][2]=j;
d+=1;
}
if(E[i][j]==2)
{
cross_value[d][0]=11;
cross_value[d][1]=i;
cross_value[d][2]=j;
d+=1;
}
if(F[i][j]==2)
{
cross_value[d][0]=12;
cross_value[d][1]=i;
cross_value[d][2]=j;
d+=1;
}
if(d==4)
{
break;
}
}
}
void calculate_edgepairs(void)
{
edgepair[0]=A[1][0]*10+D[1][2];
edgepair[1]=A[0][1]*10+E[1][0];
edgepair[2]=A[1][2]*10+B[1][0];
edgepair[3]=A[2][1]*10+F[1][0];
edgepair[4]=B[0][1]*10+E[2][1];
edgepair[5]=B[1][2]*10+C[1][0];
edgepair[6]=B[2][1]*10+F[0][1];
edgepair[7]=C[0][1]*10+E[1][2];
edgepair[8]=C[1][2]*10+D[1][0];
edgepair[9]=C[2][1]*10+F[1][2];
edgepair[10]=D[0][1]*10+E[0][1];
edgepair[11]=D[2][1]*10+F[2][1];
for(d=0;d<=11;d++)
{
printf("\nEdge pair %d : %d\n",d,edgepair[d]);
}
}