@jonnin
In the book that I had, there is no such thing as rotating any of the centre planes, all the moves are expressed as moving these planes: right, left; upper, down, front, back. So only 6 rotating planes.
markyrocks wrote: |
---|
I didn't put any planning into this I just kinda sat down and started writing |
Perhaps now you realise the value of doing some design first with a pencil and paper :+) I guess most of your 700 LOC is probably wasted effort.
It would be worth it if you show us the first parts of your new code. Just so we can see you are getting the basics right for example: like no implementation code in header files ; and good naming of variables and functions.
I thought about this problem a bit more: rather than a 3d array, I would have 6 separate 3 by 3 array to represent each face. Those arrays store the colours only, which are enums. If you then are careful & consistent about which corners are represented by the [0][0] and [2][2] parts of the array, it will be easier to manage the rotation of a face. If one was looking at the upper face, the [0][0] could be the lower left corner, while [2][2] would be the upper right. Then consider the left face, the [0][2] is the same corner as the [0][0] of the upper face, the [0][0] of the left face is the same as the lower left of the front face. Then to rotate the front face by 90 degrees clockwise, it just means moving [0][0], [0][1], [0][2] to the array representing the upper face, the same for the other 3 small cubes on each relevant face. Finally rotate the colours on the front face by 90 deg clockwise.
I hope all this is not too confusing, but doing it that way avoids having to worry about orientation of corner and edge cubes. My idea may be similar to your original idea, but your code had too much nesting of the data structure IMO.
You could do the following to start with, in a header file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
enum colours {blue, white, red, yellow, orange, green};
constexpr int CubeDim {3};
using Face = std::array<std::array<colours,CubeDim>, CubeDim>;
class rubix {
private:
Face Front; // F in the notation
Face Back; // B in the notation
Face Right; // R in the notation
Face Left; // L in the notation
Face Upper; // U in the notation
Face Down; // D in the notation
public:
rubix();
// Put declarations for the rotate functions here
// or put them in an interface class which this class inherits
};
|
In rubix.cpp
1 2 3
|
rubix::rubix() {
// Initialise each face with a colour to represent a solved cube
}
|
With the idea of rotating the entire cube, that was necessary in the book that I had. If one uses the idea of storing the faces, it would be reasonably easy to do.
Once you have the implementation, you could try making some patterns, starting out with a solved cube. For example: an X pattern on each side.
Hope all goes well !! :+)