markyrocks Posted January 31, 2020 Posted January 31, 2020 (edited) just doin this for fun. Its my version of a virtual rubix cube and I plan to just make a cout type display that shows all the sides in a fold out type way. Then i plan to write functions to rotate it around and maybe one day solve it or have it figure out how to solve itself and or put in the ability to enter in information about your own cube and have it tell you how to solve it. I've just been playing with a rubix cube lately and figured this would be a good challenge. I just started working on it this evening and its coming along. Maybe even use autoit to actually draw the cube at some point or us the the c++ as a dll and build an autoit gui to control it or something. I realize this has all been done b4 but like i said its just for fun. Just a challenge. edit. I found a typo or 2 and the one if statement was all backwards. i was going to use it in the while statement but just decided to use it in an if and just break but i forgot to switch the logic around. Spoiler expandcollapse popup#include <iostream> #include <time.h> #include <stdlib.h> class Cube { //26 pieces 9 front and back 8 in the middle public: struct Threepiece { //8 three sided pieces struct one { char right, left, up, down , front, back; struct pos{ int x, y, z; }; pos pos; }; one one; struct two { char right, left, up, down, front, back; struct pos { int x, y, z; }; pos pos; }; two two; struct three { char right, left, up, down, front, back; struct pos { int x, y, z; }; pos pos; }; three three; struct four { char right, left, up, down, front, back; struct pos { int x, y, z; }; pos pos; }; four four; struct five { char right, left, up, down, front, back; struct pos { int x, y, z; }; pos pos; }; five five; struct six { char right, left, up, down, front, back; struct pos { int x, y, z; }; pos pos; }; six six; struct seven { char right, left, up, down, front, back; struct pos { int x, y, z; }; pos pos; }; seven seven; struct eight { char right, left, up, down, front, back; struct pos { int x, y, z; }; pos pos; }; eight eight; }; Threepiece threepiece; struct Twopiece { // 12 two sided pieces struct one { char right, left,front, back,up,down; struct pos { int x, y, z; }; pos pos; }; one one; struct two{ char right, left, front, back,up,down; struct pos { int x, y, z; }; pos pos; }; two two; struct three { char right, left, front, back,up, down; struct pos { int x, y, z; }; pos pos; }; three three; struct four { char right, left, front, back, up, down; struct pos { int x, y, z; }; pos pos; }; four four; struct five { char right, left, up, down, front, back; struct pos { int x, y, z; }; pos pos; }; five five; struct six { char right, left, up, down, front, back; struct pos { int x, y, z; }; pos pos; }; six six; struct seven { char right, left, up, down, front, back; struct pos { int x, y, z; }; pos pos; }; seven seven; struct eight { char right, left, up, down, front, back; struct pos { int x, y, z; }; pos pos; }; eight eight; struct nine { char right, left, up, down, front, back; struct pos { int x, y, z; }; pos pos; }; nine nine; struct ten { char right, left, up, down, front, back; struct pos { int x, y, z; }; pos pos; }; ten ten; struct eleven { char right, left, up, down, front, back; struct pos { int x, y, z; }; pos pos; }; eleven eleven; struct twelve { char right, left, up, down, front,back; struct pos { int x, y, z; }; pos pos; }; twelve twelve; }; Twopiece twopiece; struct Onepiece { //six one sided pieces struct one { char right, left, up, down, front, back; struct pos { int x, y, z; }; pos pos; }; one one; struct two { char right, left, up, down, front, back; struct pos { int x, y, z; }; pos pos; }; two two; struct three { char right, left, up, down, front, back; struct pos { int x, y, z; }; pos pos; }; three three; struct four { char right, left, up, down, front, back; struct pos { int x, y, z; }; pos pos; }; four four; struct five { char right, left, up, down, front, back; struct pos { int x, y, z; }; pos pos; }; five five; struct six { char right, left, up, down, front, back; struct pos { int x, y, z; }; pos pos; }; six six; }; Onepiece onepiece; void OnePieceSetPos(Cube cube, int piece, int x, int y, int z) { if (piece == 0) { cube.onepiece.one.pos.x = x; cube.onepiece.one.pos.y = y; cube.onepiece.one.pos.z = z; } if (piece == 1) { cube.onepiece.two.pos.x = x; cube.onepiece.two.pos.y = y; cube.onepiece.two.pos.z = z; } if (piece == 2) { cube.onepiece.three.pos.x = x; cube.onepiece.three.pos.y = y; cube.onepiece.three.pos.z = z; } if (piece == 3) { cube.onepiece.four.pos.x = x; cube.onepiece.four.pos.y = y; cube.onepiece.four.pos.z = z; } if (piece == 4) { cube.onepiece.five.pos.x = x; cube.onepiece.five.pos.y = y; cube.onepiece.five.pos.z = z; } if (piece == 5) { cube.onepiece.six.pos.x = x; cube.onepiece.six.pos.y = y; cube.onepiece.six.pos.z = z; } } int* OnePieceGetPos(Cube cube, int piece) { int pos[3]; if (piece == 0) { pos[0] = cube.onepiece.one.pos.x; pos[1] = cube.onepiece.one.pos.y; pos[2] = cube.onepiece.one.pos.z; return pos; } if (piece == 1) { pos[0] = cube.onepiece.two.pos.x; pos[1] = cube.onepiece.two.pos.y; pos[2] = cube.onepiece.two.pos.z; return pos; } if (piece == 2) { pos[0] = cube.onepiece.three.pos.x; pos[1] = cube.onepiece.three.pos.y; pos[2] = cube.onepiece.three.pos.z; return pos; } if (piece == 3) { pos[0] = cube.onepiece.four.pos.x; pos[1] = cube.onepiece.four.pos.y; pos[2] = cube.onepiece.four.pos.z; return pos; } if (piece == 4) { pos[0] = cube.onepiece.five.pos.x; pos[1] = cube.onepiece.five.pos.y; pos[2] = cube.onepiece.five.pos.z; return pos; } if (piece == 5) { pos[0] = cube.onepiece.six.pos.x; pos[1] = cube.onepiece.six.pos.y; pos[2] = cube.onepiece.six.pos.z; return pos; } } void TwoPieceSetPos(Cube cube, int piece, int x, int y, int z) { if (piece == 0) { cube.twopiece.one.pos.x = x; cube.twopiece.one.pos.y = y; cube.twopiece.one.pos.z = z; } if (piece == 1) { cube.twopiece.two.pos.x = x; cube.twopiece.two.pos.y = y; cube.twopiece.two.pos.z = z; } if (piece == 2) { cube.twopiece.three.pos.x = x; cube.twopiece.three.pos.y = y; cube.twopiece.three.pos.z = z; } if (piece == 3) { cube.twopiece.four.pos.x = x; cube.twopiece.four.pos.y = y; cube.twopiece.four.pos.z = z; } if (piece == 4) { cube.twopiece.five.pos.x = x; cube.twopiece.five.pos.y = y; cube.twopiece.five.pos.z = z; } if (piece == 5) { cube.twopiece.six.pos.x = x; cube.twopiece.six.pos.y = y; cube.twopiece.six.pos.z = z; } if (piece == 6) { cube.twopiece.seven.pos.x = x; cube.twopiece.seven.pos.y = y; cube.twopiece.seven.pos.z = z; } if (piece == 7) { cube.twopiece.eight.pos.x = x; cube.twopiece.eight.pos.y = y; cube.twopiece.eight.pos.z = z; } if (piece == 8) { cube.twopiece.nine.pos.x = x; cube.twopiece.nine.pos.y = y; cube.twopiece.nine.pos.z = z; } if (piece == 9) { cube.twopiece.ten.pos.x = x; cube.twopiece.ten.pos.y = y; cube.twopiece.ten.pos.z = z; } if (piece == 10) { cube.twopiece.eleven.pos.x = x; cube.twopiece.eleven.pos.y = y; cube.twopiece.eleven.pos.z = z; } if (piece == 11) { cube.twopiece.twelve.pos.x = x; cube.twopiece.twelve.pos.y = y; cube.twopiece.twelve.pos.z = z; } } int* TwoPieceGetPos(Cube cube, int piece) { int pos[3]; if (piece == 0) { pos[0] = cube.twopiece.one.pos.x; pos[1] = cube.twopiece.one.pos.y; pos[2] = cube.twopiece.one.pos.z; return pos; } if (piece == 1) { pos[0] = cube.twopiece.two.pos.x; pos[1] = cube.twopiece.two.pos.y; pos[2] = cube.twopiece.two.pos.z; return pos; } if (piece == 2) { pos[0] = cube.twopiece.three.pos.x; pos[1] = cube.twopiece.three.pos.y; pos[2] = cube.twopiece.three.pos.z; return pos; } if (piece == 3) { pos[0] = cube.twopiece.four.pos.x; pos[1] = cube.twopiece.four.pos.y; pos[2] = cube.twopiece.four.pos.z; return pos; } if (piece == 4) { pos[0] = cube.twopiece.five.pos.x; pos[1] = cube.twopiece.five.pos.y; pos[2] = cube.twopiece.five.pos.z; return pos; } if (piece == 5) { pos[0] = cube.twopiece.six.pos.x; pos[1] = cube.twopiece.six.pos.y; pos[2] = cube.twopiece.six.pos.z; return pos; } if (piece == 6) { pos[0] = cube.twopiece.seven.pos.x; pos[1] = cube.twopiece.seven.pos.y; pos[2] = cube.twopiece.seven.pos.z; return pos; } if (piece == 7) { pos[0] = cube.twopiece.eight.pos.x; pos[1] = cube.twopiece.eight.pos.y; pos[2] = cube.twopiece.eight.pos.z; return pos; } if (piece == 8) { pos[0] = cube.twopiece.nine.pos.x; pos[1] = cube.twopiece.nine.pos.y; pos[2] = cube.twopiece.nine.pos.z; return pos; } if (piece == 9) { pos[0] = cube.twopiece.ten.pos.x; pos[1] = cube.twopiece.ten.pos.y; pos[2] = cube.twopiece.ten.pos.z; return pos; } if (piece == 10) { pos[0] = cube.twopiece.eleven.pos.x; pos[1] = cube.twopiece.eleven.pos.y; pos[2] = cube.twopiece.eleven.pos.z; return pos; } if (piece == 11) { pos[0] = cube.twopiece.twelve.pos.x; pos[1] = cube.twopiece.twelve.pos.y; pos[2] = cube.twopiece.twelve.pos.z; return pos; } } void BuildOnePieces(Cube cube) { cube.onepiece.one.front = 'O'; cube.onepiece.two.front = 'Y'; cube.onepiece.three.front = 'B'; cube.onepiece.four.front = 'R'; cube.onepiece.one.front = 'W'; cube.onepiece.one.front = 'G'; } void BuildTwoPieces(Cube cube) { cube.twopiece.one.right = 'G'; cube.twopiece.one.left = 'R'; cube.twopiece.two.right = 'G'; cube.twopiece.two.left = 'O'; cube.twopiece.three.right = 'G'; cube.twopiece.three.left = 'W'; cube.twopiece.four.right = 'G'; cube.twopiece.four.left = 'Y'; cube.twopiece.five.right = 'B'; cube.twopiece.five.left = 'W'; cube.twopiece.six.right = 'B'; cube.twopiece.six.left = 'R'; cube.twopiece.seven.right = 'B'; cube.twopiece.seven.left = 'O'; cube.twopiece.eight.right = 'B'; cube.twopiece.eight.left = 'Y'; cube.twopiece.nine.right = 'Y'; cube.twopiece.nine.left = 'O'; cube.twopiece.ten.right = 'Y'; cube.twopiece.ten.left = 'R'; cube.twopiece.eleven.right = 'W'; cube.twopiece.eleven.left = 'R'; cube.twopiece.twelve.right = 'W'; cube.twopiece.twelve.left = 'O'; } void BuildThreePieces(Cube cube) { cube.threepiece.one.right = 'O'; cube.threepiece.one.left = 'W'; cube.threepiece.one.up = 'G'; cube.threepiece.two.right = 'B'; cube.threepiece.two.left = 'O'; cube.threepiece.two.up = 'Y'; cube.threepiece.three.right = 'Y'; cube.threepiece.three.left = 'R'; cube.threepiece.three.up = 'B'; cube.threepiece.four.right = 'W'; cube.threepiece.four.left = 'R'; cube.threepiece.four.up = 'G'; cube.threepiece.five.right = 'W'; // cube.threepiece.five.left = 'O'; cube.threepiece.five.up = 'B'; cube.threepiece.six.right = 'R'; cube.threepiece.six.left = 'W'; cube.threepiece.six.up = 'B'; cube.threepiece.seven.right = 'Y'; cube.threepiece.seven.left = 'G'; cube.threepiece.seven.up = 'R'; cube.threepiece.eight.right = 'Y'; cube.threepiece.eight.left = 'O'; cube.threepiece.eight.up = 'G'; } void PopulateRandomCube(Cube cube) { srand(time(0)); //lets do the single sided pieces first int rando; int count = 0; while (count<6) { while ((rando = ((rand() % 10) / 2) - 1) > -1 ? false : true) { //picks a random number 5 or less subtracts 1 until its greater than -1 std::cout << "rando " << rando << std::endl; } //lets set the first piece 1= 1,1,0 2=1,2,1 3=1,0,1 4=0,1,1 5=2,1,1 6=1,1,2 xyz int* temp = OnePieceGetPos(cube, rando); if (temp[0] == NULL && count==0) { OnePieceSetPos(cube, rando, 1, 1, 0); count++; } if (temp[0] == NULL && count == 1) { OnePieceSetPos(cube, rando, 1, 2, 1); count++; } if (temp[0] == NULL && count == 2) { OnePieceSetPos(cube, rando, 1, 0, 1); count++; } if (temp[0] == NULL && count == 3) { OnePieceSetPos(cube, rando, 0, 1, 1); count++; } if (temp[0] == NULL && count == 4) { OnePieceSetPos(cube, rando, 2, 1, 1); count++; } if (temp[0] == NULL && count == 5) { OnePieceSetPos(cube, rando, 1, 1, 2); count++; } } // so now lets work on the 2 sided pieces 12 pieces count = 0; rando = NULL; while (count < 12) { while (1) { rando = ((rand() % 100) / 8) - 1; //99/8=12ish -1 should be 11 if (rando == NULL && rando < 0 && rando>13) { break; } } int* temp = TwoPieceGetPos(cube, rando); if (temp[0] == NULL && count == 0) { TwoPieceSetPos(cube, rando, 1, 0, 0); count++; } if (temp[0] == NULL && count == 1) { TwoPieceSetPos(cube, rando, 0, 1, 0); count++; } if (temp[0] == NULL && count == 2) { TwoPieceSetPos(cube, rando, 2, 1, 0); count++; } if (temp[0] == NULL && count == 3) { TwoPieceSetPos(cube, rando, 1, 2, 0); count++; } if (temp[0] == NULL && count == 4) { TwoPieceSetPos(cube, rando, 0, 0, 1); count++; } if (temp[0] == NULL && count == 5) { TwoPieceSetPos(cube, rando, 2, 0, 1); count++; } if (temp[0] == NULL && count == 6) { TwoPieceSetPos(cube, rando, 0, 2, 1); count++; } if (temp[0] == NULL && count == 7) { TwoPieceSetPos(cube, rando, 2, 2, 1); count++; } //0=1,0,0 1=0,1,0 2=2,1,0 3=1,2,0 || 4=0,0,1 5=2,0,1 6=0,2,1 7=2,2,1 || 8=0,1,2 9=2,1,2 10=1,0,2 11=1,2,2 if (temp[0] == NULL && count == 8) { TwoPieceSetPos(cube, rando, 0, 1, 2); count++; } if (temp[0] == NULL && count == 9) { TwoPieceSetPos(cube, rando, 2, 1, 2); count++; } if (temp[0] == NULL && count == 10) { TwoPieceSetPos(cube, rando, 1, 0, 2); count++; } if (temp[0] == NULL && count == 11) { TwoPieceSetPos(cube, rando, 1, 2, 2); count++; } } // start of the three sided piece bananza } }; int main() { Cube cube; Cube cubeAry[3][3][3]; } Edited January 31, 2020 by markyrocks Spoiler "I Believe array math to be potentially fatal, I may be dying from array math poisoning"
markyrocks Posted February 1, 2020 Author Posted February 1, 2020 (edited) I've come to the conclusion that the above code is some crap. Lol. It's just overly complicated and unnecessary. After thoroughly thinking about what I'm trying to do and talking to some folks on the c++ forum I could probably get to the same point in the program with like 50 lines of code instead of 500. It's just growing pains. No biggie. It's all for lols anyways. Edit edit. What i just put in the spoiler section below will make a random cube and cout what is in the cube and its right around 500 lines. Doh!! i just realized it only outputs 5 sides..... der Spoiler expandcollapse popup#include <iostream> #include <time.h> #include <stdlib.h> #include <windows.h> using namespace std; class Cube { public: struct Piece { char right, left, up, down, front, back, color1, color2, color3; int type; }; Piece piece; }; void SetRandomColors(Cube cubeArray[3][3][3]) { srand(time(0)); // these combos probably need to be global in the future char combo1[6]{ 'W','G','R','B','Y','O' }; char combo2[12][2]{ {'W','B'},{'W','O'},{'W','G'},{'W','R'},{'Y','B'},{'Y','R'},{'Y','G'},{'Y','O'},{'B','R'},{'B','O'},{'O','G'},{'G','R'} }; char combo3[8][3]{ {'B','W','R'},{'W','G','R'},{'B','R','Y'},{'Y','R','G'},{'W','B','O'},{'G','O','Y'},{'B','Y','O'},{'G','W','O'} }; int rando = NULL; int cnt = 0; bool firstTime = true; //singles while (cnt < 6) {//&& while (combo1[rando] == NULL | firstTime == true) { rando = (rand() % 100) / 19; //should pump out 0-5 firstTime = false; } if (cnt == 0 && combo1[rando] != NULL) { cubeArray[1][1][0].piece.color1 = combo1[rando]; cubeArray[1][1][0].piece.type = 1; combo1[rando] = NULL; cnt++; } if (cnt == 1 && combo1[rando] != NULL) { cubeArray[1][1][2].piece.color1 = combo1[rando]; cubeArray[1][1][2].piece.type = 1; combo1[rando] = NULL; cnt++; } if (cnt == 2 && combo1[rando] != NULL) { cubeArray[0][1][1].piece.color1 = combo1[rando]; cubeArray[0][1][1].piece.type = 1; combo1[rando] = NULL; cnt++; } if (cnt == 3 && combo1[rando] != NULL) { cubeArray[2][1][1].piece.color1 = combo1[rando]; cubeArray[2][1][1].piece.type = 1; combo1[rando] = NULL; cnt++; } if (cnt == 4 && combo1[rando] != NULL) { cubeArray[1][2][1].piece.color1 = combo1[rando]; cubeArray[1][2][1].piece.type = 1; combo1[rando] = NULL; cnt++; } if (cnt == 5 && combo1[rando] != NULL) { cubeArray[1][0][1].piece.color1 = combo1[rando]; cubeArray[1][0][1].piece.type = 1; combo1[rando] = NULL; cnt++; } } firstTime = true; cnt = 0; rando = NULL; //doubles while (cnt < 12) { while (rando > 11 | firstTime==true | combo2[rando][0] == NULL) { rando = ((rand() % 100) / 8); firstTime = false; } if (cnt == 0 && combo2[rando][0] != NULL) { cubeArray[1][0][0].piece.color1 = combo2[rando][0]; cubeArray[1][0][0].piece.color2 = combo2[rando][1]; cubeArray[1][0][0].piece.type = 2; combo2[rando][0] = NULL; combo2[rando][1] = NULL; cnt++; } if (cnt == 1 && combo2[rando][0] != NULL) { cubeArray[1][2][0].piece.color1 = combo2[rando][0]; cubeArray[1][2][0].piece.color2 = combo2[rando][1]; cubeArray[1][2][0].piece.type = 2; combo2[rando][0] = NULL; combo2[rando][1] = NULL; cnt++; } if (cnt == 2 && combo2[rando][0] != NULL) { cubeArray[0][1][0].piece.color1 = combo2[rando][0]; cubeArray[0][1][0].piece.color2 = combo2[rando][1]; cubeArray[0][1][0].piece.type = 2; combo2[rando][0] = NULL; combo2[rando][1] = NULL; cnt++; } if (cnt == 3 && combo2[rando][0] != NULL) { cubeArray[2][1][0].piece.color1 = combo2[rando][0]; cubeArray[2][1][0].piece.color2 = combo2[rando][1]; cubeArray[2][1][0].piece.type = 2; combo2[rando][0] = NULL; combo2[rando][1] = NULL; cnt++; } if (cnt == 4 && combo2[rando][0] != NULL) { cubeArray[0][0][1].piece.color1 = combo2[rando][0]; cubeArray[0][0][1].piece.color2 = combo2[rando][1]; cubeArray[0][0][1].piece.type = 2; combo2[rando][0] = NULL; combo2[rando][1] = NULL; cnt++; } if (cnt == 5 && combo2[rando][0] != NULL) { cubeArray[2][0][1].piece.color1 = combo2[rando][0]; cubeArray[2][0][1].piece.color2 = combo2[rando][1]; cubeArray[2][0][1].piece.type = 2; combo2[rando][0] = NULL; combo2[rando][1] = NULL; cnt++; } if (cnt == 6 && combo2[rando][0] != NULL) { cubeArray[0][2][1].piece.color1 = combo2[rando][0]; cubeArray[0][2][1].piece.color2 = combo2[rando][1]; cubeArray[0][2][1].piece.type = 2; combo2[rando][0] = NULL; combo2[rando][1] = NULL; cnt++; } if (cnt == 7 && combo2[rando][0] != NULL) { cubeArray[2][2][1].piece.color1 = combo2[rando][0]; cubeArray[2][2][1].piece.color2 = combo2[rando][1]; cubeArray[2][2][1].piece.type = 2; combo2[rando][0] = NULL; combo2[rando][1] = NULL; cnt++; } if (cnt == 8 && combo2[rando][0] != NULL) { cubeArray[1][0][2].piece.color1 = combo2[rando][0]; cubeArray[1][0][2].piece.color2 = combo2[rando][1]; cubeArray[1][0][2].piece.type = 2; combo2[rando][0] = NULL; combo2[rando][1] = NULL; cnt++; } if (cnt == 9 && combo2[rando][0] != NULL) { cubeArray[0][1][2].piece.color1 = combo2[rando][0]; cubeArray[0][1][2].piece.color2 = combo2[rando][1]; cubeArray[0][1][2].piece.type = 2; combo2[rando][0] = NULL; combo2[rando][1] = NULL; cnt++; } if (cnt == 10 && combo2[rando][0] != NULL) { cubeArray[2][1][2].piece.color1 = combo2[rando][0]; cubeArray[2][1][2].piece.color2 = combo2[rando][1]; cubeArray[2][1][2].piece.type = 2; combo2[rando][0] = NULL; combo2[rando][1] = NULL; cnt++; } if (cnt == 11 && combo2[rando][0] != NULL) { cubeArray[1][2][2].piece.color1 = combo2[rando][0]; cubeArray[1][2][2].piece.color2 = combo2[rando][1]; cubeArray[1][2][2].piece.type = 2; combo2[rando][0] = NULL; combo2[rando][1] = NULL; cnt++; } } firstTime = true; rando = NULL; cnt = 0; //triples while (cnt < 8) { while (rando >7 | combo3[rando][0] == NULL | firstTime == true) { rando = rand() % 10; firstTime = false; } if (cnt == 0 && combo3[rando][0] != NULL) { cubeArray[0][0][0].piece.color1 = combo3[rando][0]; cubeArray[0][0][0].piece.color2 = combo3[rando][1]; cubeArray[0][0][0].piece.color3 = combo3[rando][2]; cubeArray[0][0][0].piece.type = 3; combo3[rando][0] = NULL; combo3[rando][1] = NULL; combo3[rando][2] = NULL; cnt++; } if (cnt == 1 && combo3[rando][0] != NULL) { cubeArray[2][0][0].piece.color1 = combo3[rando][0]; cubeArray[2][0][0].piece.color2 = combo3[rando][1]; cubeArray[2][0][0].piece.color3 = combo3[rando][2]; cubeArray[2][0][0].piece.type = 3; combo3[rando][0] = NULL; combo3[rando][1] = NULL; combo3[rando][2] = NULL; cnt++; } if (cnt == 2 && combo3[rando][0] != NULL) { cubeArray[0][2][0].piece.color1 = combo3[rando][0]; cubeArray[0][2][0].piece.color2 = combo3[rando][1]; cubeArray[0][2][0].piece.color3 = combo3[rando][2]; cubeArray[0][2][0].piece.type = 3; combo3[rando][0] = NULL; combo3[rando][1] = NULL; combo3[rando][2] = NULL; cnt++; } if (cnt == 3 && combo3[rando][0] != NULL) { cubeArray[2][2][0].piece.color1 = combo3[rando][0]; cubeArray[2][2][0].piece.color2 = combo3[rando][1]; cubeArray[2][2][0].piece.color3 = combo3[rando][2]; cubeArray[2][2][0].piece.type = 3; combo3[rando][0] = NULL; combo3[rando][1] = NULL; combo3[rando][2] = NULL; cnt++; } if (cnt == 4 && combo3[rando][0] != NULL) { cubeArray[0][0][2].piece.color1 = combo3[rando][0]; cubeArray[0][0][2].piece.color2 = combo3[rando][1]; cubeArray[0][0][2].piece.color3 = combo3[rando][2]; cubeArray[0][0][2].piece.type = 3; combo3[rando][0] = NULL; combo3[rando][1] = NULL; combo3[rando][2] = NULL; cnt++; } if (cnt == 5 && combo3[rando][0] != NULL) { cubeArray[2][0][2].piece.color1 = combo3[rando][0]; cubeArray[2][0][2].piece.color2 = combo3[rando][1]; cubeArray[2][0][2].piece.color3 = combo3[rando][2]; cubeArray[2][0][2].piece.type = 3; combo3[rando][0] = NULL; combo3[rando][1] = NULL; combo3[rando][2] = NULL; cnt++; } if (cnt == 6 && combo3[rando][0] != NULL) { cubeArray[0][2][2].piece.color1 = combo3[rando][0]; cubeArray[0][2][2].piece.color2 = combo3[rando][1]; cubeArray[0][2][2].piece.color3 = combo3[rando][2]; cubeArray[0][2][2].piece.type = 3; combo3[rando][0] = NULL; combo3[rando][1] = NULL; combo3[rando][2] = NULL; cnt++; } if (cnt == 7 && combo3[rando][0] != NULL) { cubeArray[2][2][2].piece.color1 = combo3[rando][0]; cubeArray[2][2][2].piece.color2 = combo3[rando][1]; cubeArray[2][2][2].piece.color3 = combo3[rando][2]; cubeArray[2][2][2].piece.type = 3; combo3[rando][0] = NULL; combo3[rando][1] = NULL; combo3[rando][2] = NULL; cnt++; } } } void OrientCube(Cube cubeArray[3][3][3]) { //need to delete any info that was in the side information first for (int x = 0; x < 3; x++) { for (int y = 0; y < 3; y++) { for (int z = 0; z < 3; z++) { cubeArray[x][y][z].piece.back = NULL; cubeArray[x][y][z].piece.front = NULL; cubeArray[x][y][z].piece.up = NULL; cubeArray[x][y][z].piece.down = NULL; cubeArray[x][y][z].piece.left = NULL; cubeArray[x][y][z].piece.right = NULL; } } } for (int x = 0; x < 3; x++) { for (int y = 0; y < 3; y++) { for (int z = 0; z < 3; z++) { if (x == 0 && y == 0 && z == 0) { cubeArray[x][y][z].piece.left = cubeArray[x][y][z].piece.color1; //bc its basically upside down cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.color3; cubeArray[x][y][z].piece.down = cubeArray[x][y][z].piece.color2; } if (x == 0 && y == 1 && z == 0) { cubeArray[x][y][z].piece.left = cubeArray[x][y][z].piece.color1; cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.color2; } if (x == 0 && y == 2 && z == 0) { cubeArray[x][y][z].piece.left = cubeArray[x][y][z].piece.color1; cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.color2; cubeArray[x][y][z].piece.up = cubeArray[x][y][z].piece.color3; } if (x == 0 && y == 0 && z == 1) { cubeArray[x][y][z].piece.left = cubeArray[x][y][z].piece.color2; cubeArray[x][y][z].piece.down = cubeArray[x][y][z].piece.color1; } if (x == 0 && y == 1 && z == 1) { cubeArray[x][y][z].piece.left = cubeArray[x][y][z].piece.color1; } if (x == 0 && y == 2 && z == 1) { cubeArray[x][y][z].piece.left = cubeArray[x][y][z].piece.color1; cubeArray[x][y][z].piece.up = cubeArray[x][y][z].piece.color2; } if (x == 0 && y == 0 && z == 2) { cubeArray[x][y][z].piece.left = cubeArray[x][y][z].piece.color1; cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.color2; cubeArray[x][y][z].piece.down = cubeArray[x][y][z].piece.color3; } if (x == 0 && y == 1 && z == 2) { cubeArray[x][y][z].piece.left = cubeArray[x][y][z].piece.color1; cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.color2; } if (x == 0 && y == 2 && z == 2) { cubeArray[x][y][z].piece.left = cubeArray[x][y][z].piece.color1; cubeArray[x][y][z].piece.up = cubeArray[x][y][z].piece.color2; cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.color3; } if (x == 1 && y == 0 && z == 0) { cubeArray[x][y][z].piece.down = cubeArray[x][y][z].piece.color1; cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.color2; } if (x == 1 && y == 1 && z == 0) { cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.color1; } if (x == 1 && y == 2 && z == 0) { cubeArray[x][y][z].piece.up = cubeArray[x][y][z].piece.color1; cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.color2; } if (x == 1 && y == 0 && z == 1) { cubeArray[x][y][z].piece.down = cubeArray[x][y][z].piece.color1; //skipped one bc 1,1,1 is not used (center) } if (x == 1 && y == 2 && z == 1) { cubeArray[x][y][z].piece.up = cubeArray[x][y][z].piece.color1; } if (x == 1 && y == 0 && z == 2) { cubeArray[x][y][z].piece.down = cubeArray[x][y][z].piece.color1; cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.color2; } if (x == 1 && y == 1 && z == 2) { cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.color1; } if (x == 1 && y == 2 && z == 2) { cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.color1; cubeArray[x][y][z].piece.up = cubeArray[x][y][z].piece.color2; } if (x == 2 && y == 0 && z == 0) { cubeArray[x][y][z].piece.right = cubeArray[x][y][z].piece.color1; cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.color2; cubeArray[x][y][z].piece.down = cubeArray[x][y][z].piece.color3; } if (x == 2 && y == 1 && z == 0) { cubeArray[x][y][z].piece.right = cubeArray[x][y][z].piece.color1; cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.color2; } if (x == 2 && y == 2 && z == 0) { cubeArray[x][y][z].piece.up = cubeArray[x][y][z].piece.color1; cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.color2; cubeArray[x][y][z].piece.right = cubeArray[x][y][z].piece.color3; } if (x == 2 && y == 0 && z == 1) { cubeArray[x][y][z].piece.down = cubeArray[x][y][z].piece.color1; cubeArray[x][y][z].piece.right = cubeArray[x][y][z].piece.color2; } if (x == 2 && y == 1 && z == 1) { cubeArray[x][y][z].piece.right = cubeArray[x][y][z].piece.color1; } if (x == 2 && y == 2 && z == 1) { cubeArray[x][y][z].piece.up = cubeArray[x][y][z].piece.color1; cubeArray[x][y][z].piece.right = cubeArray[x][y][z].piece.color2; } if (x == 2 && y == 0 && z == 2) { cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.color1; cubeArray[x][y][z].piece.right = cubeArray[x][y][z].piece.color2; cubeArray[x][y][z].piece.down = cubeArray[x][y][z].piece.color3; } if (x == 2 && y == 1 && z == 2) { cubeArray[x][y][z].piece.right = cubeArray[x][y][z].piece.color1; cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.color2; } if (x == 2 && y == 2 && z == 2) { cubeArray[x][y][z].piece.right = cubeArray[x][y][z].piece.color1; cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.color2; cubeArray[x][y][z].piece.up = cubeArray[x][y][z].piece.color3; } } } } } void CubeDisplay(Cube cubeArray[3][3][3]) { HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); //for (int k = 1; k < 255; k++) //{ // // pick the colorattribute k you want // SetConsoleTextAttribute(hConsole, k); // cout << k << " I want to be nice today!" << endl; //} //top for (int z = 2; z > -1; z--) { cout << " "; for (int x = 0; x < 3; x++) { if (cubeArray[x][2][z].piece.up == 'R') { SetConsoleTextAttribute(hConsole, 12); } if (cubeArray[x][2][z].piece.up == 'O') { SetConsoleTextAttribute(hConsole, 13); } if (cubeArray[x][2][z].piece.up == 'B') { SetConsoleTextAttribute(hConsole, 9); } if (cubeArray[x][2][z].piece.up == 'Y') { SetConsoleTextAttribute(hConsole, 14); } if (cubeArray[x][2][z].piece.up == 'W') { SetConsoleTextAttribute(hConsole, 15); } if (cubeArray[x][2][z].piece.up == 'G'){ SetConsoleTextAttribute(hConsole, 10); } cout << '[' << cubeArray[x][2][z].piece.up << ']'; } cout << endl; } cout << endl; //left mid right for (int y = 2; y > -1; y--) { for (int z = 2; z > -1; z--) { if (cubeArray[0][y][z].piece.left == 'R') { SetConsoleTextAttribute(hConsole, 12); } if (cubeArray[0][y][z].piece.left == 'O') { SetConsoleTextAttribute(hConsole, 13); } if (cubeArray[0][y][z].piece.left == 'B') { SetConsoleTextAttribute(hConsole, 9); } if (cubeArray[0][y][z].piece.left == 'Y') { SetConsoleTextAttribute(hConsole, 14); } if (cubeArray[0][y][z].piece.left == 'W') { SetConsoleTextAttribute(hConsole, 15); } if (cubeArray[0][y][z].piece.left == 'G') { SetConsoleTextAttribute(hConsole, 10); } cout << '[' << cubeArray[0][y][z].piece.left << ']'; } cout << ' '; for (int x = 0; x < 3; x++) { if (cubeArray[x][y][0].piece.front == 'R') { SetConsoleTextAttribute(hConsole, 12); } if (cubeArray[x][y][0].piece.front == 'O') { SetConsoleTextAttribute(hConsole, 13); } if (cubeArray[x][y][0].piece.front == 'B') { SetConsoleTextAttribute(hConsole, 9); } if (cubeArray[x][y][0].piece.front == 'Y') { SetConsoleTextAttribute(hConsole, 14); } if (cubeArray[x][y][0].piece.front == 'W') { SetConsoleTextAttribute(hConsole, 15); } if (cubeArray[x][y][0].piece.front == 'G') { SetConsoleTextAttribute(hConsole, 10); } cout << '[' << cubeArray[x][y][0].piece.front << ']'; } cout << ' '; for (int z = 0; z < 3; z++) { if (cubeArray[2][y][z].piece.right == 'R') { SetConsoleTextAttribute(hConsole, 12); } if (cubeArray[2][y][z].piece.right == 'O') { SetConsoleTextAttribute(hConsole, 13); } if (cubeArray[2][y][z].piece.right == 'B') { SetConsoleTextAttribute(hConsole, 9); } if (cubeArray[2][y][z].piece.right == 'Y') { SetConsoleTextAttribute(hConsole, 14); } if (cubeArray[2][y][z].piece.right == 'W') { SetConsoleTextAttribute(hConsole, 15); } if (cubeArray[2][y][z].piece.right == 'G') { SetConsoleTextAttribute(hConsole, 10); } cout << '[' << cubeArray[2][y][z].piece.right << ']'; } cout << endl; } cout << endl; // so now the bottom for (int z = 0; z < 3; z++) { cout << " "; for (int x = 0; x < 3; x++) { if (cubeArray[x][0][z].piece.down == 'R') { SetConsoleTextAttribute(hConsole, 12); } if (cubeArray[x][0][z].piece.down == 'O') { SetConsoleTextAttribute(hConsole, 13); } if (cubeArray[x][0][z].piece.down == 'B') { SetConsoleTextAttribute(hConsole, 9); } if (cubeArray[x][0][z].piece.down == 'Y') { SetConsoleTextAttribute(hConsole, 14); } if (cubeArray[x][0][z].piece.down == 'W') { SetConsoleTextAttribute(hConsole, 15); } if (cubeArray[x][0][z].piece.down == 'G') { SetConsoleTextAttribute(hConsole, 10); } cout << '[' << cubeArray[x][0][z].piece.down << ']'; } cout << endl; } cout << endl; //back for (int x = 0; x < 3; x++) { cout << " "; for (int y = 0; y < 3; y++) { if (cubeArray[x][y][2].piece.back == 'R') { SetConsoleTextAttribute(hConsole, 12); } if (cubeArray[x][y][2].piece.back == 'O') { SetConsoleTextAttribute(hConsole, 13); } if (cubeArray[x][y][2].piece.back == 'B') { SetConsoleTextAttribute(hConsole, 9); } if (cubeArray[x][y][2].piece.back == 'Y') { SetConsoleTextAttribute(hConsole, 14); } if (cubeArray[x][y][2].piece.back == 'W') { SetConsoleTextAttribute(hConsole, 15); } if (cubeArray[x][y][2].piece.back == 'G') { SetConsoleTextAttribute(hConsole, 10); } cout << '[' << cubeArray[x][y][2].piece.back << ']'; } cout << endl; SetConsoleTextAttribute(hConsole, 15); //resets it back to white } } void SetType(Cube cubeArray[3][3][3]) { for (int x = 0; x < 3; x++) { // this should only need done once per cube bc these piece types won't change for (int y = 0; y < 3; y++) { for (int z = 0; z < 3; z++) { if ((x == 0 | x == 2) && (y == 0 | y == 2) && (z == 0 | z == 2)) { //corners cubeArray[x][y][z].piece.type = 3; } if ((x == 1 && y == 1 && (z == 0 | z == 2)) | ((x == 0 | x == 2) && y == 1 && z == 1) | (x == 1 && (y == 0 | y == 2) && z == 1)) { //center pieces cubeArray[x][y][z].piece.type = 1; } if (((x == 0 | x == 2) && y == 1 && (z == 0 | z == 3)) | (x == 1 && (y == 0 | y == 2) && (z == 0 | z == 2)) | ((x == 0 | x == 2) && (y == 0 | y == 2) && z == 1)) { cubeArray[x][y][z].piece.type = 2; //2 sided edge pieces } } } } } int main() { Cube cube; Cube cubeAry[3][3][3]; SetRandomColors(cubeAry); //cout << "made it out of SetRandomColor()" << endl; OrientCube(cubeAry); CubeDisplay(cubeAry); } Edited February 2, 2020 by markyrocks update Spoiler "I Believe array math to be potentially fatal, I may be dying from array math poisoning"
markyrocks Posted February 11, 2020 Author Posted February 11, 2020 So i Figured i'd update this not that anyone seems that interested. I'll be the first to admit that this program does have some unnecessary bloat but hindsight is always 2020. I just figured i'd share this. This rubix cube simulator actually works surprisingly well at this point. I've Implemented just about every movement imaginable. even against the protests of other people i spoke to about this. I included the ability to move the center around and rotate the entire cube 360 degrees and even flipping it upside down. I included the basic algorithms to solve the cube. I've solved it a few times now and it usually takes me between 10 to 20 min to solve using the algorithms. But ya as far as i can tell it operates exactly like a real cube. So if you want to copy this into your version of visual studio. Have a go at it. Spoiler expandcollapse popup#include <iostream> #include <time.h> #include <stdlib.h> #include <windows.h> using namespace std; class Cube { public: struct Piece { char right, left, up, down, front, back, color1, color2, color3; int type; }; Piece piece; }; /* Declarations..... */ void OrientRightBack(Cube cubeArray[3][3][3]); void OrientRightFront(Cube cubeArray[3][3][3]); void OrientLeftFront(Cube cubeArray[3][3][3]); void OrientLeftBack(Cube cubeArray[3][3][3]); void OrientTopRight(Cube cubeArray[3][3][3]); void OrientTopLeft(Cube cubeArray[3][3][3]); void OrientBottomRight(Cube cubeArray[3][3][3]); void OrientBottomLeft(Cube cubeArray[3][3][3]); void OrientBackLeft(Cube cubeArray[3][3][3]); void OrientBackRight(Cube cubeArray[3][3][3]); void OrientFrontLeft(Cube cubeArray[3][3][3]); void OrientFrontRight(Cube cubeArray[3][3][3]); void OrientFlipCube(Cube cubeArray[3][3][3]); void OrientRotateCubeRight(Cube cubeArray[3][3][3]); void SolveMiddleRight(Cube cubeArray[3][3][3]); void SolveMiddleLeft(Cube cubeArray[3][3][3]); void MoveMiddleFront(Cube cubeArray[3][3][3]); void MoveMiddleBack(Cube cubeArray[3][3][3]); void OrientMiddleBack(Cube cubeArray[3][3][3]); void MoveMiddleRight(Cube cubeArray[3][3][3]); void MoveMiddleLeft(Cube cubeArray[3][3][3]); void OrientMiddleRight(Cube cubeArray[3][3][3]); void SolveYellowCross(Cube cubeArray[3][3][3]); void SwapYellowEdges(Cube cubeArray[3][3][3]); void SwapYellowCorners(Cube cubeArray[3][3][3]); void OrientYellowCorners(Cube cubeArray[3][3][3]); void ResetCube(Cube cubeArray[3][3][3]); void MoveLeftBack(Cube cubeArray[3][3][3]); void MoveRightFront(Cube cubeArray[3][3][3]); void MoveBackRight(Cube cubeArray[3][3][3]); void MoveTopRight(Cube cubeArray[3][3][3]); /* END Declarations */ void SetRandomColors(Cube cubeArray[3][3][3]) { srand(time(0)); ResetCube(cubeArray); int rando = ((rand()) % 10) / 4; for (int x = 0; x < rando; x++) { MoveLeftBack(cubeArray); } rando = ((rand()) % 10) / 4; for (int x = 0; x < rando; x++) { MoveRightFront(cubeArray); } rando = ((rand()) % 10) / 4; for (int x = 0; x < rando; x++) { OrientYellowCorners(cubeArray); } rando = ((rand()) % 10) / 4; for (int x = 0; x < rando; x++) { MoveMiddleRight(cubeArray); } rando = ((rand()) % 10) / 4; for (int x = 0; x < rando; x++) { MoveBackRight(cubeArray); } rando = ((rand()) % 10) / 4; for (int x = 0; x < rando; x++) { SwapYellowCorners(cubeArray); } rando = ((rand()) % 10) / 4; for (int x = 0; x < rando; x++) { SolveMiddleRight(cubeArray); } rando = ((rand()) % 10) / 4; for (int x = 0; x < rando; x++) { OrientYellowCorners(cubeArray); } rando = ((rand()) % 10) / 4; for (int x = 0; x < rando; x++) { MoveTopRight(cubeArray); } rando = ((rand()) % 10) / 4; for (int x = 0; x < rando; x++) { MoveRightFront(cubeArray); } rando = ((rand()) % 10) / 4; for (int x = 0; x < rando; x++) { MoveTopRight(cubeArray); } rando = ((rand()) % 10) / 4; for (int x = 0; x < rando; x++) { OrientYellowCorners(cubeArray); } rando = ((rand()) % 10) / 4; for (int x = 0; x < rando; x++) { MoveMiddleBack(cubeArray); } rando = ((rand()) % 10) / 4; for (int x = 0; x < rando; x++) { MoveMiddleRight(cubeArray); } rando = ((rand()) % 10) / 4; for (int x = 0; x < rando; x++) { MoveBackRight(cubeArray); } rando = ((rand()) % 10) / 4; for (int x = 0; x < rando; x++) { SwapYellowCorners(cubeArray); } rando = ((rand()) % 10) / 4; for (int x = 0; x < rando; x++) { OrientYellowCorners(cubeArray); } // these combos probably need to be global in the future //char combo1[6]{ 'W','G','R','B','Y','O' }; //char combo2[12][2]{ {'W','B'},{'W','O'},{'W','G'},{'W','R'},{'Y','B'},{'Y','R'},{'Y','G'},{'Y','O'},{'B','R'},{'B','O'},{'O','G'},{'G','R'} }; //char combo3[8][3]{ {'R','B','W'},{'G','R','W'},{'B','R','Y'},{'R','G','Y'},{'B','O','W'},{'O','G','Y'},{'O','B','Y'},{'O','G','W'} }; //for (int z = 0; z < 3; z++) { // for (int y = 0; y < 3; y++) { // for (int x = 0; x < 3; x++) { // cubeArray[x][y][z].piece.front = NULL; // cubeArray[x][y][z].piece.back = NULL; // cubeArray[x][y][z].piece.right = NULL; // cubeArray[x][y][z].piece.left = NULL; // cubeArray[x][y][z].piece.up = NULL; // cubeArray[x][y][z].piece.down = NULL; // cubeArray[x][y][z].piece.color1 = NULL; // cubeArray[x][y][z].piece.color2 = NULL; // cubeArray[x][y][z].piece.color3 = NULL; // // } // } //} //for (int z = 0; z < 3; z++) { //for (int y = 0; y < 3; y++) { //for (int x = 0; x < 3; x++) { // if (x == 0 && y == 0 && z == 0) { // cubeArray[x][y][z].piece.color1 = combo3[1][0];//'G','R','W' // cubeArray[x][y][z].piece.color2 = combo3[1][2]; // cubeArray[x][y][z].piece.color3 = combo3[1][1]; // cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.color2; // cubeArray[x][y][z].piece.left = cubeArray[x][y][z].piece.color1; // cubeArray[x][y][z].piece.down = cubeArray[x][y][z].piece.color3; // } // if (x == 1 && y == 0 && z == 0) { // cubeArray[x][y][z].piece.color1 = combo2[3][0]; //w r // cubeArray[x][y][z].piece.color2 = combo2[3][1]; // cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.color1; // cubeArray[x][y][z].piece.down = cubeArray[x][y][z].piece.color2; // } // if (x == 2 && y == 0 && z == 0) { // cubeArray[x][y][z].piece.color1 = combo3[0][2]; // cubeArray[x][y][z].piece.color2 = combo3[0][1]; // cubeArray[x][y][z].piece.color3 = combo3[0][0]; // cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.color1; // cubeArray[x][y][z].piece.right = cubeArray[x][y][z].piece.color2; // cubeArray[x][y][z].piece.down = cubeArray[x][y][z].piece.color3; // } // if (x == 0 && y == 1 && z == 0) { // cubeArray[x][y][z].piece.color1 = combo2[2][1]; //w g // cubeArray[x][y][z].piece.color2 = combo2[2][0]; // cubeArray[x][y][z].piece.left = cubeArray[x][y][z].piece.color1; // cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.color2; // } // if (x == 1 && y == 1 && z == 0) { // cubeArray[x][y][z].piece.color1 = combo1[0]; // cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.color1; // } // if (x == 2 && y == 1 && z == 0) { // cubeArray[x][y][z].piece.color1 = combo2[0][0]; // cubeArray[x][y][z].piece.color2 = combo2[0][1]; // cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.color1; // cubeArray[x][y][z].piece.right = cubeArray[x][y][z].piece.color2; // } // if (x == 0 && y == 2 && z == 0) { // cubeArray[x][y][z].piece.color1 = combo3[7][1]; //'O','G','W' // cubeArray[x][y][z].piece.color2 = combo3[7][2]; // cubeArray[x][y][z].piece.color3 = combo3[7][0]; // cubeArray[x][y][z].piece.left = cubeArray[x][y][z].piece.color1; // cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.color2; // cubeArray[x][y][z].piece.up = cubeArray[x][y][z].piece.color3; // } // if (x == 1 && y == 2 && z == 0) { // cubeArray[x][y][z].piece.color1 = combo2[1][1]; //w o // cubeArray[x][y][z].piece.color2 = combo2[1][0]; // cubeArray[x][y][z].piece.up = cubeArray[x][y][z].piece.color1; // cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.color2; // } // if (x == 2 && y == 2 && z == 0) { // cubeArray[x][y][z].piece.color1 = combo3[4][2]; //'B','O','W' // cubeArray[x][y][z].piece.color2 = combo3[4][0]; // cubeArray[x][y][z].piece.color3 = combo3[4][1]; // cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.color1; // cubeArray[x][y][z].piece.right = cubeArray[x][y][z].piece.color2; // cubeArray[x][y][z].piece.up = cubeArray[x][y][z].piece.color3; // } // if (x == 0 && y == 0 && z == 1) { // cubeArray[x][y][z].piece.color1 = combo2[11][0]; //'G','R' // cubeArray[x][y][z].piece.color2 = combo2[11][1]; // cubeArray[x][y][z].piece.left = cubeArray[x][y][z].piece.color1; // cubeArray[x][y][z].piece.down = cubeArray[x][y][z].piece.color2; // } // if (x == 1 && y == 0 && z == 1) { // cubeArray[x][y][z].piece.color1 = combo1[2]; //r // cubeArray[x][y][z].piece.down = cubeArray[x][y][z].piece.color1; // // } // if (x == 2 && y == 0 && z == 1) { // cubeArray[x][y][z].piece.color1 = combo2[8][1]; //'B','R' // cubeArray[x][y][z].piece.color2 = combo2[8][0]; // cubeArray[x][y][z].piece.down = cubeArray[x][y][z].piece.color1; // cubeArray[x][y][z].piece.right = cubeArray[x][y][z].piece.color2; // } // if (x == 0 && y == 1 && z == 1) { // cubeArray[x][y][z].piece.color1 = combo1[1]; //g // cubeArray[x][y][z].piece.left = cubeArray[x][y][z].piece.color1; // } // if (x == 2 && y == 1 && z == 1) { // cubeArray[x][y][z].piece.color1 = combo1[3]; //b // cubeArray[x][y][z].piece.right = cubeArray[x][y][z].piece.color1; // } // if (x == 0 && y == 2 && z == 1) { // cubeArray[x][y][z].piece.color1 = combo2[10][1]; //'O','G' // cubeArray[x][y][z].piece.color2 = combo2[10][0]; // cubeArray[x][y][z].piece.left = cubeArray[x][y][z].piece.color1; // cubeArray[x][y][z].piece.up = cubeArray[x][y][z].piece.color2; // } // if (x == 1 && y == 2 && z == 1) { // cubeArray[x][y][z].piece.color1 = combo1[5]; //0 // cubeArray[x][y][z].piece.up = cubeArray[x][y][z].piece.color1; // } // if (x == 2 && y == 2 && z == 1) { // cubeArray[x][y][z].piece.color1 = combo2[9][0]; //'B','O' // cubeArray[x][y][z].piece.color2 = combo2[9][1]; // cubeArray[x][y][z].piece.right = cubeArray[x][y][z].piece.color1; // cubeArray[x][y][z].piece.up = cubeArray[x][y][z].piece.color2; // } // if (x == 0 && y == 0 && z == 2) { // cubeArray[x][y][z].piece.color1 = combo3[3][2]; //'R','G','Y' // cubeArray[x][y][z].piece.color2 = combo3[3][1]; // cubeArray[x][y][z].piece.color3 = combo3[3][0]; // cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.color1; // cubeArray[x][y][z].piece.left = cubeArray[x][y][z].piece.color2; // cubeArray[x][y][z].piece.down = cubeArray[x][y][z].piece.color3; // } // if (x == 1 && y == 0 && z == 2) { // cubeArray[x][y][z].piece.color1 = combo2[5][0]; //'Y','R' // cubeArray[x][y][z].piece.color2 = combo2[5][1]; // cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.color1; // cubeArray[x][y][z].piece.down = cubeArray[x][y][z].piece.color2; // } // if (x == 2 && y == 0 && z == 2) { // cubeArray[x][y][z].piece.color1 = combo3[2][0]; //'B','R','Y' // cubeArray[x][y][z].piece.color2 = combo3[2][2]; // cubeArray[x][y][z].piece.color3 = combo3[2][1]; // cubeArray[x][y][z].piece.right = cubeArray[x][y][z].piece.color1; // cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.color2; // cubeArray[x][y][z].piece.down = cubeArray[x][y][z].piece.color3; // } // if (x == 0 && y == 1 && z == 2) { // cubeArray[x][y][z].piece.color1 = combo2[6][1]; //'Y','G' // cubeArray[x][y][z].piece.color2 = combo2[6][0]; // cubeArray[x][y][z].piece.left = cubeArray[x][y][z].piece.color1; // cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.color2; // } // if (x == 1 && y == 1 && z == 2) { // cubeArray[x][y][z].piece.color1 = combo1[4]; //y // cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.color1; // } // if (x == 2 && y == 1 && z == 2) { // cubeArray[x][y][z].piece.color1 = combo2[4][1]; //'Y','B' // cubeArray[x][y][z].piece.color2 = combo2[4][0]; // cubeArray[x][y][z].piece.right = cubeArray[x][y][z].piece.color1; // cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.color2; // } // if (x == 0 && y == 2 && z == 2) { // cubeArray[x][y][z].piece.color1 = combo3[5][2]; //'O','G','Y' // cubeArray[x][y][z].piece.color2 = combo3[5][1]; // cubeArray[x][y][z].piece.color3 = combo3[5][0]; // cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.color1; // cubeArray[x][y][z].piece.left = cubeArray[x][y][z].piece.color2; // cubeArray[x][y][z].piece.up = cubeArray[x][y][z].piece.color3; // } // if (x == 1 && y == 2 && z == 2) { // cubeArray[x][y][z].piece.color1 = combo2[7][0]; //'Y','O' // cubeArray[x][y][z].piece.color2 = combo2[7][1]; // cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.color1; // cubeArray[x][y][z].piece.up = cubeArray[x][y][z].piece.color2; // } // if (x == 2 && y == 2 && z == 2) { // cubeArray[x][y][z].piece.color1 = combo3[6][1]; //'O','B','Y' // cubeArray[x][y][z].piece.color2 = combo3[6][2]; // cubeArray[x][y][z].piece.color3 = combo3[6][0]; // cubeArray[x][y][z].piece.right = cubeArray[x][y][z].piece.color1; // cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.color2; // cubeArray[x][y][z].piece.up = cubeArray[x][y][z].piece.color3; // } //} //} //} } void OrientCube(Cube cubeArray[3][3][3]) { //need to delete any info that was in the side information first for (int x = 0; x < 3; x++) { for (int y = 0; y < 3; y++) { for (int z = 0; z < 3; z++) { cubeArray[x][y][z].piece.back = NULL; cubeArray[x][y][z].piece.front = NULL; cubeArray[x][y][z].piece.up = NULL; cubeArray[x][y][z].piece.down = NULL; cubeArray[x][y][z].piece.left = NULL; cubeArray[x][y][z].piece.right = NULL; } } } for (int x = 0; x < 3; x++) { for (int y = 0; y < 3; y++) { for (int z = 0; z < 3; z++) { if (x == 0 && y == 0 && z == 0) { cubeArray[x][y][z].piece.left = cubeArray[x][y][z].piece.color1; //bc its basically upside down cubeArray[x][y][z].piece.down = cubeArray[x][y][z].piece.color2; cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.color3; } if (x == 0 && y == 1 && z == 0) { cubeArray[x][y][z].piece.left = cubeArray[x][y][z].piece.color1; cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.color2; } if (x == 0 && y == 2 && z == 0) { cubeArray[x][y][z].piece.left = cubeArray[x][y][z].piece.color1; cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.color2; cubeArray[x][y][z].piece.up = cubeArray[x][y][z].piece.color3; } if (x == 0 && y == 0 && z == 1) { cubeArray[x][y][z].piece.down = cubeArray[x][y][z].piece.color2; cubeArray[x][y][z].piece.left = cubeArray[x][y][z].piece.color1; } if (x == 0 && y == 1 && z == 1) { cubeArray[x][y][z].piece.left = cubeArray[x][y][z].piece.color1; } if (x == 0 && y == 2 && z == 1) { cubeArray[x][y][z].piece.left = cubeArray[x][y][z].piece.color1; cubeArray[x][y][z].piece.up = cubeArray[x][y][z].piece.color2; } if (x == 0 && y == 0 && z == 2) { cubeArray[x][y][z].piece.left = cubeArray[x][y][z].piece.color1; cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.color2; cubeArray[x][y][z].piece.down = cubeArray[x][y][z].piece.color3; } if (x == 0 && y == 1 && z == 2) { cubeArray[x][y][z].piece.left = cubeArray[x][y][z].piece.color1; cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.color2; } if (x == 0 && y == 2 && z == 2) { cubeArray[x][y][z].piece.left = cubeArray[x][y][z].piece.color1; cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.color3; cubeArray[x][y][z].piece.up = cubeArray[x][y][z].piece.color2; } if (x == 1 && y == 0 && z == 0) { cubeArray[x][y][z].piece.down = cubeArray[x][y][z].piece.color1; cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.color2; } if (x == 1 && y == 1 && z == 0) { cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.color1; } if (x == 1 && y == 2 && z == 0) { cubeArray[x][y][z].piece.up = cubeArray[x][y][z].piece.color1; cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.color2; } if (x == 1 && y == 0 && z == 1) { cubeArray[x][y][z].piece.down = cubeArray[x][y][z].piece.color1; //skipped one bc 1,1,1 is not used (center) } if (x == 1 && y == 2 && z == 1) { cubeArray[x][y][z].piece.up = cubeArray[x][y][z].piece.color1; } if (x == 1 && y == 0 && z == 2) { cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.color1; cubeArray[x][y][z].piece.down = cubeArray[x][y][z].piece.color2; } if (x == 1 && y == 1 && z == 2) { cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.color1; } if (x == 1 && y == 2 && z == 2) { cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.color1; cubeArray[x][y][z].piece.up = cubeArray[x][y][z].piece.color2; } if (x == 2 && y == 0 && z == 0) { cubeArray[x][y][z].piece.down = cubeArray[x][y][z].piece.color1; cubeArray[x][y][z].piece.right = cubeArray[x][y][z].piece.color2; cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.color3; //hmmmmmmm } if (x == 2 && y == 1 && z == 0) { cubeArray[x][y][z].piece.right = cubeArray[x][y][z].piece.color1; cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.color2; } if (x == 2 && y == 2 && z == 0) { cubeArray[x][y][z].piece.up = cubeArray[x][y][z].piece.color3; cubeArray[x][y][z].piece.right = cubeArray[x][y][z].piece.color2; cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.color1; } if (x == 2 && y == 0 && z == 1) { cubeArray[x][y][z].piece.right = cubeArray[x][y][z].piece.color1; cubeArray[x][y][z].piece.down = cubeArray[x][y][z].piece.color2; } if (x == 2 && y == 1 && z == 1) { cubeArray[x][y][z].piece.right = cubeArray[x][y][z].piece.color1; } if (x == 2 && y == 2 && z == 1) { cubeArray[x][y][z].piece.right = cubeArray[x][y][z].piece.color1; cubeArray[x][y][z].piece.up = cubeArray[x][y][z].piece.color2; } if (x == 2 && y == 0 && z == 2) { cubeArray[x][y][z].piece.right = cubeArray[x][y][z].piece.color2; cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.color1; cubeArray[x][y][z].piece.down = cubeArray[x][y][z].piece.color3; } if (x == 2 && y == 1 && z == 2) { cubeArray[x][y][z].piece.right = cubeArray[x][y][z].piece.color1; cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.color2; } if (x == 2 && y == 2 && z == 2) { cubeArray[x][y][z].piece.right = cubeArray[x][y][z].piece.color1; cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.color2; cubeArray[x][y][z].piece.up = cubeArray[x][y][z].piece.color3; } /* cout << "up " << cubeArray[x][y][z].piece.up << " down " << cubeArray[x][y][z].piece.down << " right " << cubeArray[x][y][z].piece.right; cout << " left " << cubeArray[x][y][z].piece.left << " back " << cubeArray[x][y][z].piece.back << " front " << cubeArray[x][y][z].piece.front; cout << endl;*/ } } } } void CubeDisplay(Cube cubeArray[3][3][3]) { HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); std::cout << endl; //for (int k = 1; k < 255; k++) //{ // // pick the colorattribute k you want // SetConsoleTextAttribute(hConsole, k); // cout << k << " I want to be nice today!" << endl; //} //top for (int z = 2; z > -1; z--) { cout << " "; for (int x = 0; x < 3; x++) { if (cubeArray[x][2][z].piece.up == 'R') { SetConsoleTextAttribute(hConsole, 12); } if (cubeArray[x][2][z].piece.up == 'O') { SetConsoleTextAttribute(hConsole, 13); } if (cubeArray[x][2][z].piece.up == 'B') { SetConsoleTextAttribute(hConsole, 9); } if (cubeArray[x][2][z].piece.up == 'Y') { SetConsoleTextAttribute(hConsole, 14); } if (cubeArray[x][2][z].piece.up == 'W') { SetConsoleTextAttribute(hConsole, 15); } if (cubeArray[x][2][z].piece.up == 'G'){ SetConsoleTextAttribute(hConsole, 10); } cout << '[' << cubeArray[x][2][z].piece.up << ']'; } cout << endl; } cout << endl; //left mid right for (int y = 2; y > -1; y--) { for (int z = 2; z > -1; z--) { if (cubeArray[0][y][z].piece.left == 'R') { SetConsoleTextAttribute(hConsole, 12); } if (cubeArray[0][y][z].piece.left == 'O') { SetConsoleTextAttribute(hConsole, 13); } if (cubeArray[0][y][z].piece.left == 'B') { SetConsoleTextAttribute(hConsole, 9); } if (cubeArray[0][y][z].piece.left == 'Y') { SetConsoleTextAttribute(hConsole, 14); } if (cubeArray[0][y][z].piece.left == 'W') { SetConsoleTextAttribute(hConsole, 15); } if (cubeArray[0][y][z].piece.left == 'G') { SetConsoleTextAttribute(hConsole, 10); } cout << '[' << cubeArray[0][y][z].piece.left << ']'; } cout << ' '; for (int x = 0; x < 3; x++) { if (cubeArray[x][y][0].piece.front == 'R') { SetConsoleTextAttribute(hConsole, 12); } if (cubeArray[x][y][0].piece.front == 'O') { SetConsoleTextAttribute(hConsole, 13); } if (cubeArray[x][y][0].piece.front == 'B') { SetConsoleTextAttribute(hConsole, 9); } if (cubeArray[x][y][0].piece.front == 'Y') { SetConsoleTextAttribute(hConsole, 14); } if (cubeArray[x][y][0].piece.front == 'W') { SetConsoleTextAttribute(hConsole, 15); } if (cubeArray[x][y][0].piece.front == 'G') { SetConsoleTextAttribute(hConsole, 10); } cout << '[' << cubeArray[x][y][0].piece.front << ']'; } cout << ' '; for (int z = 0; z < 3; z++) { if (cubeArray[2][y][z].piece.right == 'R') { SetConsoleTextAttribute(hConsole, 12); } if (cubeArray[2][y][z].piece.right == 'O') { SetConsoleTextAttribute(hConsole, 13); } if (cubeArray[2][y][z].piece.right == 'B') { SetConsoleTextAttribute(hConsole, 9); } if (cubeArray[2][y][z].piece.right == 'Y') { SetConsoleTextAttribute(hConsole, 14); } if (cubeArray[2][y][z].piece.right == 'W') { SetConsoleTextAttribute(hConsole, 15); } if (cubeArray[2][y][z].piece.right == 'G') { SetConsoleTextAttribute(hConsole, 10); } cout << '[' << cubeArray[2][y][z].piece.right << ']'; } cout << endl; } cout << endl; // so now the bottom for (int z = 0; z < 3; z++) { cout << " "; for (int x = 0; x < 3; x++) { if (cubeArray[x][0][z].piece.down == 'R') { SetConsoleTextAttribute(hConsole, 12); } if (cubeArray[x][0][z].piece.down == 'O') { SetConsoleTextAttribute(hConsole, 13); } if (cubeArray[x][0][z].piece.down == 'B') { SetConsoleTextAttribute(hConsole, 9); } if (cubeArray[x][0][z].piece.down == 'Y') { SetConsoleTextAttribute(hConsole, 14); } if (cubeArray[x][0][z].piece.down == 'W') { SetConsoleTextAttribute(hConsole, 15); } if (cubeArray[x][0][z].piece.down == 'G') { SetConsoleTextAttribute(hConsole, 10); } cout << '[' << cubeArray[x][0][z].piece.down << ']'; } cout << endl; } cout << endl; //back for (int y = 0; y < 3; y++) { cout << " "; for (int x = 0; x < 3; x++) { if (cubeArray[x][y][2].piece.back == 'R') { SetConsoleTextAttribute(hConsole, 12); } if (cubeArray[x][y][2].piece.back == 'O') { SetConsoleTextAttribute(hConsole, 13); } if (cubeArray[x][y][2].piece.back == 'B') { SetConsoleTextAttribute(hConsole, 9); } if (cubeArray[x][y][2].piece.back == 'Y') { SetConsoleTextAttribute(hConsole, 14); } if (cubeArray[x][y][2].piece.back == 'W') { SetConsoleTextAttribute(hConsole, 15); } if (cubeArray[x][y][2].piece.back == 'G') { SetConsoleTextAttribute(hConsole, 10); } cout << '[' << cubeArray[x][y][2].piece.back << ']'; } cout << endl; SetConsoleTextAttribute(hConsole, 15); //resets it back to white } } void SetType(Cube cubeArray[3][3][3]) { for (int x = 0; x < 3; x++) { // this should only need done once per cube bc these piece types won't change for (int y = 0; y < 3; y++) { for (int z = 0; z < 3; z++) { if ((x == 0 || x == 2) && (y == 0 || y == 2) && (z == 0 || z == 2)) { //corners cubeArray[x][y][z].piece.type = 3; } if ((x == 1 && y == 1 && (z == 0 || z == 2)) | ((x == 0 || x == 2) && y == 1 && z == 1) || (x == 1 && (y == 0 || y == 2) && z == 1)) { //center pieces cubeArray[x][y][z].piece.type = 1; } if (((x == 0 || x == 2) && y == 1 && (z == 0 || z == 3)) || (x == 1 && (y == 0 || y == 2) && (z == 0 || z == 2)) | ((x == 0 || x == 2) && (y == 0 || y == 2) && z == 1)) { cubeArray[x][y][z].piece.type = 2; //2 sided edge pieces } } } } } void MoveRightBack(Cube cubeArray[3][3][3]) { Cube temp[3][3][3]; for (int y = 0; y < 3; y++) { for (int z = 0; z < 3; z++) { temp[2][y][z] = cubeArray[2][y][z]; //copy } } int z = 0; for (int y = 2; y>-1; y--) { cubeArray[2][y][2] = temp[2][2][z]; z+=1; } int y = 2; for (int z = 2; z > -1; z--) { cubeArray[2][0][z] = temp[2][y][2]; y--; } y = 0; for (int z = 2; z > -1; z--) { cubeArray[2][y][0] = temp[2][0][z]; y++; } y = 0; for (int z = 0; z<3; z++) { cubeArray[2][2][z] = temp[2][y][0]; y++; } OrientRightBack(cubeArray); } void OrientRightBack(Cube cubeArray[3][3][3]) { for (int y = 0; y < 3; y++) { for (int z = 0; z < 3; z++) { if (y == 0 && z == 0) { cubeArray[2][y][z].piece.front = cubeArray[2][y][z].piece.down; cubeArray[2][y][z].piece.down = cubeArray[2][y][z].piece.back; cubeArray[2][y][z].piece.back = NULL; } if (y == 1 && z == 0) { cubeArray[2][y][z].piece.front = cubeArray[2][y][z].piece.down; cubeArray[2][y][z].piece.down = NULL; } if (y == 2 && z == 0) { cubeArray[2][y][z].piece.up = cubeArray[2][y][z].piece.front; cubeArray[2][y][z].piece.front = cubeArray[2][y][z].piece.down; cubeArray[2][y][z].piece.down = NULL; } if (y == 0 && z == 1) { cubeArray[2][y][z].piece.down = cubeArray[2][y][z].piece.back; cubeArray[2][y][z].piece.back = NULL; } if (y == 2 && z == 1) { cubeArray[2][y][z].piece.up = cubeArray[2][y][z].piece.front; cubeArray[2][y][z].piece.front = NULL; } if (y == 0 && z == 2) { cubeArray[2][y][z].piece.down = cubeArray[2][y][z].piece.back; cubeArray[2][y][z].piece.back = cubeArray[2][y][z].piece.up; cubeArray[2][y][z].piece.up = NULL; } if (y == 1 && z == 2) { cubeArray[2][y][z].piece.back = cubeArray[2][y][z].piece.up; cubeArray[2][y][z].piece.up = NULL; } if (y == 2 && z == 2) { cubeArray[2][y][z].piece.back = cubeArray[2][y][z].piece.up; cubeArray[2][y][z].piece.up = cubeArray[2][y][z].piece.front; cubeArray[2][y][z].piece.front = NULL; } } } } void MoveRightFront(Cube cubeArray[3][3][3]) { Cube temp[3][3][3]; // this just copies the current cube to a temp for (int y = 0; y < 3; y++) { for (int z = 0; z < 3; z++) { temp[2][y][z] = cubeArray[2][y][z]; } } int z = 2; for (int y = 2; y > -1; y--) { cubeArray[2][y][0] = temp[2][2][z]; //moves top to front z--; } int y = 0; for (int z = 2; z > -1; z--) { cubeArray[2][2][z] = temp[2][y][2]; //back to top y++; } y = 2; for (int z = 0; z<3; z++) { cubeArray[2][0][z] = temp[2][y][0]; //front to bottom y--; } y = 0; for (int z = 0; z < 3; z++) { cubeArray[2][y][2] = temp[2][0][z]; //bottom to back y++; } OrientRightFront(cubeArray); } void OrientRightFront(Cube cubeArray[3][3][3]) { for (int y = 0; y < 3; y++) { for (int z = 0; z < 3; z++) { if (y == 0 && z == 0) { cubeArray[2][y][z].piece.down = cubeArray[2][y][z].piece.front; cubeArray[2][y][z].piece.front = cubeArray[2][y][z].piece.up; cubeArray[2][y][z].piece.up = NULL; } if (y == 1 && z == 0) { cubeArray[2][y][z].piece.front = cubeArray[2][y][z].piece.up; cubeArray[2][y][z].piece.up = NULL; } if (y == 2 && z == 0) { cubeArray[2][y][z].piece.front = cubeArray[2][y][z].piece.up; cubeArray[2][y][z].piece.up = cubeArray[2][y][z].piece.back; cubeArray[2][y][z].piece.back = NULL; } if (y == 0 && z == 1) { cubeArray[2][y][z].piece.down = cubeArray[2][y][z].piece.front; cubeArray[2][y][z].piece.front = NULL; } if (y == 2 && z == 1) { cubeArray[2][y][z].piece.up = cubeArray[2][y][z].piece.back; cubeArray[2][y][z].piece.back = NULL; } if (y == 0 && z == 2) { cubeArray[2][y][z].piece.back = cubeArray[2][y][z].piece.down; cubeArray[2][y][z].piece.down = cubeArray[2][y][z].piece.front; cubeArray[2][y][z].piece.front = NULL; } if (y == 1 && z == 2) { cubeArray[2][y][z].piece.back = cubeArray[2][y][z].piece.down; cubeArray[2][y][z].piece.down = NULL; } if (y == 2 && z == 2) { cubeArray[2][y][z].piece.up = cubeArray[2][y][z].piece.back; cubeArray[2][y][z].piece.back = cubeArray[2][y][z].piece.down; cubeArray[2][y][z].piece.down = NULL; } } } } void MoveLeftBack(Cube cubeArray[3][3][3]) { Cube temp[3][3][3]; // this just copies the current cube to a temp for (int y = 0; y < 3; y++) { for (int z = 0; z < 3; z++) { temp[0][y][z] = cubeArray[0][y][z]; } } int z = 0; for (int y = 2; y > -1; y--) { cubeArray[0][y][2] = temp[0][2][z]; z += 1; } int y = 2; for (int z = 2; z > -1; z--) { cubeArray[0][0][z] = temp[0][y][2]; y--; } y = 0; for (int z = 2; z > -1; z--) { cubeArray[0][y][0] = temp[0][0][z]; y++; } y = 0; for (int z = 0; z < 3; z++) { cubeArray[0][2][z] = temp[0][y][0]; y++; } OrientLeftBack(cubeArray); } void OrientLeftBack(Cube cubeArray[3][3][3]) { for (int y = 0; y < 3; y++) { for (int z = 0; z < 3; z++) { if (y == 0 && z == 0) { cubeArray[0][y][z].piece.front = cubeArray[0][y][z].piece.down; cubeArray[0][y][z].piece.down = cubeArray[0][y][z].piece.back; cubeArray[0][y][z].piece.back = NULL; } if (y == 1 && z == 0) { cubeArray[0][y][z].piece.front = cubeArray[0][y][z].piece.down; cubeArray[0][y][z].piece.down = NULL; } if (y == 2 && z == 0) { cubeArray[0][y][z].piece.up = cubeArray[0][y][z].piece.front; cubeArray[0][y][z].piece.front = cubeArray[0][y][z].piece.down; cubeArray[0][y][z].piece.down = NULL; } if (y == 0 && z == 1) { cubeArray[0][y][z].piece.down = cubeArray[0][y][z].piece.back; cubeArray[0][y][z].piece.back = NULL; } if (y == 2 && z == 1) { cubeArray[0][y][z].piece.up = cubeArray[0][y][z].piece.front; cubeArray[0][y][z].piece.front = NULL; } if (y == 0 && z == 2) { cubeArray[0][y][z].piece.down = cubeArray[0][y][z].piece.back; cubeArray[0][y][z].piece.back = cubeArray[0][y][z].piece.up; cubeArray[0][y][z].piece.up = NULL; } if (y == 1 && z == 2) { cubeArray[0][y][z].piece.back = cubeArray[0][y][z].piece.up; cubeArray[0][y][z].piece.up = NULL; } if (y == 2 && z == 2) { cubeArray[0][y][z].piece.back = cubeArray[0][y][z].piece.up; cubeArray[0][y][z].piece.up = cubeArray[0][y][z].piece.front; cubeArray[0][y][z].piece.front = NULL; } } } } void MoveLeftFront(Cube cubeArray[3][3][3]) { Cube temp[3][3][3]; // this just copies the current cube to a temp for (int y = 0; y < 3; y++) { for (int z = 0; z < 3; z++) { temp[0][y][z] = cubeArray[0][y][z]; } } int z = 2; for (int y = 2; y > -1; y--) { cubeArray[0][y][0] = temp[0][2][z]; //moves top to front z--; } int y = 0; for (int z = 2; z > -1; z--) { cubeArray[0][2][z] = temp[0][y][2]; //back to top y++; } y = 2; for (int z = 0; z < 3; z++) { cubeArray[0][0][z] = temp[0][y][0]; //front to bottom y--; } y = 0; for (int z = 0; z < 3; z++) { cubeArray[0][y][2] = temp[0][0][z]; //bottom to back y++; } OrientLeftFront(cubeArray); } void OrientLeftFront(Cube cubeArray[3][3][3]) { for (int y = 0; y < 3; y++) { for (int z = 0; z < 3; z++) { if (y == 0 && z == 0) { cubeArray[0][y][z].piece.down = cubeArray[0][y][z].piece.front; cubeArray[0][y][z].piece.front = cubeArray[0][y][z].piece.up; cubeArray[0][y][z].piece.up = NULL; } if (y == 1 && z == 0) { cubeArray[0][y][z].piece.front = cubeArray[0][y][z].piece.up; cubeArray[0][y][z].piece.up = NULL; } if (y == 2 && z == 0) { cubeArray[0][y][z].piece.front = cubeArray[0][y][z].piece.up; cubeArray[0][y][z].piece.up = cubeArray[0][y][z].piece.back; cubeArray[0][y][z].piece.back = NULL; } if (y == 0 && z == 1) { cubeArray[0][y][z].piece.down = cubeArray[0][y][z].piece.front; cubeArray[0][y][z].piece.front = NULL; } if (y == 2 && z == 1) { cubeArray[0][y][z].piece.up = cubeArray[0][y][z].piece.back; cubeArray[0][y][z].piece.back = NULL; } if (y == 0 && z == 2) { cubeArray[0][y][z].piece.back = cubeArray[0][y][z].piece.down; cubeArray[0][y][z].piece.down = cubeArray[0][y][z].piece.front; cubeArray[0][y][z].piece.front = NULL; } if (y == 1 && z == 2) { cubeArray[0][y][z].piece.back = cubeArray[0][y][z].piece.down; cubeArray[0][y][z].piece.down = NULL; } if (y == 2 && z == 2) { cubeArray[0][y][z].piece.up = cubeArray[0][y][z].piece.back; cubeArray[0][y][z].piece.back = cubeArray[0][y][z].piece.down; cubeArray[0][y][z].piece.down = NULL; } } } } void MoveFrontRight(Cube cubeArray[3][3][3]) { Cube temp[3][3][3]; // this just copies the current cube to a temp for (int x = 0; x < 3; x++) { for (int y = 0; y < 3; y++) { temp[x][y][0] = cubeArray[x][y][0]; } } int x = 0; for (int y = 2; y > -1; y--) { cubeArray[2][y][0] = temp[x][2][0]; //moves top to right x++; } int y = 2; for (int x = 2; x > -1; x--) { cubeArray[x][0][0] = temp[2][y][0]; //right to down y--; } x = 2; for (int y = 0; y < 3; y++) { cubeArray[0][y][0] = temp[x][0][0]; //down to left x--; } y = 0; for (int x = 0; x < 3; x++) { cubeArray[x][2][0] = temp[0][y][0]; //left to top y++; } OrientFrontRight(cubeArray); } void OrientFrontRight(Cube cubeArray[3][3][3]) { for (int y = 0; y < 3; y++) { for (int x = 0; x < 3; x++) { if (x == 0 && y == 0) { cubeArray[x][y][0].piece.left = cubeArray[x][y][0].piece.down; cubeArray[x][y][0].piece.down = cubeArray[x][y][0].piece.right; cubeArray[x][y][0].piece.right = NULL; } if (x == 0 && y == 1) { cubeArray[x][y][0].piece.left = cubeArray[x][y][0].piece.down; cubeArray[x][y][0].piece.down = NULL; } if (x == 0 && y == 2) { cubeArray[x][y][0].piece.up = cubeArray[x][y][0].piece.left; cubeArray[x][y][0].piece.left = cubeArray[x][y][0].piece.down; cubeArray[x][y][0].piece.down = NULL; } if (x == 1 && y == 0) { cubeArray[x][y][0].piece.down = cubeArray[x][y][0].piece.right; cubeArray[x][y][0].piece.right = NULL; } if (x == 1 && y == 2) { cubeArray[x][y][0].piece.up = cubeArray[x][y][0].piece.left; //skip 1,1 bc its the middle piece cubeArray[x][y][0].piece.left = NULL; } if (x == 2 && y == 0) { cubeArray[x][y][0].piece.down = cubeArray[x][y][0].piece.right; cubeArray[x][y][0].piece.right = cubeArray[x][y][0].piece.up; cubeArray[x][y][0].piece.up = NULL; } if (x == 2 && y == 1) { cubeArray[x][y][0].piece.right = cubeArray[x][y][0].piece.up; cubeArray[x][y][0].piece.up = NULL; } if (x == 2 && y == 2) { cubeArray[x][y][0].piece.right = cubeArray[x][y][0].piece.up; cubeArray[x][y][0].piece.up = cubeArray[x][y][0].piece.left; cubeArray[x][y][0].piece.left = NULL; } } } } void MoveFrontLeft(Cube cubeArray[3][3][3]) { Cube temp[3][3][3]; // this just copies the current cube to a temp for (int x = 0; x < 3; x++) { for (int y = 0; y < 3; y++) { temp[x][y][0] = cubeArray[x][y][0]; } } int x = 2; for (int y = 2; y > -1; y--) { cubeArray[0][y][0] = temp[x][2][0]; //moves top to left x--; } int y = 2; for (int x = 0; x < 3; x++) { cubeArray[x][0][0] = temp[0][y][0]; //left to down y--; } x = 0; for (int y = 0; y < 3; y++) { cubeArray[2][y][0] = temp[x][0][0]; //down to right x++; } y = 0; for (int x = 2; x > -1; x--) { cubeArray[x][2][0] = temp[2][y][0]; //right to top y++; } OrientFrontLeft(cubeArray); } void OrientFrontLeft(Cube cubeArray[3][3][3]) { for (int y = 0; y < 3; y++) { for (int x = 0; x < 3; x++) { if (x == 0 && y == 0) { cubeArray[x][y][0].piece.down = cubeArray[x][y][0].piece.left; cubeArray[x][y][0].piece.left = cubeArray[x][y][0].piece.up; cubeArray[x][y][0].piece.up = NULL; } if (x == 0 && y == 1) { cubeArray[x][y][0].piece.left = cubeArray[x][y][0].piece.up; cubeArray[x][y][0].piece.up = NULL; } if (x == 0 && y == 2) { cubeArray[x][y][0].piece.left = cubeArray[x][y][0].piece.up; cubeArray[x][y][0].piece.up = cubeArray[x][y][0].piece.right; cubeArray[x][y][0].piece.right = NULL; } if (x == 1 && y == 0) { cubeArray[x][y][0].piece.down = cubeArray[x][y][0].piece.left; cubeArray[x][y][0].piece.left = NULL; } if (x == 1 && y == 2) { cubeArray[x][y][0].piece.up = cubeArray[x][y][0].piece.right; //skip 1,1 bc its the middle piece cubeArray[x][y][0].piece.right = NULL; } if (x == 2 && y == 0) { cubeArray[x][y][0].piece.right = cubeArray[x][y][0].piece.down; cubeArray[x][y][0].piece.down = cubeArray[x][y][0].piece.left; cubeArray[x][y][0].piece.left = NULL; } if (x == 2 && y == 1) { cubeArray[x][y][0].piece.right = cubeArray[x][y][0].piece.down; cubeArray[x][y][0].piece.down = NULL; } if (x == 2 && y == 2) { cubeArray[x][y][0].piece.up = cubeArray[x][y][0].piece.right; cubeArray[x][y][0].piece.right = cubeArray[x][y][0].piece.down; cubeArray[x][y][0].piece.down = NULL; } } } } void MoveBackRight(Cube cubeArray[3][3][3]) { Cube temp[3][3][3]; // this just copies the current cube to a temp for (int x = 0; x < 3; x++) { for (int y = 0; y < 3; y++) { temp[x][y][2] = cubeArray[x][y][2]; } } int x = 0; for (int y = 2; y > -1; y--) { cubeArray[2][y][2] = temp[x][2][2]; //moves top to right x++; } int y = 2; for (int x = 2; x > -1; x--) { cubeArray[x][0][2] = temp[2][y][2]; //right to down y--; } x = 2; for (int y = 0; y < 3; y++) { cubeArray[0][y][2] = temp[x][0][2]; //down to left x--; } y = 0; for (int x = 0; x < 3; x++) { cubeArray[x][2][2] = temp[0][y][2]; //left to top y++; } OrientBackRight(cubeArray); } void OrientBackRight(Cube cubeArray[3][3][3]) { for (int y = 0; y < 3; y++) { for (int x = 0; x < 3; x++) { if (x == 0 && y == 0) { cubeArray[x][y][2].piece.left = cubeArray[x][y][2].piece.down; cubeArray[x][y][2].piece.down = cubeArray[x][y][2].piece.right; cubeArray[x][y][2].piece.right = NULL; } if (x == 0 && y == 1) { cubeArray[x][y][2].piece.left = cubeArray[x][y][2].piece.down; cubeArray[x][y][2].piece.down = NULL; } if (x == 0 && y == 2) { cubeArray[x][y][2].piece.up = cubeArray[x][y][2].piece.left; cubeArray[x][y][2].piece.left = cubeArray[x][y][2].piece.down; cubeArray[x][y][2].piece.down = NULL; } if (x == 1 && y == 0) { cubeArray[x][y][2].piece.down = cubeArray[x][y][2].piece.right; cubeArray[x][y][2].piece.right = NULL; } if (x == 1 && y == 2) { cubeArray[x][y][2].piece.up = cubeArray[x][y][2].piece.left; //skip 1,1 bc its the middle piece cubeArray[x][y][2].piece.left = NULL; } if (x == 2 && y == 0) { cubeArray[x][y][2].piece.down = cubeArray[x][y][2].piece.right; cubeArray[x][y][2].piece.right = cubeArray[x][y][2].piece.up; cubeArray[x][y][2].piece.up = NULL; } if (x == 2 && y == 1) { cubeArray[x][y][2].piece.right = cubeArray[x][y][2].piece.up; cubeArray[x][y][2].piece.up = NULL; } if (x == 2 && y == 2) { cubeArray[x][y][2].piece.right = cubeArray[x][y][2].piece.up; cubeArray[x][y][2].piece.up = cubeArray[x][y][2].piece.left; cubeArray[x][y][2].piece.left = NULL; } } } } void MoveBackLeft(Cube cubeArray[3][3][3]) { Cube temp[3][3][3]; // this just copies the current cube to a temp for (int x = 0; x < 3; x++) { for (int y = 0; y < 3; y++) { temp[x][y][2] = cubeArray[x][y][2]; } } int x = 2; for (int y = 2; y > -1; y--) { cubeArray[0][y][2] = temp[x][2][2]; //moves top to left x--; } int y = 2; for (int x = 0; x < 3; x++) { cubeArray[x][0][2] = temp[0][y][2]; //left to down y--; } x = 0; for (int y = 0; y < 3; y++) { cubeArray[2][y][2] = temp[x][0][2]; //down to right x++; } y = 0; for (int x = 2; x > -1; x--) { cubeArray[x][2][2] = temp[2][y][2]; //right to top y++; } OrientBackLeft(cubeArray); } void OrientBackLeft(Cube cubeArray[3][3][3]) { for (int y = 0; y < 3; y++) { for (int x = 0; x < 3; x++) { if (x == 0 && y == 0) { cubeArray[x][y][2].piece.down = cubeArray[x][y][2].piece.left; cubeArray[x][y][2].piece.left = cubeArray[x][y][2].piece.up; cubeArray[x][y][2].piece.up = NULL; } if (x == 0 && y == 1) { cubeArray[x][y][2].piece.left = cubeArray[x][y][2].piece.up; cubeArray[x][y][2].piece.up = NULL; } if (x == 0 && y == 2) { cubeArray[x][y][2].piece.left = cubeArray[x][y][2].piece.up; cubeArray[x][y][2].piece.up = cubeArray[x][y][2].piece.right; cubeArray[x][y][2].piece.right = NULL; } if (x == 1 && y == 0) { cubeArray[x][y][2].piece.down = cubeArray[x][y][2].piece.left; cubeArray[x][y][2].piece.left = NULL; } if (x == 1 && y == 2) { cubeArray[x][y][2].piece.up = cubeArray[x][y][2].piece.right; //skip 1,1 bc its the middle piece cubeArray[x][y][2].piece.right = NULL; } if (x == 2 && y == 0) { cubeArray[x][y][2].piece.right = cubeArray[x][y][2].piece.down; cubeArray[x][y][2].piece.down = cubeArray[x][y][2].piece.left; cubeArray[x][y][2].piece.left = NULL; } if (x == 2 && y == 1) { cubeArray[x][y][2].piece.right = cubeArray[x][y][2].piece.down; cubeArray[x][y][2].piece.down = NULL; } if (x == 2 && y == 2) { cubeArray[x][y][2].piece.up = cubeArray[x][y][2].piece.right; cubeArray[x][y][2].piece.right = cubeArray[x][y][2].piece.down; cubeArray[x][y][2].piece.down = NULL; } } } } void MoveTopRight(Cube cubeArray[3][3][3]) { Cube temp[3][3][3]; // this just copies the current cube to a temp for (int x = 0; x < 3; x++) { for (int z = 0; z < 3; z++) { temp[x][2][z] = cubeArray[x][2][z]; } } int x = 0; for (int z = 0; z < 3; z++) { cubeArray[2][2][z] = temp[x][2][0]; //front to right x++; } int z = 0; for (int x = 2; x > -1; x--) { cubeArray[x][2][2] = temp[2][2][z]; //right to back z++; } x = 2; for (int z = 2; z >-1; z--) { cubeArray[0][2][z] = temp[x][2][2]; //back to left x--; } z = 2; for (int x = 0; x < 3; x++) { cubeArray[x][2][0] = temp[0][2][z]; //left to front z--; } OrientTopRight(cubeArray); } void OrientTopRight(Cube cubeArray[3][3][3]) { int y = 2; for (int z = 0; z < 3; z++) { for (int x = 0; x < 3; x++) { if (x == 0 && z == 0) { cubeArray[x][2][z].piece.front = cubeArray[x][2][z].piece.left; cubeArray[x][2][z].piece.left = cubeArray[x][2][z].piece.back; cubeArray[x][2][z].piece.back = NULL; } if (x == 0 && z == 1) { cubeArray[x][y][z].piece.left = cubeArray[x][y][z].piece.back; cubeArray[x][y][z].piece.back = NULL; } if (x == 0 && z == 2) { cubeArray[x][y][z].piece.left = cubeArray[x][y][z].piece.back; cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.right; cubeArray[x][y][z].piece.right = NULL; } if (x == 1 && z == 0) { cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.left; cubeArray[x][y][z].piece.left = NULL; } if (x == 1 && z == 2) { cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.right; //skip 1,1 bc its the middle piece cubeArray[x][y][z].piece.right = NULL; } if (x == 2 && z == 0) { cubeArray[x][y][z].piece.right = cubeArray[x][y][z].piece.front; cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.left; cubeArray[x][y][z].piece.left = NULL; } if (x == 2 && z == 1) { cubeArray[x][y][z].piece.right = cubeArray[x][y][z].piece.front; cubeArray[x][y][z].piece.front = NULL; } if (x == 2 && z == 2) { cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.right; cubeArray[x][y][z].piece.right = cubeArray[x][y][z].piece.front; cubeArray[x][y][z].piece.front = NULL; } } } } void MoveTopLeft(Cube cubeArray[3][3][3]) { Cube temp[3][3][3]; // this just copies the current cube to a temp for (int x = 0; x < 3; x++) { for (int z = 0; z < 3; z++) { temp[x][2][z] = cubeArray[x][2][z]; } } int x = 2; for (int z = 0; z < 3; z++) { cubeArray[0][2][z] = temp[x][2][0]; //front to left x--; } int z = 0; for (int x = 0; x < 3; x++) { cubeArray[x][2][2] = temp[0][2][z]; //left to back z++; } x = 0; for (int z = 2; z > -1; z--) { cubeArray[2][2][z] = temp[x][2][2]; //back to right x++; } z = 2; for (int x = 2; x > -1; x--) { cubeArray[x][2][0] = temp[2][2][z]; //right to front z--; } OrientTopLeft(cubeArray); } void OrientTopLeft(Cube cubeArray[3][3][3]) { int y = 2; for (int z = 0; z < 3; z++) { for (int x = 0; x < 3; x++) { if (x == 0 && z == 0) { cubeArray[x][y][z].piece.left = cubeArray[x][y][z].piece.front; cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.right; cubeArray[x][y][z].piece.right = NULL; } if (x == 0 && z == 1) { cubeArray[x][y][z].piece.left = cubeArray[x][y][z].piece.front; cubeArray[x][y][z].piece.front = NULL; } if (x == 0 && z == 2) { cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.left; cubeArray[x][y][z].piece.left = cubeArray[x][y][z].piece.front; cubeArray[x][y][z].piece.front = NULL; } if (x == 1 && z == 0) { cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.right; cubeArray[x][y][z].piece.right = NULL; } if (x == 1 && z == 2) { cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.left; //skip 1,1 bc its the middle piece cubeArray[x][y][z].piece.left = NULL; } if (x == 2 && z == 0) { cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.right; cubeArray[x][y][z].piece.right = cubeArray[x][y][z].piece.back; cubeArray[x][y][z].piece.back = NULL; } if (x == 2 && z == 1) { cubeArray[x][y][z].piece.right = cubeArray[x][y][z].piece.back; cubeArray[x][y][z].piece.back = NULL; } if (x == 2 && z == 2) { cubeArray[x][y][z].piece.right = cubeArray[x][y][z].piece.back; cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.left; cubeArray[x][y][z].piece.left = NULL; } } } } void MoveBottomRight(Cube cubeArray[3][3][3]) { Cube temp[3][3][3]; // this just copies the current cube to a temp for (int x = 0; x < 3; x++) { for (int z = 0; z < 3; z++) { temp[x][0][z] = cubeArray[x][0][z]; } } int x = 0; for (int z = 0; z < 3; z++) { cubeArray[2][0][z] = temp[x][0][0]; //front to right x++; } int z = 0; for (int x = 2; x > -1; x--) { cubeArray[x][0][2] = temp[2][0][z]; //right to back z++; } x = 2; for (int z = 2; z > -1; z--) { cubeArray[0][0][z] = temp[x][0][2]; //back to left x--; } z = 2; for (int x = 0; x < 3; x++) { cubeArray[x][0][0] = temp[0][0][z]; //left to front z--; } OrientBottomRight(cubeArray); } void OrientBottomRight(Cube cubeArray[3][3][3]) { int y = 0; for (int z = 0; z < 3; z++) { for (int x = 0; x < 3; x++) { if (x == 0 && z == 0) { cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.left; cubeArray[x][y][z].piece.left = cubeArray[x][y][z].piece.back; cubeArray[x][y][z].piece.back = NULL; } if (x == 0 && z == 1) { cubeArray[x][y][z].piece.left = cubeArray[x][y][z].piece.back; cubeArray[x][y][z].piece.back = NULL; } if (x == 0 && z == 2) { cubeArray[x][y][z].piece.left = cubeArray[x][y][z].piece.back; cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.right; cubeArray[x][y][z].piece.right = NULL; } if (x == 1 && z == 0) { cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.left; cubeArray[x][y][z].piece.left = NULL; } if (x == 1 && z == 2) { cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.right; //skip 1,1 bc its the middle piece cubeArray[x][y][z].piece.right = NULL; } if (x == 2 && z == 0) { cubeArray[x][y][z].piece.right = cubeArray[x][y][z].piece.front; cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.left; cubeArray[x][y][z].piece.left = NULL; } if (x == 2 && z == 1) { cubeArray[x][y][z].piece.right = cubeArray[x][y][z].piece.front; cubeArray[x][y][z].piece.front = NULL; } if (x == 2 && z == 2) { cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.right; cubeArray[x][y][z].piece.right = cubeArray[x][y][z].piece.front; cubeArray[x][y][z].piece.front = NULL; } } } } void MoveBottomLeft(Cube cubeArray[3][3][3]) { Cube temp[3][3][3]; // this just copies the current cube to a temp for (int x = 0; x < 3; x++) { for (int z = 0; z < 3; z++) { temp[x][0][z] = cubeArray[x][0][z]; } } int x = 2; for (int z = 0; z < 3; z++) { cubeArray[0][0][z] = temp[x][0][0]; //front to left x--; } int z = 0; for (int x = 0; x < 3; x++) { cubeArray[x][0][2] = temp[0][0][z]; //left to back z++; } x = 0; for (int z = 2; z > -1; z--) { cubeArray[2][0][z] = temp[x][0][2]; //back to right x++; } z = 2; for (int x = 2; x > -1; x--) { cubeArray[x][0][0] = temp[2][0][z]; //right to front z--; } OrientBottomLeft(cubeArray); } void OrientBottomLeft(Cube cubeArray[3][3][3]) { int y = 0; for (int z = 0; z < 3; z++) { for (int x = 0; x < 3; x++) { if (x == 0 && z == 0) { cubeArray[x][y][z].piece.left = cubeArray[x][y][z].piece.front; cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.right; cubeArray[x][y][z].piece.right = NULL; } if (x == 0 && z == 1) { cubeArray[x][y][z].piece.left = cubeArray[x][y][z].piece.front; cubeArray[x][y][z].piece.front = NULL; } if (x == 0 && z == 2) { cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.left; cubeArray[x][y][z].piece.left = cubeArray[x][y][z].piece.front; cubeArray[x][y][z].piece.front = NULL; } if (x == 1 && z == 0) { cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.right; cubeArray[x][y][z].piece.right = NULL; } if (x == 1 && z == 2) { cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.left; //skip 1,1 bc its the middle piece cubeArray[x][y][z].piece.left = NULL; } if (x == 2 && z == 0) { cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.right; cubeArray[x][y][z].piece.right = cubeArray[x][y][z].piece.back; cubeArray[x][y][z].piece.back = NULL; } if (x == 2 && z == 1) { cubeArray[x][y][z].piece.right = cubeArray[x][y][z].piece.back; cubeArray[x][y][z].piece.back = NULL; } if (x == 2 && z == 2) { cubeArray[x][y][z].piece.right = cubeArray[x][y][z].piece.back; cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.left; cubeArray[x][y][z].piece.left = NULL; } } } } void FlipCube(Cube cubeArray[3][3][3]) { Cube temp[3][3][3]; for (int x = 0; x < 3; x++) { for (int y = 0; y < 3; y++) { for (int z = 0; z < 3; z++) { temp[x][y][z] = cubeArray[x][y][z]; //copy cube } } } int yy = 2; int zz = 2; for (int x = 0; x < 3; x++) { for (int y = 0; y < 3; y++) { for (int z = 0; z < 3; z++) { if (z == 0) { zz = 2; } if (y == 0) { yy = 2; } cubeArray[x][y][z] = temp[x][yy][zz]; zz--; } yy--; } } OrientFlipCube(cubeArray); } void OrientFlipCube(Cube cubeArray[3][3][3]) { for (int y=0;y<3;y++){ for (int z = 0; z < 3; z++) { for (int x = 0; x < 3; x++) { if (x == 0 && y == 0 && z == 0) { cubeArray[x][y][z].piece.down = cubeArray[x][y][z].piece.up; cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.back; cubeArray[x][y][z].piece.up = NULL; cubeArray[x][y][z].piece.back = NULL; } if (x == 1 && y == 0 && z == 0) { cubeArray[x][y][z].piece.down = cubeArray[x][y][z].piece.up; cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.back; /*cout << "down " << cubeArray[x][y][z].piece.down << " front " << cubeArray[x][y][z].piece.front << " up " << cubeArray[x][y][z].piece.up; cout << " back " << cubeArray[x][y][z].piece.back << " right " << cubeArray[x][y][z].piece.right<< " left " << cubeArray[x][y][z].piece.left << endl;*/ cubeArray[x][y][z].piece.up = NULL; cubeArray[x][y][z].piece.back = NULL; } if (x == 2 && y == 0 && z == 0) { cubeArray[x][y][z].piece.down = cubeArray[x][y][z].piece.up; cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.back; cubeArray[x][y][z].piece.back = NULL; cubeArray[x][y][z].piece.up = NULL; } if (x == 0 && y == 1 && z == 0) { cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.back; cubeArray[x][y][z].piece.back = NULL; } if (x == 1 && y == 1 && z == 0) { cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.back; //skip 1,1 bc its the middle piece cubeArray[x][y][z].piece.back = NULL; } if (x == 2 && y == 1 && z == 0) { cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.back; cubeArray[x][y][z].piece.down = cubeArray[x][y][z].piece.up; cubeArray[x][y][z].piece.back = NULL; cubeArray[x][y][z].piece.up = NULL; } if (x == 0 && y == 2 && z == 0) { cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.back; cubeArray[x][y][z].piece.up = cubeArray[x][y][z].piece.down; cubeArray[x][y][z].piece.back = NULL; cubeArray[x][y][z].piece.down = NULL; } if (x == 1 && y == 2 && z == 0) { cubeArray[x][y][z].piece.up = cubeArray[x][y][z].piece.down; cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.back; cubeArray[x][y][z].piece.down = NULL; cubeArray[x][y][z].piece.back = NULL; } if (x == 2 && y == 2 && z == 0) { cubeArray[x][y][z].piece.up = cubeArray[x][y][z].piece.down; cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.back; cubeArray[x][y][z].piece.back = NULL; cubeArray[x][y][z].piece.down = NULL; } if (x == 0 && y == 0 && z == 1) { cubeArray[x][y][z].piece.down = cubeArray[x][y][z].piece.up; cubeArray[x][y][z].piece.up = NULL; } if (x == 1 && y == 0 && z == 1) { cubeArray[x][y][z].piece.down = cubeArray[x][y][z].piece.up; cubeArray[x][y][z].piece.up = NULL; } if (x == 2 && y == 0 && z == 1) { cubeArray[x][y][z].piece.down = cubeArray[x][y][z].piece.up; //skip 0,1,1 , 111,211 cubeArray[x][y][z].piece.up = NULL; } if (x == 0 && y == 2 && z == 1) { cubeArray[x][y][z].piece.up = cubeArray[x][y][z].piece.down;// out of order cubeArray[x][y][z].piece.down = NULL; } if (x == 1 && y == 2 && z == 1) { cubeArray[x][y][z].piece.up = cubeArray[x][y][z].piece.down; cubeArray[x][y][z].piece.down = NULL; } if (x == 2 && y == 2 && z == 1) { cubeArray[x][y][z].piece.up = cubeArray[x][y][z].piece.down; cubeArray[x][y][z].piece.down = NULL; } if (x == 0 && y == 0 && z == 2) { cubeArray[x][y][z].piece.down = cubeArray[x][y][z].piece.up; cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.front; cubeArray[x][y][z].piece.up = NULL; cubeArray[x][y][z].piece.front = NULL; } if (x == 1 && y == 0 && z == 2) { cubeArray[x][y][z].piece.down = cubeArray[x][y][z].piece.up; cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.front; cubeArray[x][y][z].piece.up = NULL; cubeArray[x][y][z].piece.front = NULL; } if (x == 2 && y == 0 && z == 2) { cubeArray[x][y][z].piece.down = cubeArray[x][y][z].piece.up; cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.front; cubeArray[x][y][z].piece.up = NULL; cubeArray[x][y][z].piece.front = NULL; } if (x == 0 && y == 1 && z == 2) { cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.front; cubeArray[x][y][z].piece.front = NULL; } if (x == 1 && y == 1 && z == 2) { cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.front; cubeArray[x][y][z].piece.front = NULL; } if (x == 2 && y == 1 && z == 2) { cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.front; cubeArray[x][y][z].piece.front = NULL; } if (x == 0 && y == 2 && z == 2) { cubeArray[x][y][z].piece.up = cubeArray[x][y][z].piece.down; cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.front; cubeArray[x][y][z].piece.down = NULL; cubeArray[x][y][z].piece.front = NULL; } if (x == 1 && y == 2 && z == 2) { cubeArray[x][y][z].piece.up = cubeArray[x][y][z].piece.down; cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.front; cubeArray[x][y][z].piece.down = NULL; cubeArray[x][y][z].piece.front = NULL; } if (x == 2 && y == 2 && z == 2) { cubeArray[x][y][z].piece.up = cubeArray[x][y][z].piece.down; cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.front; cubeArray[x][y][z].piece.down = NULL; cubeArray[x][y][z].piece.front = NULL; } } } } } void RotateCubeRight(Cube cubeArray[3][3][3]) { Cube temp[3][3][3]; for (int x = 0; x < 3; x++) { for (int y = 0; y < 3; y++) { for (int z = 0; z < 3; z++) { temp[x][y][z] = cubeArray[x][y][z]; //copy cube } } } int zz = 2; int xx = 0; for (int z = 0; z < 3; z++) { for (int y = 0; y < 3; y++) { for (int x = 0; x < 3; x++) { //cout << "x " << x << " Y " << y << " z " << " xx " << xx << " zz " << zz << endl; if (x == 0) { zz = 2; } if (z == 0) { xx = 0; } //cout << "x " << x << " Y " << y << " z " << z << " xx " << xx << " zz " << zz << endl; cubeArray[x][y][z] = temp[xx][y][zz]; zz--; } } xx++; } OrientRotateCubeRight(cubeArray); } void OrientRotateCubeRight(Cube cubeArray[3][3][3]){ for (int y = 0; y < 3; y++) { for (int z = 0; z < 3; z++) { for (int x = 0; x < 3; x++) { if (x == 0 && y == 0 && z == 0) { cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.left; cubeArray[x][y][z].piece.left = cubeArray[x][y][z].piece.back; cubeArray[x][y][z].piece.back = NULL; } if (x == 1 && y == 0 && z == 0) { cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.left; cubeArray[x][y][z].piece.left = NULL; } if (x == 2 && y == 0 && z == 0) { cubeArray[x][y][z].piece.right = cubeArray[x][y][z].piece.front; cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.left; cubeArray[x][y][z].piece.left = NULL; } if (x == 0 && y == 1 && z == 0) { cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.left; cubeArray[x][y][z].piece.left = cubeArray[x][y][z].piece.back; cubeArray[x][y][z].piece.back = NULL; } if (x == 1 && y == 1 && z == 0) { cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.left; //skip 1,1 bc its the middle piece cubeArray[x][y][z].piece.left = NULL; } if (x == 2 && y == 1 && z == 0) { cubeArray[x][y][z].piece.right = cubeArray[x][y][z].piece.front; cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.left; cubeArray[x][y][z].piece.left = NULL; } if (x == 0 && y == 2 && z == 0) { cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.left; cubeArray[x][y][z].piece.left = cubeArray[x][y][z].piece.back; cubeArray[x][y][z].piece.back = NULL; } if (x == 1 && y == 2 && z == 0) { cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.left; cubeArray[x][y][z].piece.left = NULL; } if (x == 2 && y == 2 && z == 0) { cubeArray[x][y][z].piece.right = cubeArray[x][y][z].piece.front; cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.left; cubeArray[x][y][z].piece.left = NULL; } if (x == 0 && y == 0 && z == 1) { cubeArray[x][y][z].piece.left = cubeArray[x][y][z].piece.back; cubeArray[x][y][z].piece.back = NULL; } /*if (x == 1 && y == 0 && z == 1) { cubeArray[x][y][z].piece.down = cubeArray[x][y][z].piece.up; cubeArray[x][y][z].piece.up = NULL;*/ //} if (x == 2 && y == 0 && z == 1) { cubeArray[x][y][z].piece.right = cubeArray[x][y][z].piece.front; //skip , 111,211 cubeArray[x][y][z].piece.front = NULL; } if (x == 0 && y == 1 && z == 1) { cubeArray[x][y][z].piece.left = cubeArray[x][y][z].piece.back; cubeArray[x][y][z].piece.back = NULL; } if (x == 0 && y == 2 && z == 1) { cubeArray[x][y][z].piece.left = cubeArray[x][y][z].piece.back;// out of order cubeArray[x][y][z].piece.back = NULL; } if (x == 2 && y == 1 && z == 1) { cubeArray[x][y][z].piece.right = cubeArray[x][y][z].piece.front; cubeArray[x][y][z].piece.front = NULL; } if (x == 2 && y == 2 && z == 1) { cubeArray[x][y][z].piece.right = cubeArray[x][y][z].piece.front; cubeArray[x][y][z].piece.front = NULL; } if (x == 0 && y == 0 && z == 2) { cubeArray[x][y][z].piece.left = cubeArray[x][y][z].piece.back; cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.right; cubeArray[x][y][z].piece.right = NULL; } if (x == 1 && y == 0 && z == 2) { cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.right; cubeArray[x][y][z].piece.right = NULL; } if (x == 2 && y == 0 && z == 2) { cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.right; cubeArray[x][y][z].piece.right = cubeArray[x][y][z].piece.front; cubeArray[x][y][z].piece.front = NULL; } if (x == 0 && y == 1 && z == 2) { cubeArray[x][y][z].piece.left = cubeArray[x][y][z].piece.back; cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.right; cubeArray[x][y][z].piece.right = NULL; } if (x == 1 && y == 1 && z == 2) { cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.right; cubeArray[x][y][z].piece.right = NULL; } if (x == 2 && y == 1 && z == 2) { cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.right; cubeArray[x][y][z].piece.right = cubeArray[x][y][z].piece.front; cubeArray[x][y][z].piece.front = NULL; } if (x == 0 && y == 2 && z == 2) { cubeArray[x][y][z].piece.left = cubeArray[x][y][z].piece.back; cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.right; cubeArray[x][y][z].piece.right = NULL; } if (x == 1 && y == 2 && z == 2) { cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.right; cubeArray[x][y][z].piece.right = NULL; } if (x == 2 && y == 2 && z == 2) { cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.right; cubeArray[x][y][z].piece.right = cubeArray[x][y][z].piece.front; cubeArray[x][y][z].piece.front = NULL; } } } } } void RotateCubeLeft(Cube cubeArray[3][3][3]) { for (int x = 0; x < 3; x++) { RotateCubeRight(cubeArray); } } void MoveList() { cout << "MoveList" << endl; cout << endl; cout << "RightBack or RB" << endl; cout << "RightFront or RF" << endl; cout << "LeftBack or LB" << endl; cout << "LeftFront or LF" << endl; cout << "TopRight or TR" << endl; cout << "TopLeft or TL" << endl; cout << "DownRight or DR" << endl; cout << "DownLeft or DL" << endl; cout << "FrontRight or FR" << endl; cout << "FrontLeft or FL" << endl; cout << "BackRight or BR" << endl; cout << "BackLeft or BL" << endl; cout << "MiddleFront or MF" << endl; cout << "MiddleBack or MB" << endl; cout << "MiddleRight or MR" << endl; cout << "MiddleLeft or ML" << endl; cout << "FlipCube (upside down) or FC" << endl; cout << "RotateRight (rotate whole cube right) or RR" << endl; cout << "RotateLeft (rotate whole cube left) or RL" << endl; cout << "SolveMiddleRight (For Solving Middle Layer From Top layer Down Right) or SMR" << endl; cout << "SolveMiddleLeft (For Solving Middle Layer From Top layer Down Left) or SML" << endl; cout << "(Solve for) YellowCross (For Solving the 3rd layer) or YC" << endl; cout << "SwapYellowEdges (For Solving 3rd Layer) or SYE" << endl; cout << "SwapYellowCorners(For Solving 3rd Layer) or SYC" << endl; cout << "OrientYellowCorners (For Solving 3rd Layer or OYC" << endl; cout << "ResetCube or Reset (Returns Cube to Solved State" << endl; cout << "ShuffleCube (Mixes up Cube) or Shuffle or SC" << endl; } void Play(Cube cubeArray[3][3][3]) { cout << "Cube Simulator" << endl; cout << endl; cout << "Use Random Cube? Y or N?" << endl; string in; cin >> in; if (in == "Y" || in == "y") { SetRandomColors(cubeArray); CubeDisplay(cubeArray); } else if (in == "N" || in == "n") { ResetCube(cubeArray); CubeDisplay(cubeArray); } while (1) { cout << "Enter Move ....(Move List Enter M)" << endl; cin >> in; if (in == "m" || in == "M") { MoveList(); } else if (in == "Right Back" || in == "right back" || in == "RightBack" || in == "rightback" || in == "RB" || in == "rb" || in == "R B" || in == "r b") { MoveRightBack(cubeArray); CubeDisplay(cubeArray); } else if (in == "Right Front" || in == "right front" || in == "RightFront" || in == "rightfront" || in == "RF" || in == "rf" || in == "R F" || in == "r f") { MoveRightFront(cubeArray); CubeDisplay(cubeArray); } else if (in == "Left Back" || in == "left back" || in == "LeftBack" || in == "leftback" || in == "LB" || in == "lb" || in == "L B" || in == "l b") { MoveLeftBack(cubeArray); CubeDisplay(cubeArray); } else if (in == "Left Front" || in == "left front" || in == "LeftFront" || in == "leftfront" || in == "LF" || in == "lf" || in == "L F" || in == "l f") { MoveLeftFront(cubeArray); CubeDisplay(cubeArray); } else if (in == "Back Right" || in == "back right" || in == "BackRight" || in == "backright" || in == "BR" || in == "br" || in == "B R" || in == "b r") { MoveBackRight(cubeArray); CubeDisplay(cubeArray); } else if (in == "Back Left" || in == "back left" || in == "BackLeft" || in == "backleft" || in == "BL" || in == "bl" || in == "B L" || in == "b l") { MoveBackLeft(cubeArray); CubeDisplay(cubeArray); } else if (in == "Front Left" || in == "front left" || in == "FrontLeft" || in == "frontleft" || in == "FL" || in == "fl" || in == "F L" || in == "f l") { MoveFrontLeft(cubeArray); CubeDisplay(cubeArray); } else if (in == "Front Right" || in == "front right" || in == "FrontRight" || in == "frontright" || in == "FR" || in == "fr" || in == "F R" || in == "f r") { MoveFrontRight(cubeArray); CubeDisplay(cubeArray); } else if (in == "Top Right" || in == "top right" || in == "TopRight" || in == "topright" || in == "TR" || in == "tr" || in == "T R" || in == "t r") { MoveTopRight(cubeArray); CubeDisplay(cubeArray); } else if (in == "Top Left" || in == "top left" || in == "TopLeft" || in == "topleft" || in == "TL" || in == "tl" || in == "T L" || in == "t l") { MoveTopLeft(cubeArray); CubeDisplay(cubeArray); } else if (in == "Down Left" || in == "down left" || in == "DownLeft" || in == "downleft" || in == "DL" || in == "dl" || in == "D L" || in == "d l") { MoveBottomLeft(cubeArray); CubeDisplay(cubeArray); } else if (in == "Down Right" || in == "down right" || in == "DownRight" || in == "downright" || in == "DR" || in == "dr" || in == "D R" || in == "d r") { MoveBottomRight(cubeArray); CubeDisplay(cubeArray); } else if (in == "Flip Cube" || in == "flip cube" || in == "FlipCube" || in == "flipcube" || in == "FC" || in == "fc" || in == "f c" || in == "F C") { FlipCube(cubeArray); CubeDisplay(cubeArray); } else if (in == "Rotate Right" || in == "rotate right" || in == "RotateRight" || in == "rotateright" || in == "RR" || in == "rr" || in == "R R" || in == "r r") { RotateCubeRight(cubeArray); CubeDisplay(cubeArray); } else if (in == "Rotate Left" || in == "rotate left" || in == "RotateLeft" || in == "rotateleft" || in == "RL" || in == "rl" || in == "R L" || in == "r l") { RotateCubeLeft(cubeArray); CubeDisplay(cubeArray); } else if (in == "SolveMiddleRight" || in == "solvemiddleright" || in == "Solve Middle Right" || in == "solve middle right" || in == "SMR" || in == "smr" || in == "S M R" || in == "s m r") { SolveMiddleRight(cubeArray); CubeDisplay(cubeArray); } else if (in == "SolveMiddleLeft" || in == "solvemiddleleft" || in == "Solve Middle Left" || in == "solve middle left" || in == "SML" || in == "sml" || in == "S M L" || in == "s m l") { SolveMiddleLeft(cubeArray); CubeDisplay(cubeArray); } else if (in == "MiddleFront" || in == "middlefront" || in == "Middle Front" || in == "middle front" || in == "MF" || in == "mf" || in == "M F" || in == "m f") { MoveMiddleFront(cubeArray); CubeDisplay(cubeArray); } else if (in == "MiddleBack" || in == "middleback" || in == "Middle Back" || in == "middle back" || in == "MB" || in == "mb" || in == "M B" || in == "m b") { MoveMiddleBack(cubeArray); CubeDisplay(cubeArray); } else if (in == "MiddleRight" || in == "middleright" || in == "Middle Right" || in == "middle right" || in == "MR" || in == "mr") { MoveMiddleRight(cubeArray); CubeDisplay(cubeArray); } else if (in == "MiddleLeft" || in == "middleleft" || in == "Middle Left" || in == "middle left" || in == "ML" || in == "ml") { MoveMiddleLeft(cubeArray); CubeDisplay(cubeArray); } else if (in == "YellowCross" || in == "yellowcross" || in == "YC" || in == "yc") { SolveYellowCross(cubeArray); CubeDisplay(cubeArray); } else if (in == "SwapYellowEdges" || in == "swapyellowedges" || in == "SYE" || in == "sye") { SwapYellowEdges(cubeArray); CubeDisplay(cubeArray); } else if (in == "SwapYellowCorners" || in == "swapyellowcorners" || in == "SYC" || in == "syc") { SwapYellowCorners(cubeArray); CubeDisplay(cubeArray); } else if (in == "OrientYellowCorners" || in == "orientyellowcorners" || in == "OYC" || in == "oyc") { OrientYellowCorners(cubeArray); CubeDisplay(cubeArray); } else if (in == "ResetCube" || in == "resetcube" || in == "Reset" || in == "reset") { ResetCube(cubeArray); CubeDisplay(cubeArray); } else if (in == "ShuffleCube" || in == "shufflecube" || in == "Shuffle" || in == "shuffle" || in == "SC" || in == "sc") { SetRandomColors(cubeArray); CubeDisplay(cubeArray); } else { cout << "Please Enter Valid Move, See Move List For Help" << endl; } } } void SolveMiddleRight(Cube cubeArray[3][3][3]) { //this is an algorithm MoveTopLeft(cubeArray); MoveRightBack(cubeArray); MoveTopRight(cubeArray); MoveRightFront(cubeArray); MoveTopRight(cubeArray); MoveFrontLeft(cubeArray); MoveTopLeft(cubeArray); MoveFrontRight(cubeArray); } void SolveMiddleLeft(Cube cubeArray[3][3][3]) { //algorithm MoveTopRight(cubeArray); MoveLeftBack(cubeArray); MoveTopLeft(cubeArray); MoveLeftFront(cubeArray); MoveTopLeft(cubeArray); MoveFrontRight(cubeArray); MoveTopRight(cubeArray); MoveFrontLeft(cubeArray); } void MoveMiddleBack(Cube cubeArray[3][3][3]) { Cube temp[3][3][3]; for (int y = 0; y < 3; y++) { for (int z = 0; z < 3; z++) { temp[1][y][z] = cubeArray[1][y][z]; //copy } } int z = 0; for (int y = 2; y > -1; y--) { cubeArray[1][y][2] = temp[1][2][z]; z += 1; } int y = 2; for (int z = 2; z > -1; z--) { cubeArray[1][0][z] = temp[1][y][2]; y--; } y = 0; for (int z = 2; z > -1; z--) { cubeArray[1][y][0] = temp[1][0][z]; y++; } y = 0; for (int z = 0; z < 3; z++) { cubeArray[1][2][z] = temp[1][y][0]; y++; } OrientMiddleBack(cubeArray); } void OrientMiddleBack(Cube cubeArray[3][3][3]) { for (int y = 0; y < 3; y++) { for (int z = 0; z < 3; z++) { if (y == 0 && z == 0) { cubeArray[1][y][z].piece.front = cubeArray[1][y][z].piece.down; cubeArray[1][y][z].piece.down = cubeArray[1][y][z].piece.back; cubeArray[1][y][z].piece.back = NULL; } if (y == 1 && z == 0) { cubeArray[1][y][z].piece.front = cubeArray[1][y][z].piece.down; cubeArray[1][y][z].piece.down = NULL; } if (y == 2 && z == 0) { cubeArray[1][y][z].piece.up = cubeArray[1][y][z].piece.front; cubeArray[1][y][z].piece.front = cubeArray[1][y][z].piece.down; cubeArray[1][y][z].piece.down = NULL; } if (y == 0 && z == 1) { cubeArray[1][y][z].piece.down = cubeArray[1][y][z].piece.back; cubeArray[1][y][z].piece.back = NULL; } if (y == 2 && z == 1) { cubeArray[1][y][z].piece.up = cubeArray[1][y][z].piece.front; cubeArray[1][y][z].piece.front = NULL; } if (y == 0 && z == 2) { cubeArray[1][y][z].piece.down = cubeArray[1][y][z].piece.back; cubeArray[1][y][z].piece.back = cubeArray[1][y][z].piece.up; cubeArray[1][y][z].piece.up = NULL; } if (y == 1 && z == 2) { cubeArray[1][y][z].piece.back = cubeArray[1][y][z].piece.up; cubeArray[1][y][z].piece.up = NULL; } if (y == 2 && z == 2) { cubeArray[1][y][z].piece.back = cubeArray[1][y][z].piece.up; cubeArray[1][y][z].piece.up = cubeArray[1][y][z].piece.front; cubeArray[1][y][z].piece.front = NULL; } } } } void MoveMiddleFront(Cube cubeArray[3][3][3]) { for (int x = 0; x < 3; x++) { MoveMiddleBack(cubeArray); } } void MoveMiddleRight(Cube cubeArray[3][3][3]) { Cube temp[3][3][3]; // this just copies the current cube to a temp for (int x = 0; x < 3; x++) { for (int z = 0; z < 3; z++) { temp[x][1][z] = cubeArray[x][1][z]; } } int x = 0; for (int z = 0; z < 3; z++) { cubeArray[2][1][z] = temp[x][1][0]; //front to right x++; } int z = 0; for (int x = 2; x > -1; x--) { cubeArray[x][1][2] = temp[2][1][z]; //right to back z++; } x = 2; for (int z = 2; z > -1; z--) { cubeArray[0][1][z] = temp[x][1][2]; //back to left x--; } z = 2; for (int x = 0; x < 3; x++) { cubeArray[x][1][0] = temp[0][1][z]; //left to front z--; } OrientMiddleRight(cubeArray); } void OrientMiddleRight(Cube cubeArray[3][3][3]) { int y = 1; for (int z = 0; z < 3; z++) { for (int x = 0; x < 3; x++) { if (x == 0 && z == 0) { cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.left; cubeArray[x][y][z].piece.left = cubeArray[x][y][z].piece.back; cubeArray[x][y][z].piece.back = NULL; } if (x == 0 && z == 1) { cubeArray[x][y][z].piece.left = cubeArray[x][y][z].piece.back; cubeArray[x][y][z].piece.back = NULL; } if (x == 0 && z == 2) { cubeArray[x][y][z].piece.left = cubeArray[x][y][z].piece.back; cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.right; cubeArray[x][y][z].piece.right = NULL; } if (x == 1 && z == 0) { cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.left; cubeArray[x][y][z].piece.left = NULL; } if (x == 1 && z == 2) { cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.right; //skip 1,1 bc its the middle piece cubeArray[x][y][z].piece.right = NULL; } if (x == 2 && z == 0) { cubeArray[x][y][z].piece.right = cubeArray[x][y][z].piece.front; cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.left; cubeArray[x][y][z].piece.left = NULL; } if (x == 2 && z == 1) { cubeArray[x][y][z].piece.right = cubeArray[x][y][z].piece.front; cubeArray[x][y][z].piece.front = NULL; } if (x == 2 && z == 2) { cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.right; cubeArray[x][y][z].piece.right = cubeArray[x][y][z].piece.front; cubeArray[x][y][z].piece.front = NULL; } } } } void MoveMiddleLeft(Cube cubeArray[3][3][3]) { for (int x = 0; x < 3; x++) { MoveMiddleRight(cubeArray); } } void SolveYellowCross(Cube cubeArray[3][3][3]) { //algorithm MoveFrontRight(cubeArray); MoveRightBack(cubeArray); MoveTopLeft(cubeArray); MoveRightFront(cubeArray); MoveTopRight(cubeArray); MoveFrontLeft(cubeArray); } void SwapYellowEdges(Cube cubeArray[3][3][3]) { //algorithm MoveRightBack(cubeArray); MoveTopLeft(cubeArray); MoveRightFront(cubeArray); MoveTopLeft(cubeArray); MoveRightBack(cubeArray); MoveTopLeft(cubeArray); MoveTopLeft(cubeArray); MoveRightFront(cubeArray); MoveTopLeft(cubeArray); } void SwapYellowCorners(Cube cubeArray[3][3][3]) { //algorithm MoveTopLeft(cubeArray); MoveRightBack(cubeArray); MoveTopRight(cubeArray); MoveLeftBack(cubeArray); MoveTopLeft(cubeArray); MoveRightFront(cubeArray); MoveTopRight(cubeArray); MoveLeftFront(cubeArray); } void OrientYellowCorners(Cube cubeArray[3][3][3]) { //algorithm MoveRightFront(cubeArray); MoveBottomLeft(cubeArray); MoveRightBack(cubeArray); MoveBottomRight(cubeArray); } void ResetCube(Cube cubeArray[3][3][3]) { char combo1[6]{ 'W','G','R','B','Y','O' }; char combo2[12][2]{ {'W','B'},{'W','O'},{'W','G'},{'W','R'},{'Y','B'},{'Y','R'},{'Y','G'},{'Y','O'},{'B','R'},{'B','O'},{'O','G'},{'G','R'} }; char combo3[8][3]{ {'R','B','W'},{'G','R','W'},{'B','R','Y'},{'R','G','Y'},{'B','O','W'},{'O','G','Y'},{'O','B','Y'},{'O','G','W'} }; for (int z = 0; z < 3; z++) { for (int y = 0; y < 3; y++) { for (int x = 0; x < 3; x++) { cubeArray[x][y][z].piece.front = NULL; cubeArray[x][y][z].piece.back = NULL; cubeArray[x][y][z].piece.right = NULL; cubeArray[x][y][z].piece.left = NULL; cubeArray[x][y][z].piece.up = NULL; cubeArray[x][y][z].piece.down = NULL; cubeArray[x][y][z].piece.color1 = NULL; cubeArray[x][y][z].piece.color2 = NULL; cubeArray[x][y][z].piece.color3 = NULL; } } } for (int z = 0; z < 3; z++) { for (int y = 0; y < 3; y++) { for (int x = 0; x < 3; x++) { if (x == 0 && y == 0 && z == 0) { cubeArray[x][y][z].piece.color1 = combo3[1][0];//'G','R','W' cubeArray[x][y][z].piece.color2 = combo3[1][2]; cubeArray[x][y][z].piece.color3 = combo3[1][1]; cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.color2; cubeArray[x][y][z].piece.left = cubeArray[x][y][z].piece.color1; cubeArray[x][y][z].piece.down = cubeArray[x][y][z].piece.color3; } if (x == 1 && y == 0 && z == 0) { cubeArray[x][y][z].piece.color1 = combo2[3][0]; //w r cubeArray[x][y][z].piece.color2 = combo2[3][1]; cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.color1; cubeArray[x][y][z].piece.down = cubeArray[x][y][z].piece.color2; } if (x == 2 && y == 0 && z == 0) { cubeArray[x][y][z].piece.color1 = combo3[0][2]; cubeArray[x][y][z].piece.color2 = combo3[0][1]; cubeArray[x][y][z].piece.color3 = combo3[0][0]; cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.color1; cubeArray[x][y][z].piece.right = cubeArray[x][y][z].piece.color2; cubeArray[x][y][z].piece.down = cubeArray[x][y][z].piece.color3; } if (x == 0 && y == 1 && z == 0) { cubeArray[x][y][z].piece.color1 = combo2[2][1]; //w g cubeArray[x][y][z].piece.color2 = combo2[2][0]; cubeArray[x][y][z].piece.left = cubeArray[x][y][z].piece.color1; cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.color2; } if (x == 1 && y == 1 && z == 0) { cubeArray[x][y][z].piece.color1 = combo1[0]; cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.color1; } if (x == 2 && y == 1 && z == 0) { cubeArray[x][y][z].piece.color1 = combo2[0][0]; cubeArray[x][y][z].piece.color2 = combo2[0][1]; cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.color1; cubeArray[x][y][z].piece.right = cubeArray[x][y][z].piece.color2; } if (x == 0 && y == 2 && z == 0) { cubeArray[x][y][z].piece.color1 = combo3[7][1]; //'O','G','W' cubeArray[x][y][z].piece.color2 = combo3[7][2]; cubeArray[x][y][z].piece.color3 = combo3[7][0]; cubeArray[x][y][z].piece.left = cubeArray[x][y][z].piece.color1; cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.color2; cubeArray[x][y][z].piece.up = cubeArray[x][y][z].piece.color3; } if (x == 1 && y == 2 && z == 0) { cubeArray[x][y][z].piece.color1 = combo2[1][1]; //w o cubeArray[x][y][z].piece.color2 = combo2[1][0]; cubeArray[x][y][z].piece.up = cubeArray[x][y][z].piece.color1; cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.color2; } if (x == 2 && y == 2 && z == 0) { cubeArray[x][y][z].piece.color1 = combo3[4][2]; //'B','O','W' cubeArray[x][y][z].piece.color2 = combo3[4][0]; cubeArray[x][y][z].piece.color3 = combo3[4][1]; cubeArray[x][y][z].piece.front = cubeArray[x][y][z].piece.color1; cubeArray[x][y][z].piece.right = cubeArray[x][y][z].piece.color2; cubeArray[x][y][z].piece.up = cubeArray[x][y][z].piece.color3; } if (x == 0 && y == 0 && z == 1) { cubeArray[x][y][z].piece.color1 = combo2[11][0]; //'G','R' cubeArray[x][y][z].piece.color2 = combo2[11][1]; cubeArray[x][y][z].piece.left = cubeArray[x][y][z].piece.color1; cubeArray[x][y][z].piece.down = cubeArray[x][y][z].piece.color2; } if (x == 1 && y == 0 && z == 1) { cubeArray[x][y][z].piece.color1 = combo1[2]; //r cubeArray[x][y][z].piece.down = cubeArray[x][y][z].piece.color1; } if (x == 2 && y == 0 && z == 1) { cubeArray[x][y][z].piece.color1 = combo2[8][1]; //'B','R' cubeArray[x][y][z].piece.color2 = combo2[8][0]; cubeArray[x][y][z].piece.down = cubeArray[x][y][z].piece.color1; cubeArray[x][y][z].piece.right = cubeArray[x][y][z].piece.color2; } if (x == 0 && y == 1 && z == 1) { cubeArray[x][y][z].piece.color1 = combo1[1]; //g cubeArray[x][y][z].piece.left = cubeArray[x][y][z].piece.color1; } if (x == 2 && y == 1 && z == 1) { cubeArray[x][y][z].piece.color1 = combo1[3]; //b cubeArray[x][y][z].piece.right = cubeArray[x][y][z].piece.color1; } if (x == 0 && y == 2 && z == 1) { cubeArray[x][y][z].piece.color1 = combo2[10][1]; //'O','G' cubeArray[x][y][z].piece.color2 = combo2[10][0]; cubeArray[x][y][z].piece.left = cubeArray[x][y][z].piece.color1; cubeArray[x][y][z].piece.up = cubeArray[x][y][z].piece.color2; } if (x == 1 && y == 2 && z == 1) { cubeArray[x][y][z].piece.color1 = combo1[5]; //0 cubeArray[x][y][z].piece.up = cubeArray[x][y][z].piece.color1; } if (x == 2 && y == 2 && z == 1) { cubeArray[x][y][z].piece.color1 = combo2[9][0]; //'B','O' cubeArray[x][y][z].piece.color2 = combo2[9][1]; cubeArray[x][y][z].piece.right = cubeArray[x][y][z].piece.color1; cubeArray[x][y][z].piece.up = cubeArray[x][y][z].piece.color2; } if (x == 0 && y == 0 && z == 2) { cubeArray[x][y][z].piece.color1 = combo3[3][2]; //'R','G','Y' cubeArray[x][y][z].piece.color2 = combo3[3][1]; cubeArray[x][y][z].piece.color3 = combo3[3][0]; cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.color1; cubeArray[x][y][z].piece.left = cubeArray[x][y][z].piece.color2; cubeArray[x][y][z].piece.down = cubeArray[x][y][z].piece.color3; } if (x == 1 && y == 0 && z == 2) { cubeArray[x][y][z].piece.color1 = combo2[5][0]; //'Y','R' cubeArray[x][y][z].piece.color2 = combo2[5][1]; cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.color1; cubeArray[x][y][z].piece.down = cubeArray[x][y][z].piece.color2; } if (x == 2 && y == 0 && z == 2) { cubeArray[x][y][z].piece.color1 = combo3[2][0]; //'B','R','Y' cubeArray[x][y][z].piece.color2 = combo3[2][2]; cubeArray[x][y][z].piece.color3 = combo3[2][1]; cubeArray[x][y][z].piece.right = cubeArray[x][y][z].piece.color1; cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.color2; cubeArray[x][y][z].piece.down = cubeArray[x][y][z].piece.color3; } if (x == 0 && y == 1 && z == 2) { cubeArray[x][y][z].piece.color1 = combo2[6][1]; //'Y','G' cubeArray[x][y][z].piece.color2 = combo2[6][0]; cubeArray[x][y][z].piece.left = cubeArray[x][y][z].piece.color1; cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.color2; } if (x == 1 && y == 1 && z == 2) { cubeArray[x][y][z].piece.color1 = combo1[4]; //y cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.color1; } if (x == 2 && y == 1 && z == 2) { cubeArray[x][y][z].piece.color1 = combo2[4][1]; //'Y','B' cubeArray[x][y][z].piece.color2 = combo2[4][0]; cubeArray[x][y][z].piece.right = cubeArray[x][y][z].piece.color1; cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.color2; } if (x == 0 && y == 2 && z == 2) { cubeArray[x][y][z].piece.color1 = combo3[5][2]; //'O','G','Y' cubeArray[x][y][z].piece.color2 = combo3[5][1]; cubeArray[x][y][z].piece.color3 = combo3[5][0]; cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.color1; cubeArray[x][y][z].piece.left = cubeArray[x][y][z].piece.color2; cubeArray[x][y][z].piece.up = cubeArray[x][y][z].piece.color3; } if (x == 1 && y == 2 && z == 2) { cubeArray[x][y][z].piece.color1 = combo2[7][0]; //'Y','O' cubeArray[x][y][z].piece.color2 = combo2[7][1]; cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.color1; cubeArray[x][y][z].piece.up = cubeArray[x][y][z].piece.color2; } if (x == 2 && y == 2 && z == 2) { cubeArray[x][y][z].piece.color1 = combo3[6][1]; //'O','B','Y' cubeArray[x][y][z].piece.color2 = combo3[6][2]; cubeArray[x][y][z].piece.color3 = combo3[6][0]; cubeArray[x][y][z].piece.right = cubeArray[x][y][z].piece.color1; cubeArray[x][y][z].piece.back = cubeArray[x][y][z].piece.color2; cubeArray[x][y][z].piece.up = cubeArray[x][y][z].piece.color3; } } } } } int main() { Cube cube; Cube cubeAry[3][3][3]; Play(cubeAry); } Spoiler "I Believe array math to be potentially fatal, I may be dying from array math poisoning"
argumentum Posted February 11, 2020 Posted February 11, 2020 1 hour ago, markyrocks said: hindsight is always 2020. this applies only to this year Thanks for sharing, even if you never know how made good use of it Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now