Rubik Cube C

Started by
2 comments, last by iMalc 12 years, 3 months ago
Hello,

I'm developing a rubik cube in c for a class I have. And I've defined the structures, but, am having a bit of a problem initializing them.

Was wondering if I could get a little help.


// each square of the little cubes in the rubik cube
typedef struct quadr
{
char collor;
char axys;
} quad;

// Cubes in the rubik cube
typedef struct squareR
{
quad q[6];
char axys;
// Check if its side is valid, eg. If it shows on the rubik cube
int valid;
} square;
// Rubik cube
typedef struct cubeR
{
square q[3][3][3];
} cubo;


I was thinking of doing something like this:


void startup()
{
int x,y,z,w;
for(x=0;x<3;x++)
{
for(y=0;y<3;y++)
{
for(z=0;z<3;z++)
{
for(w=0;w<6;w++)
{
//initialization goes here
}
}
}
}
}


The hard part i find by now, is making the initialization...

The axys variable has to do to which side the cube(s) are turning to, so that i can show the correct collors.
The collors at the beggining, will be filled probably with numbers from 0 to 5, or something like that.

Thank you,
Advertisement
I have no idea how you plan to use the axys variables so I can't say how to initialize them. For the face colors I would approach things from the opposite direction: for each face color figure out which cubes need to have faces with those colors and then mark the cube faces that color. You should probably start with every cube with every face black or however you plan to mark the faces that face inwards.
Hmm, I agree, thankyou. Just don't still know how to initialize my variables, I might have complicated the problem much more than it was needed to...
Pingback to a cross-post from another forum: http://cboard.cprogramming.com/c-programming/144837-typedef-structs-inside-typdef-structs.html
"In order to understand recursion, you must first understand recursion."
My website dedicated to sorting algorithms

This topic is closed to new replies.

Advertisement