Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include "cube.h"
- using namespace std;
- cube::cube(face start_state[6]) {
- int i;
- if (start_state != NULL) {
- for (i=0; i<6; i++) state[i] = start_state[i];
- }
- return;
- }
- void cube::printColor(char c) {
- //lowercase
- if (c > 'Z') c -= 'z' - 'Z';
- if ((c < 'E' && c >= 'A') || c == '0') cout << "\x1b[37m" << "[" << c << "]";
- else if ((c < 'I' && c >= 'A') || c == '1') cout << "\x1b[35m" << "[" << c << "]";
- else if ((c < 'M' && c >= 'A') || c == '2') cout << "\x1b[32m" << "[" << c << "]";
- else if ((c < 'Q' && c >= 'A') || c == '3') cout << "\x1b[31m" << "[" << c << "]";
- else if ((c < 'U' && c >= 'A') || c == '4') cout << "\x1b[34m" << "[" << c << "]";
- else cout << "\x1b[33m" << "[" << c << "]";
- }
- void cube::printCube() {
- //sorry this is confusing AF, but it works
- int i;
- int j;
- cout << " ";
- for (j=0; j<9; j++) {
- printColor(*(state[4].CState[j]));
- if (j%3 == 2) cout << endl << " ";
- }
- cout << endl;
- for (i=0; i<3; i++) {
- for (j=0; j<3; j++) printColor(*(state[1].BState[j + 3*i]));
- cout << " ";
- for (j=0; j<3; j++) printColor(*(state[0].AState[j + 3*i]));
- cout << " ";
- for (j=0; j<3; j++) printColor(*(state[3].DState[j + 3*i]));
- cout << endl;
- }
- cout << endl << " ";
- for (j=0; j<9; j++) {
- printColor(*(state[2].AState[j]));
- if (j%3 == 2) cout << endl << " ";
- }
- cout << endl << " ";
- for (j=0; j<9; j++) {
- printColor(*(state[5].AState[j]));
- if (j%3 == 2) cout << endl << " ";
- }
- cout << "\x1b[37m" << endl;
- return;
- }
- void cube::vSlice(char layer) {
- int i;
- char buffer[9];
- //drop U into the buffer
- for (i=layer; i<9; i+=3) buffer[i] = *(state[0].AState[i]);
- //move F to U
- for (i=layer; i<9; i+=3) *(state[0].AState[i]) = *(state[2].AState[i]);
- //move D to F
- for (i=layer; i<9; i+=3) *(state[2].AState[i]) = *(state[5].AState[i]);
- //move B to D
- for (i=layer; i<9; i+=3) *(state[5].AState[i]) = *(state[4].CState[i]);
- //move F to B
- for (i=layer; i<9; i+=3) *(state[4].CState[i]) = buffer[i];
- char rBuffer[9];
- switch (layer) {
- case 0:
- for (i=0; i<9; i++) rBuffer[i] = *(state[1].DState[i]);
- for (i=0; i<9; i++) *(state[1].AState[i]) = rBuffer[i];
- break;
- case 2:
- for (i=0; i<9; i++) rBuffer[i] = *(state[3].BState[i]);
- for (i=0; i<9; i++) *(state[3].AState[i]) = rBuffer[i];
- break;
- }
- }
- void cube::R() {
- vSlice(2);
- return;
- }
- void cube::r() {
- vSlice(2);
- vSlice(1);
- return;
- }
- void cube::Li() {
- vSlice(0);
- return;
- }
- void cube::li() {
- vSlice(0);
- vSlice(1);
- return;
- }
- void cube::Mi() {
- vSlice(1);
- return;
- }
- #include <iostream>
- #include "face.h"
- using namespace std;
- int solved[54] = {
- 'a', 'A', 'b', 'D', '0', 'B', 'd', 'C', 'c',
- 'e', 'E', 'f', 'H', '1', 'F', 'h', 'G', 'g',
- 'i', 'I', 'j', 'L', '2', 'J', 'l', 'K', 'k',
- 'm', 'M', 'n', 'P', '3', 'N', 'p', 'O', 'o',
- 'q', 'Q', 'r', 'T', '4', 'R', 't', 'S', 's',
- 'u', 'U', 'v', 'X', '5', 'V', 'x', 'W', 'w'
- };
- face::face(int start_state[9], char face) {
- int i;
- //set the initial state
- if (start_state == NULL) {
- face = (face - '0')*9;
- for (i=0; i<9; i++) state[i] = solved[face + i];
- }
- else {
- for (i=0; i<9; i++) state[i] = start_state[i];
- }
- //set the pointer arrays
- for (i=0; i<9; i++) AState[i] = &(state[i]);
- //the rotation of one side and how it switches
- //everything. Makes it easier to use fors
- const char rotate[9] = {6, 3, 0, 7, 4, 1, 8, 5, 2};
- //rotate all of the sides using our rotate array
- for (i=0; i<9; i++) BState[i] = AState[rotate[i]];
- for (i=0; i<9; i++) CState[i] = BState[rotate[i]];
- for (i=0; i<9; i++) DState[i] = CState[rotate[i]];
- return;
- }
- #include <iostream>
- #include "cube.h"
- #define SUCCESS 0
- #define FAIL 1
- #define U c.U();
- #define Ui c.Ui();
- #define D c.D();
- #define Di c.Di();
- #define R c.R();
- #define Ri c.Ri();
- #define L c.F();
- #define Li c.Fi();
- #define F c.F();
- #define Fi c.Fi();
- #define B c.B();
- #define Bi c.Bi();
- #define M c.M();
- #define Mi c.Mi();
- using namespace std;
- int main(int argc, char* argv[]) {
- cube c;
- c.printCube();
- //T perm
- R U Ri Ui Ri F R R Ui Ri Ui R U Ri Fi
- cout << "-------------------" << endl << endl;
- c.printCube();
- //undo
- R U Ri Ui Ri F R R Ui Ri Ui R U Ri Fi
- cout << "-------------------" << endl << endl;
- c.printCube();
- //M perm
- Mi Mi U Mi Mi U U Mi Mi U Mi Mi
- cout << "-------------------" << endl << endl;
- c.printCube();
- //undo
- Mi Mi U Mi Mi U U Mi Mi U Mi Mi
- cout << "-------------------" << endl << endl;
- c.printCube();
- return SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment