Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <algorithm>
- #define MAX_DEPTH 9
- #define PIECE_COUNT 52
- #define STATIC_COUNT 32
- #define VALID_MOVES 18
- #define VALID_MOVE_SET 6
- using namespace std;
- const char defaultState[] = {
- 0, 0, 0, 0, 0, 0, 0, 0,
- 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4,
- 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4,
- 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4,
- 5, 5, 5, 5, 5, 5, 5, 5,
- };
- struct level {
- char moveId = 0;
- bool tested = false;
- char state[PIECE_COUNT] = { 0 };
- };
- string moveIdName(char moveId) {
- switch (moveId) {
- case 0:
- return "R";
- case 1:
- return "U";
- case 2:
- return "D";
- case 3:
- return "L";
- case 4:
- return "F";
- case 5:
- return "B";
- case 6:
- return "R2";
- case 7:
- return "U2";
- case 8:
- return "D2";
- case 9:
- return "L2";
- case 10:
- return "F2";
- case 11:
- return "B2";
- case 12:
- return "R'";
- case 13:
- return "U'";
- case 14:
- return "D'";
- case 15:
- return "L'";
- case 16:
- return "F'";
- case 17:
- return "B'";
- default:
- return "?";
- }
- }
- void printState(char (&actual)[PIECE_COUNT]) {
- cout << "WHITE: ";
- for (int i = 0; i < 8; i++) {
- cout << (int)actual[i] << "; ";
- }
- for (int j = 0; j < 3; j++) {
- cout << "\nSLICE" << j << ": ";
- for (int i = 8 + j * 12; i < 20 + j * 12; i++) {
- cout << (int)actual[i] << "; ";
- }
- }
- cout << "\nYELLOW: ";
- for (int i = 44; i < 52; i++) {
- cout << (int)actual[i] << "; ";
- }
- cout << "\n";
- }
- void applyMove(char (&source)[PIECE_COUNT], char (&target)[PIECE_COUNT], char moveId) {
- char temp[PIECE_COUNT] = { 0 };
- for (int i = 0; i < PIECE_COUNT; i++) {
- temp[i] = source[i];
- }
- switch (moveId % VALID_MOVE_SET) {
- case 0: // R
- // d
- temp[2] = source[34];
- temp[3] = source[22];
- temp[4] = source[10];
- // f
- temp[14] = source[2];
- temp[26] = source[3];
- temp[38] = source[4];
- // u
- temp[48] = source[14];
- temp[47] = source[26];
- temp[46] = source[38];
- // b
- temp[34] = source[48];
- temp[22] = source[47];
- temp[10] = source[46];
- // r
- temp[11] = source[35];
- temp[12] = source[23];
- temp[13] = source[11];
- temp[25] = source[12];
- temp[37] = source[13];
- temp[36] = source[25];
- temp[35] = source[37];
- temp[23] = source[36];
- break;
- case 1: // U
- // u (yellow)
- temp[44] = source[50];
- temp[45] = source[51];
- temp[46] = source[44];
- temp[47] = source[45];
- temp[48] = source[46];
- temp[49] = source[47];
- temp[50] = source[48];
- temp[51] = source[49];
- // top slice
- temp[32] = source[41];
- temp[33] = source[42];
- temp[34] = source[43];
- temp[35] = source[32];
- temp[36] = source[33];
- temp[37] = source[34];
- temp[38] = source[35];
- temp[39] = source[36];
- temp[40] = source[37];
- temp[41] = source[38];
- temp[42] = source[39];
- temp[43] = source[40];
- break;
- case 2: // D
- // d (white)
- temp[0] = source[2];
- temp[1] = source[3];
- temp[2] = source[4];
- temp[3] = source[5];
- temp[4] = source[6];
- temp[5] = source[7];
- temp[6] = source[0];
- temp[7] = source[1];
- // top slice
- temp[8] = source[11];
- temp[9] = source[12];
- temp[10] = source[13];
- temp[11] = source[14];
- temp[12] = source[15];
- temp[13] = source[16];
- temp[14] = source[17];
- temp[15] = source[18];
- temp[16] = source[19];
- temp[17] = source[8];
- temp[18] = source[9];
- temp[19] = source[10];
- break;
- case 3: // L
- // d
- temp[6] = source[40];
- temp[7] = source[28];
- temp[0] = source[16];
- // f
- temp[40] = source[44];
- temp[28] = source[51];
- temp[16] = source[50];
- // u
- temp[44] = source[8];
- temp[51] = source[20];
- temp[50] = source[32];
- // b
- temp[8] = source[6];
- temp[20] = source[7];
- temp[32] = source[0];
- // l
- temp[17] = source[41];
- temp[18] = source[29];
- temp[19] = source[17];
- temp[31] = source[18];
- temp[43] = source[19];
- temp[42] = source[31];
- temp[41] = source[43];
- temp[29] = source[42];
- break;
- case 4: // F
- // d
- temp[4] = source[37];
- temp[5] = source[25];
- temp[6] = source[13];
- // r
- temp[37] = source[50];
- temp[25] = source[49];
- temp[13] = source[48];
- // u
- temp[50] = source[17];
- temp[49] = source[29];
- temp[48] = source[41];
- // l
- temp[17] = source[4];
- temp[29] = source[5];
- temp[41] = source[6];
- // f
- temp[14] = source[38];
- temp[15] = source[26];
- temp[16] = source[14];
- temp[28] = source[15];
- temp[40] = source[16];
- temp[39] = source[28];
- temp[38] = source[40];
- temp[26] = source[39];
- break;
- case 5: // B
- // 0-7 - white face
- // 8-19 - bottom slice
- // 20-31 - middle slice
- // 32-43 - top slice
- // 44-51 - yellow face
- // d
- temp[0] = source[43];
- temp[1] = source[31];
- temp[2] = source[19];
- // r
- temp[43] = source[46];
- temp[31] = source[45];
- temp[19] = source[44];
- // u
- temp[46] = source[11];
- temp[45] = source[23];
- temp[44] = source[35];
- // l
- temp[11] = source[0];
- temp[23] = source[1];
- temp[35] = source[2];
- // b
- temp[8] = source[32];
- temp[9] = source[20];
- temp[10] = source[8];
- temp[22] = source[9];
- temp[34] = source[10];
- temp[33] = source[22];
- temp[32] = source[34];
- temp[20] = source[33];
- break;
- default:
- break;
- }
- if (moveId < VALID_MOVE_SET) {
- for (int i = 0; i < PIECE_COUNT; i++) {
- target[i] = temp[i];
- }
- }
- else {
- applyMove(temp, target, moveId - VALID_MOVE_SET);
- }
- }
- void findLL() {
- unsigned char depth = 0;
- level levels[MAX_DEPTH];
- for (unsigned char i = 0; i < PIECE_COUNT; i++) {
- levels[0].state[i] = defaultState[i];
- }
- /*unsigned char toApply[] = {7, 255};
- for (unsigned char i = 0; toApply[i] != 255; i++) {
- applyMove(levels[0].state, levels[1].state, toApply[i]);
- for (int j = 0; j < PIECE_COUNT; j++) {
- levels[0].state[j] = levels[1].state[j];
- }
- printState(levels[0].state);
- }
- return;*/
- while (depth < 255) {
- short moveId = levels[depth].moveId;
- if ((depth > 0 && (moveId % VALID_MOVE_SET) == (levels[depth - 1].moveId % VALID_MOVE_SET))) {
- levels[depth].moveId++;
- moveId++;
- }
- if (moveId >= VALID_MOVES) {
- depth--;
- if (depth < 255) {
- levels[depth].moveId++;
- }
- continue;
- }
- // check if LL alg
- if (!levels[depth].tested) {
- char (&actual)[PIECE_COUNT] = levels[depth].state;
- bool isStatic = true;
- for (int j = 0; j < STATIC_COUNT; j++) {
- if (actual[j] != defaultState[j]) {
- isStatic = false;
- }
- }
- if (isStatic) {
- bool llChanged = false;
- bool isPll = true;
- for (int j = 44; j < 51; j++) {
- if (actual[j] != 5) {
- llChanged = true;
- isPll = false;
- }
- }
- for (int j = 32; j < 44; j += 3) {
- if (actual[j] != actual[j + 1] || actual[j] != actual[j + 2]) {
- llChanged = true;
- }
- }
- if (llChanged) {
- if (isPll) {
- cout << "PLL: ";
- }
- for (int i = 0; i < depth; i++) {
- cout << moveIdName(levels[i].moveId) << ' ';
- }
- cout << "\n";
- printState(levels[depth].state);
- }
- }
- levels[depth].tested = true;
- }
- if (depth >= MAX_DEPTH - 1) {
- depth--;
- levels[depth].moveId++;
- continue;
- }
- char (&source)[PIECE_COUNT] = levels[depth].state;
- char (&target)[PIECE_COUNT] = levels[depth + 1].state;
- applyMove(source, target, moveId);
- depth++;
- levels[depth].tested = false;
- levels[depth].moveId = 0;
- }
- }
- int main() {
- findLL();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement