How to use moveAxes method in Testcafe

Best JavaScript code snippet using testcafe

coordmoves.js

Source:coordmoves.js Github

copy

Full Screen

1var movesDef = {2 "U" : [[0,0,0,0, 0,0,0,0], [1,2,3,0, 4,5,6,7], [0,0,0,0, 0,0,0,0, 0,0,0,0], [1,2,3,0, 4,5,6,7, 8,9,10,11], [0,1,2,3,4,5]],3 "U2": [[0,0,0,0, 0,0,0,0], [2,3,0,1, 4,5,6,7], [0,0,0,0, 0,0,0,0, 0,0,0,0], [2,3,0,1, 4,5,6,7, 8,9,10,11], [0,1,2,3,4,5]],4 "U'": [[0,0,0,0, 0,0,0,0], [3,0,1,2, 4,5,6,7], [0,0,0,0, 0,0,0,0, 0,0,0,0], [3,0,1,2, 4,5,6,7, 8,9,10,11], [0,1,2,3,4,5]],5 "R" : [[0,1,2,0, 0,2,1,0], [0,5,1,3, 4,6,2,7], [0,0,0,0, 0,0,0,0, 0,0,0,0], [0,5,2,3, 4,9,1,7, 8,6,10,11], [0,1,2,3,4,5]],6 "R2": [[0,0,0,0, 0,0,0,0], [0,6,5,3, 4,2,1,7], [0,0,0,0, 0,0,0,0, 0,0,0,0], [0,9,2,3, 4,6,5,7, 8,1,10,11], [0,1,2,3,4,5]], 7 "R'": [[0,1,2,0, 0,2,1,0], [0,2,6,3, 4,1,5,7], [0,0,0,0, 0,0,0,0, 0,0,0,0], [0,6,2,3, 4,1,9,7, 8,5,10,11], [0,1,2,3,4,5]], 8 "F" : [[0,0,1,2, 0,0,2,1], [0,1,6,2, 4,5,7,3], [0,0,1,0, 0,0,1,1, 0,0,1,0], [0,1,6,3, 4,5,10,2, 8,9,7,11], [0,1,2,3,4,5]], 9 "F2": [[0,0,0,0, 0,0,0,0], [0,1,7,6, 4,5,3,2], [0,0,0,0, 0,0,0,0, 0,0,0,0], [0,1,10,3, 4,5,7,6, 8,9,2,11], [0,1,2,3,4,5]], 10 "F'": [[0,0,1,2, 0,0,2,1], [0,1,3,7, 4,5,2,6], [0,0,1,0, 0,0,1,1, 0,0,1,0], [0,1,7,3, 4,5,2,10, 8,9,6,11], [0,1,2,3,4,5]], 11 "L" : [[2,0,0,1, 1,0,0,2], [3,1,2,7, 0,5,6,4], [0,0,0,0, 0,0,0,0, 0,0,0,0], [0,1,2,7, 3,5,6,11, 8,9,10,4], [0,1,2,3,4,5]], 12 "L2": [[0,0,0,0, 0,0,0,0], [7,1,2,4, 3,5,6,0], [0,0,0,0, 0,0,0,0, 0,0,0,0], [0,1,2,11, 7,5,6,4, 8,9,10,3], [0,1,2,3,4,5]], 13 "L'": [[2,0,0,1, 1,0,0,2], [4,1,2,0, 7,5,6,3], [0,0,0,0, 0,0,0,0, 0,0,0,0], [0,1,2,4, 11,5,6,3, 8,9,10,7], [0,1,2,3,4,5]], 14 "D" : [[0,0,0,0, 0,0,0,0], [0,1,2,3, 7,4,5,6], [0,0,0,0, 0,0,0,0, 0,0,0,0], [0,1,2,3, 4,5,6,7, 11,8,9,10], [0,1,2,3,4,5]],15 "D2": [[0,0,0,0, 0,0,0,0], [0,1,2,3, 6,7,4,5], [0,0,0,0, 0,0,0,0, 0,0,0,0], [0,1,2,3, 4,5,6,7, 10,11,8,9], [0,1,2,3,4,5]], 16 "D'": [[0,0,0,0, 0,0,0,0], [0,1,2,3, 5,6,7,4], [0,0,0,0, 0,0,0,0, 0,0,0,0], [0,1,2,3, 4,5,6,7, 9,10,11,8], [0,1,2,3,4,5]], 17 "B" : [[1,2,0,0, 2,1,0,0], [4,0,2,3, 5,1,6,7], [1,0,0,0, 1,1,0,0, 1,0,0,0], [4,1,2,3, 8,0,6,7, 5,9,10,11], [0,1,2,3,4,5]], 18 "B2": [[0,0,0,0, 0,0,0,0], [5,4,2,3, 1,0,6,7], [0,0,0,0, 0,0,0,0, 0,0,0,0], [8,1,2,3, 5,4,6,7, 0,9,10,11], [0,1,2,3,4,5]], 19 "B'": [[1,2,0,0, 2,1,0,0], [1,5,2,3, 0,4,6,7], [1,0,0,0, 1,1,0,0, 1,0,0,0], [5,1,2,3, 0,8,6,7, 4,9,10,11], [0,1,2,3,4,5]],20 "M" : [[0,0,0,0,0,0,0,0], [0,1,2,3,4,5,6,7], [1,0,1,0,0,0,0,0,1,0,1,0], [2,1,10,3,4,5,6,7,0,9,8,11],[1,5,2,0,4,3]],21 "M2": [[0,0,0,0,0,0,0,0], [0,1,2,3,4,5,6,7], [0,0,0,0,0,0,0,0,0,0,0,0], [10,1,8,3,4,5,6,7,2,9,0,11],[5,3,2,1,4,0]], 22 "M'": [[0,0,0,0,0,0,0,0], [0,1,2,3,4,5,6,7], [1,0,1,0,0,0,0,0,1,0,1,0], [8,1,0,3,4,5,6,7,10,9,2,11],[3,0,2,5,4,1]], 23 "E" : [[0,0,0,0,0,0,0,0], [0,1,2,3,4,5,6,7], [0,0,0,0,1,1,1,1,0,0,0,0], [0,1,2,3,5,6,7,4,8,9,10,11], [0,4,1,2,3,5]],24 "E2": [[0,0,0,0,0,0,0,0], [0,1,2,3,4,5,6,7], [0,0,0,0,0,0,0,0,0,0,0,0], [0,1,2,3,6,7,4,5,8,9,10,11], [0,3,4,1,2,5]],25 "E'": [[0,0,0,0,0,0,0,0], [0,1,2,3,4,5,6,7], [0,0,0,0,1,1,1,1,0,0,0,0], [0,1,2,3,7,4,5,6,8,9,10,11], [0,2,3,4,1,5]],26 "S" : [[0,0,0,0,0,0,0,0], [0,1,2,3,4,5,6,7], [0,1,0,1,0,0,0,0,0,1,0,1], [0,9,2,1,4,5,6,7,8,11,10,3], [2,1,5,3,0,4]],27 "S2": [[0,0,0,0,0,0,0,0], [0,1,2,3,4,5,6,7], [0,0,0,0,0,0,0,0,0,0,0,0], [0,11,2,9,4,5,6,7,8,3,10,1], [5,1,4,3,2,0]],28 "S'": [[0,0,0,0,0,0,0,0], [0,1,2,3,4,5,6,7], [0,1,0,1,0,0,0,0,0,1,0,1], [0,3,2,11,4,5,6,7,8,1,10,9], [4,1,0,3,5,2]],29 "u" : [[0,0,0,0,0,0,0,0], [1,2,3,0,4,5,6,7], [0,0,0,0,1,1,1,1,0,0,0,0], [1,2,3,0,5,6,7,4,8,9,10,11], [0,4,1,2,3,5]],30 "u2": [[0,0,0,0,0,0,0,0], [2,3,0,1,4,5,6,7], [0,0,0,0,0,0,0,0,0,0,0,0], [2,3,0,1,6,7,4,5,8,9,10,11], [0,3,4,1,2,5]],31 "u'": [[0,0,0,0,0,0,0,0], [3,0,1,2,4,5,6,7], [0,0,0,0,1,1,1,1,0,0,0,0], [3,0,1,2,7,4,5,6,8,9,10,11], [0,2,3,4,1,5]],32 "r" : [[0,1,2,0,0,2,1,0], [0,5,1,3,4,6,2,7], [1,0,1,0,0,0,0,0,1,0,1,0], [8,5,0,3,4,9,1,7,10,6,2,11], [3,0,2,5,4,1]], 33 "r2": [[0,0,0,0,0,0,0,0], [0,6,5,3,4,2,1,7], [0,0,0,0,0,0,0,0,0,0,0,0], [10,9,8,3,4,6,5,7,2,1,0,11], [5,3,2,1,4,0]], 34 "r'": [[0,1,2,0,0,2,1,0], [0,2,6,3,4,1,5,7], [1,0,1,0,0,0,0,0,1,0,1,0], [2,6,10,3,4,1,9,7,0,5,8,11], [1,5,2,0,4,3]], 35 "f" : [[0,0,1,2,0,0,2,1], [0,1,6,2,4,5,7,3], [0,1,1,1,0,0,1,1,0,1,1,1], [0,9,6,1,4,5,10,2,8,11,7,3], [2,1,5,3,0,4]],36 "f2": [[0,0,0,0,0,0,0,0], [0,1,7,6,4,5,3,2], [0,0,0,0,0,0,0,0,0,0,0,0], [0,11,10,9,4,5,7,6,8,3,2,1], [5,1,4,3,2,0]],37 "f'": [[0,0,1,2,0,0,2,1], [0,1,3,7,4,5,2,6], [0,1,1,1,0,0,1,1,0,1,1,1], [0,3,7,11,4,5,2,10,8,1,6,9], [4,1,0,3,5,2]],38 "l" : [[2,0,0,1,1,0,0,2], [3,1,2,7,0,5,6,4], [1,0,1,0,0,0,0,0,1,0,1,0], [2,1,10,7,3,5,6,11,0,9,8,4], [1,5,2,0,4,3]],39 "l2": [[0,0,0,0,0,0,0,0], [7,1,2,4,3,5,6,0], [0,0,0,0,0,0,0,0,0,0,0,0], [10,1,8,11,7,5,6,4,2,9,0,3], [5,3,2,1,4,0]],40 "l'": [[2,0,0,1,1,0,0,2], [4,1,2,0,7,5,6,3], [1,0,1,0,0,0,0,0,1,0,1,0], [8,1,0,4,11,5,6,3,10,9,2,7], [3,0,2,5,4,1]],41 "b" : [[1,2,0,0,2,1,0,0], [4,0,2,3,5,1,6,7], [1,1,0,1,1,1,0,0,1,1,0,1], [4,3,2,11,8,0,6,7,5,1,10,9], [4,1,0,3,5,2]],42 "b2": [[0,0,0,0,0,0,0,0], [5,4,2,3,1,0,6,7], [0,0,0,0,0,0,0,0,0,0,0,0], [8,11,2,9,5,4,6,7,0,3,10,1], [5,1,4,3,2,0]],43 "b'": [[1,2,0,0,2,1,0,0], [1,5,2,3,0,4,6,7], [1,1,0,1,1,1,0,0,1,1,0,1], [5,9,2,1,0,8,6,7,4,11,10,3], [2,1,5,3,0,4]],44 "d" : [[0,0,0,0,0,0,0,0], [0,1,2,3,7,4,5,6], [0,0,0,0,1,1,1,1,0,0,0,0], [0,1,2,3,7,4,5,6,11,8,9,10], [0,2,3,4,1,5]],45 "d2": [[0,0,0,0,0,0,0,0], [0,1,2,3,6,7,4,5], [0,0,0,0,0,0,0,0,0,0,0,0], [0,1,2,3,6,7,4,5,10,11,8,9], [0,3,4,1,2,5]],46 "d'": [[0,0,0,0,0,0,0,0], [0,1,2,3,5,6,7,4], [0,0,0,0,1,1,1,1,0,0,0,0], [0,1,2,3,5,6,7,4,9,10,11,8], [0,4,1,2,3,5]],47 "x" : [[2,1,2,1, 1,2,1,2], [4,5,1,0, 7,6,2,3], [1,0,1,0,0,0,0,0,1,0,1,0], [8,5,0,4,11,9,1,3,10,6,2,7], [3,0,2,5,4,1]], 48 "x2": [[0,0,0,0, 0,0,0,0], [7,6,5,4, 3,2,1,0], [0,0,0,0,0,0,0,0,0,0,0,0], [10,9,8,11,7,6,5,4,2,1,0,3], [5,3,2,1,4,0]], 49 "x'": [[2,1,2,1, 1,2,1,2], [3,2,6,7, 0,1,5,4], [1,0,1,0,0,0,0,0,1,0,1,0], [2,6,10,7,3,1,9,11,0,5,8,4], [1,5,2,0,4,3]],50 "y" : [[0,0,0,0,0,0,0,0], [1,2,3,0,5,6,7,4], [0,0,0,0,1,1,1,1,0,0,0,0], [1,2,3,0,5,6,7,4,9,10,11,8], [0,4,1,2,3,5]], 51 "y2": [[0,0,0,0,0,0,0,0], [2,3,0,1,6,7,4,5], [0,0,0,0,0,0,0,0,0,0,0,0], [2,3,0,1,6,7,4,5,10,11,8,9], [0,3,4,1,2,5]], 52 "y'": [[0,0,0,0,0,0,0,0], [3,0,1,2,7,4,5,6], [0,0,0,0,1,1,1,1,0,0,0,0], [3,0,1,2,7,4,5,6,11,8,9,10], [0,2,3,4,1,5]],53 "z" : [[1,2,1,2,2,1,2,1], [1,5,6,2,0,4,7,3], [1,1,1,1,1,1,1,1,1,1,1,1], [5,9,6,1,0,8,10,2,4,11,7,3], [2,1,5,3,0,4]],54 "z2": [[0,0,0,0,0,0,0,0], [5,4,7,6,1,0,3,2], [0,0,0,0,0,0,0,0,0,0,0,0], [8,11,10,9,5,4,7,6,0,3,2,1], [5,1,4,3,2,0]],55 "z'": [[1,2,1,2,2,1,2,1], [4,0,3,7,5,1,2,6], [1,1,1,1,1,1,1,1,1,1,1,1], [4,3,7,11,8,0,2,10,5,1,6,9], [4,1,0,3,5,2]]56};57var moveAxes = {58 "U" : 0, "U2": 0, "U'": 0,59 "R" : 1, "R2": 1, "R'": 1, 60 "F" : 2, "F2": 2, "F'": 2, 61 "L" : 1, "L2": 1, "L'": 1, 62 "D" : 0, "D2": 0, "D'": 0, 63 "B" : 2, "B2": 2, "B'": 2,64 "M" : 1, "M2": 1, "M'": 1, 65 "E" : 0, "E2": 0, "E'": 0,66 "S" : 2, "S2": 2, "S'": 2,67 "u" : 0, "u2": 0, "u'": 0,68 "r" : 1, "r2": 1, "r'": 1, 69 "f" : 2, "f2": 2, "f'": 2,70 "l" : 1, "l2": 1, "l'": 1,71 "b" : 2, "b2": 2, "b'": 2,72 "d" : 0, "d2": 0, "d'": 0,73 "x" : 1, "x2": 1, "x'": 1,74 "y" : 0, "y2": 0, "y'": 0,75 "z" : 2, "z2": 2, "z'": 2 76};77var trivialFollowSet = {78 "U" : 0, "U2": 0, "U'": 0,79 "R" : 1, "R2": 1, "R'": 1, 80 "F" : 2, "F2": 2, "F'": 2, 81 "L" : 3, "L2": 3, "L'": 3, 82 "D" : 4, "D2": 4, "D'": 4, 83 "B" : 5, "B2": 5, "B'": 5,84 "M" : 6, "M2": 6, "M'": 6, 85 "E" : 7, "E2": 7, "E'": 7,86 "S" : 8, "S2": 8, "S'": 8,87 "u" : 9, "u2": 9, "u'": 9,88 "r" : 10, "r2": 10, "r'": 10, 89 "f" : 11, "f2": 11, "f'": 11,90 "l" : 12, "l2": 12, "l'": 12,91 "b" : 13, "b2": 13, "b'": 13,92 "d" : 14, "d2": 14, "d'": 14,93 "x" : 15, "x2": 15, "x'": 15,94 "y" : 16, "y2": 16, "y'": 16,95 "z" : 17, "z2": 17, "z'": 1796};97var isTrivialMove = function (move, moveset) {98 for (let i=moveset.length-1; i>=0; i--) {99 if (moveAxes[moveset[i]] === moveAxes[move]) {100 if (trivialFollowSet[moveset[i]] >= trivialFollowSet[move]) {101 return true; // Trivial turn102 }103 } 104 else { 105 return false; // Preceded by turn on a different axis106 }107 } 108 return false; // No trivial turns109};110var isAllowedMove = function (move, moveset) {111 if (isTrivialMove(move, moveset)) {112 return false;113 }114 if (maxMoveNumbers[move]<0) {115 return true;116 }117 count = 0;118 for (let i=moveset.length-1; i>=0; i--) {119 if (moveset[i] === move) {120 count++121 }122 if (count >= maxMoveNumbers[move]) {123 return false124 }125 } 126 return true; // No trivial turns127};128var applyRawMoveOrientation = function (oriState, moveOriEffect, movePermEffect, nOrientations) {129 let newState = applyRawMovePermutation(oriState, movePermEffect);130 for (let i=0; i < moveOriEffect.length; i++) {131 newState[i] = (newState[i] + moveOriEffect[i]) % nOrientations;132 } 133 return newState;134};135var applyRawMovePermutation = function (permState, movePermEffect) {136 let newState = permState.slice();137 for (let i=0; i < movePermEffect.length; i++) {138 newState[movePermEffect[i]] = permState[i];139 }140 return newState; 141};142var coord333HashFunction = {143 0: function (state) {144 // Corner orientation coordinate145 // Input is [CO]146 // Est size = 2,187147 let coord = 0;148 for (let i=0; i<7; i++) {149 // corner orientation of all but last corner150 coord = coord*3 + state[0][i];151 } 152 return coord;153 },154 1: function (state) {155 // Edge orientation coordinate156 // Input is [EO]157 // Est size = 2,048158 let coord = 0;159 for (let i=0; i<11; i++) {160 // edge orientation of all but last edge161 coord = coord*2 + state[0][i];162 }163 return coord;164 },165 2: function (state) {166 // Corner Permutation167 // Input is [CP]168 // Est size = 40,320169 let coord = 0;170 for (let i=0; i<8; i++) {171 // corner permutation172 coord = coord*9 + state[0][i];173 } 174 return coord;175 },176 3: function (state) {177 // Full orientation coordinate178 // Input is [CO, EO]179 // Est size = 4,478,976180 let coord = 0;181 for (let i=0; i<7; i++) {182 // corner orientation183 coord = coord*3 + state[0][i];184 }185 for (let i=0; i<11; i++) {186 // edge orientation187 coord = coord*2 + state[1][i];188 }189 return coord;190 },191 4: function (state) {192 // Full corner coordinate193 // Input is [CO, CP]194 // Est size = 11,022,480195 let coord = 0;196 for (let i=0; i<7; i++) {197 // corner orientation of all but last corner198 coord = coord*3 + state[0][i];199 }200 for (let i=0; i<7; i++) {201 // home position of corner in each position202 coord = coord*9 + state[1][i];203 } 204 return coord;205 },206 5: function (state) {207 // First four edge coordinate (U edges)208 // Input is [EO, EP]209 // Est size = 190,080210 let coord = 0;211 for (let i=0; i<12; i++) {212 // For each position, if the edge is one of the 4 edges213 coord *= 26;214 if (state[1][i] <= 4) {215 // Encode the position and orientation of the edge216 coord += state[1][i]*2 + state[0][i]; 217 }218 } 219 return coord;220 },221 6: function (state) {222 // Second four edge coordinate (E edges)223 // Input is [EO, EP]224 // Est size = 190,080225 let coord = 0;226 for (let i=0; i<12; i++) {227 // For each position, if the edge is one of the 4 edges228 coord *= 26;229 if (state[1][i] > 4 && state[1][i] <= 8) {230 // Encode the position and orientation of the edge231 coord += state[1][i]*2 + state[0][i]; 232 }233 } 234 return coord;235 },236 7: function (state) {237 // Third four edge coordinate (D edges)238 // Input is [EO, EP]239 // Est size = 190,080240 let coord = 0;241 for (let i=0; i<12; i++) {242 // For each position, if the edge is one of the 4 edges243 coord *= 26;244 if (state[1][i] > 8) {245 // Encode the position and orientation of the edge246 coord += state[1][i]*2 + state[0][i]; 247 }248 } 249 return coord;250 }, 251 8: function (state) {252 // Full centre coordinate253 // Input is [centres]254 // Est size = 24255 let coord = 0;256 for (let i=0; i<5; i++) {257 // positions of 5 of the centres258 coord = coord*7 + state[0][i];259 } 260 return coord;261 },262 9: function (state) {263 // First four edge position coordinate 264 // Input is [EP]265 // Est size = 11,880266 let coord = 0;267 for (let i=0; i<12; i++) {268 // For each position, if the edge is one of the 4 edges269 coord *= 13;270 if (state[0][i] <= 4) {271 // Encode the position and orientation of the edge272 coord += state[0][i]; 273 }274 } 275 return coord;276 },277 10: function (state) {278 // Second four edge position coordinate 279 // Input is [EP]280 // Est size = 11,880281 let coord = 0;282 for (let i=0; i<12; i++) {283 // For each position, if the edge is one of the 4 edges284 coord *= 13;285 if (state[0][i] > 4 && state[0][i] <= 8) {286 // Encode the position and orientation of the edge287 coord += state[0][i]; 288 }289 } 290 return coord;291 },292 11: function (state) {293 // Third four edge position coordinate 294 // Input is [EP]295 // Est size = 11,880296 let coord = 0;297 for (let i=0; i<12; i++) {298 // For each position, if the edge is one of the 4 edges299 coord *= 13;300 if (state[0][i] > 8) {301 // Encode the position and orientation of the edge302 coord += state[0][i]; 303 }304 } 305 return coord;306 },307 12: function (state) {308 // Second four corner position coordinate 309 // Input is [CP]310 // Est size = 1,680311 let coord = 0;312 for (let i=0; i<8; i++) {313 // For each position, if the corner is one of the 4 corners314 coord *= 9;315 if (state[0][i] <= 4) {316 // Encode the position and orientation of the corner317 coord += state[0][i]; 318 }319 } 320 return coord;321 },322 13: function (state) {323 // Second four corner position coordinate 324 // Input is [CP]325 // Est size = 1,680326 let coord = 0;327 for (let i=0; i<8; i++) {328 // For each position, if the corner is one of the 4 corners329 coord *= 9;330 if (state[0][i] > 4) {331 // Encode the position and orientation of the corner332 coord += state[0][i]; 333 }334 } 335 return coord;336 }337};338var coord333RawStateMap = {339 0: function (state) {340 // Corner orientation coordinate341 // Output is [CO]342 return [state[0]];343 },344 1: function (state) {345 // Edge orientation coordinate346 // Output is [EO]347 return [state[2]];348 },349 2: function (state) {350 // Corner permutation coordinate351 // Output is [CP]352 return [state[1]];353 },354 3: function (state) {355 // Full orientation coordinate356 // Output is [CO, EO]357 return [state[0], state[2]];358 },359 4: function (state) {360 // Full corner coordinate361 // Output is [CO, CP]362 return [state[0], state[1]];363 },364 5: function (state) {365 // First four edge coordinate (U edges)366 // Output is [EO, EP]367 return [state[2], state[3]];368 },369 6: function (state) {370 // Second four edge coordinate (E edges)371 // Output is [EO, EP]372 return [state[2], state[3]];373 },374 7: function (state) {375 // Third four edge coordinate (D edges)376 // Output is [EO, EP]377 return [state[2], state[3]];378 },379 8: function (state) {380 // Full centre coordinate381 // Output is [centres]382 return [state[4]];383 },384 9: function (state) {385 // First four edge position coordinate 386 // Input is [EP]387 return [state[3]];388 },389 10: function (state) {390 // Second four edge position coordinate 391 // Input is [EP]392 return [state[3]];393 },394 11: function (state) {395 // Third four edge position coordinate 396 // Input is [EP]397 return [state[3]];398 },399 12: function (state) {400 // First four corner position coordinate 401 // Input is [CP]402 return [state[1]];403 },404 13: function (state) {405 // Second four corner position coordinate 406 // Input is [CP]407 return [state[1]];408 }409};410var coord333MoveFunction = {411 0: function (state, move) {412 // Corner orientation coordinate413 // Input is [CO]414 return [415 applyRawMoveOrientation(state[0], move[0], move[1], 3),416 ];417 },418 1: function (state, move) {419 // Edge orientation coordinate420 // Input is [EO]421 return [422 applyRawMoveOrientation(state[0], move[2], move[3], 2),423 ];424 },425 2: function (state, move) {426 // Corner permutation coordinate427 // Output is [CP]428 return [429 applyRawMovePermutation(state[0], move[1])430 ];431 },432 3: function (state, move) {433 // Full orientation coordinate434 // Input is [CO, EO]435 return [436 applyRawMoveOrientation(state[0], move[0], move[1], 3),437 applyRawMoveOrientation(state[1], move[2], move[3], 2)438 ];439 }, 440 4: function (state, move) {441 // Full corner coordinate442 // Input is [CO, CP]443 return [444 applyRawMoveOrientation(state[0], move[0], move[1], 3),445 applyRawMovePermutation(state[1], move[1])446 ];447 },448 5: function (state, move) {449 // First four edge coordinate (U edges)450 // Input is [EO, EP]451 return [452 applyRawMoveOrientation(state[0], move[2], move[3], 2),453 applyRawMovePermutation(state[1], move[3])454 ];455 },456 6: function (state, move) {457 // Second four edge coordinate (E edges)458 // Input is [EO, EP]459 return [460 applyRawMoveOrientation(state[0], move[2], move[3], 2),461 applyRawMovePermutation(state[1], move[3])462 ];463 },464 7: function (state, move) {465 // Third four edge coordinate (D edges)466 // Input is [EO, EP]467 return [468 applyRawMoveOrientation(state[0], move[2], move[3], 2),469 applyRawMovePermutation(state[1], move[3])470 ];471 },472 8: function (state, move) {473 // Full centre coordinate474 // Input is [centres]475 return [476 applyRawMovePermutation(state[0], move[4])477 ];478 },479 9: function (state, move) {480 // First four edge position coordinate 481 // Input is [EP]482 return [483 applyRawMovePermutation(state[0], move[3])484 ];485 },486 10: function (state, move) {487 // Second four edge position coordinate 488 // Input is [EP]489 return [490 applyRawMovePermutation(state[0], move[3])491 ];492 },493 11: function (state, move) {494 // Third four edge position coordinate 495 // Input is [EP]496 return [497 applyRawMovePermutation(state[0], move[3])498 ];499 },500 12: function (state, move) {501 // First four corner position coordinate 502 // Input is [CP]503 return [504 applyRawMovePermutation(state[0], move[1])505 ];506 },507 13: function (state, move) {508 // Second four corner position coordinate 509 // Input is [CP]510 return [511 applyRawMovePermutation(state[0], move[1])512 ];513 }514};515var state2coord = function (coordIndex, state) {516 return coord333HashFunction[coordIndex](coord333RawStateMap[coordIndex](state))517};518var state2coordCombined = function (coordIndices, state) {519 return [state2coord(coordIndices[0], state),520 state2coord(coordIndices[1], state)]521};522var coord333Names = {523 0: "CO",524 1: "EO",525 2: "CP",526 3: "Orientation",527 4: "Corners",528 5: "Partial Edges - U layer",529 6: "Partial Edges - E slice",530 7: "Partial Edges - D layer",531 8: "Centres",532 9: "Partial EP - U layer",533 10: "Partial EP - E slice",534 11: "Partial EP - D layer",535 12: "Partial CP - U layer",536 13: "Partial CP - D layer"...

Full Screen

Full Screen

kociemba.js

Source:kociemba.js Github

copy

Full Screen

1"use strict";2var utils = require('./utils.js');3var nChooseK = utils.nChooseK;4var tic = utils.tic;5var toc = utils.toc;6var movesDef = {7 "U" : [[0,0,0,0, 0,0,0,0], [1,2,3,0, 4,5,6,7], [0,0,0,0, 0,0,0,0, 0,0,0,0], [1,2,3,0, 4,5,6,7, 8,9,10,11], [0,1,2,3,4,5]],8 "U2": [[0,0,0,0, 0,0,0,0], [2,3,0,1, 4,5,6,7], [0,0,0,0, 0,0,0,0, 0,0,0,0], [2,3,0,1, 4,5,6,7, 8,9,10,11], [0,1,2,3,4,5]],9 "U'": [[0,0,0,0, 0,0,0,0], [3,0,1,2, 4,5,6,7], [0,0,0,0, 0,0,0,0, 0,0,0,0], [3,0,1,2, 4,5,6,7, 8,9,10,11], [0,1,2,3,4,5]],10 "R" : [[0,1,2,0, 0,2,1,0], [0,5,1,3, 4,6,2,7], [0,0,0,0, 0,0,0,0, 0,0,0,0], [0,5,2,3, 4,9,1,7, 8,6,10,11], [0,1,2,3,4,5]],11 "R2": [[0,0,0,0, 0,0,0,0], [0,6,5,3, 4,2,1,7], [0,0,0,0, 0,0,0,0, 0,0,0,0], [0,9,2,3, 4,6,5,7, 8,1,10,11], [0,1,2,3,4,5]], 12 "R'": [[0,1,2,0, 0,2,1,0], [0,2,6,3, 4,1,5,7], [0,0,0,0, 0,0,0,0, 0,0,0,0], [0,6,2,3, 4,1,9,7, 8,5,10,11], [0,1,2,3,4,5]], 13 "F" : [[0,0,1,2, 0,0,2,1], [0,1,6,2, 4,5,7,3], [0,0,1,0, 0,0,1,1, 0,0,1,0], [0,1,6,3, 4,5,10,2, 8,9,7,11], [0,1,2,3,4,5]], 14 "F2": [[0,0,0,0, 0,0,0,0], [0,1,7,6, 4,5,3,2], [0,0,0,0, 0,0,0,0, 0,0,0,0], [0,1,10,3, 4,5,7,6, 8,9,2,11], [0,1,2,3,4,5]], 15 "F'": [[0,0,1,2, 0,0,2,1], [0,1,3,7, 4,5,2,6], [0,0,1,0, 0,0,1,1, 0,0,1,0], [0,1,7,3, 4,5,2,10, 8,9,6,11], [0,1,2,3,4,5]], 16 "L" : [[2,0,0,1, 1,0,0,2], [3,1,2,7, 0,5,6,4], [0,0,0,0, 0,0,0,0, 0,0,0,0], [0,1,2,7, 3,5,6,11, 8,9,10,4], [0,1,2,3,4,5]], 17 "L2": [[0,0,0,0, 0,0,0,0], [7,1,2,4, 3,5,6,0], [0,0,0,0, 0,0,0,0, 0,0,0,0], [0,1,2,11, 7,5,6,4, 8,9,10,3], [0,1,2,3,4,5]], 18 "L'": [[2,0,0,1, 1,0,0,2], [4,1,2,0, 7,5,6,3], [0,0,0,0, 0,0,0,0, 0,0,0,0], [0,1,2,4, 11,5,6,3, 8,9,10,7], [0,1,2,3,4,5]], 19 "D" : [[0,0,0,0, 0,0,0,0], [0,1,2,3, 7,4,5,6], [0,0,0,0, 0,0,0,0, 0,0,0,0], [0,1,2,3, 4,5,6,7, 11,8,9,10], [0,1,2,3,4,5]],20 "D2": [[0,0,0,0, 0,0,0,0], [0,1,2,3, 6,7,4,5], [0,0,0,0, 0,0,0,0, 0,0,0,0], [0,1,2,3, 4,5,6,7, 10,11,8,9], [0,1,2,3,4,5]], 21 "D'": [[0,0,0,0, 0,0,0,0], [0,1,2,3, 5,6,7,4], [0,0,0,0, 0,0,0,0, 0,0,0,0], [0,1,2,3, 4,5,6,7, 9,10,11,8], [0,1,2,3,4,5]], 22 "B" : [[1,2,0,0, 2,1,0,0], [4,0,2,3, 5,1,6,7], [1,0,0,0, 1,1,0,0, 1,0,0,0], [4,1,2,3, 8,0,6,7, 5,9,10,11], [0,1,2,3,4,5]], 23 "B2": [[0,0,0,0, 0,0,0,0], [5,4,2,3, 1,0,6,7], [0,0,0,0, 0,0,0,0, 0,0,0,0], [8,1,2,3, 5,4,6,7, 0,9,10,11], [0,1,2,3,4,5]], 24 "B'": [[1,2,0,0, 2,1,0,0], [1,5,2,3, 0,4,6,7], [1,0,0,0, 1,1,0,0, 1,0,0,0], [5,1,2,3, 0,8,6,7, 4,9,10,11], [0,1,2,3,4,5]],25 "M" : [[0,0,0,0,0,0,0,0], [0,1,2,3,4,5,6,7], [1,0,1,0,0,0,0,0,1,0,1,0], [2,1,10,3,4,5,6,7,0,9,8,11],[1,5,2,0,4,3]],26 "M2": [[0,0,0,0,0,0,0,0], [0,1,2,3,4,5,6,7], [0,0,0,0,0,0,0,0,0,0,0,0], [10,1,8,3,4,5,6,7,2,9,0,11],[5,3,2,1,4,0]], 27 "M'": [[0,0,0,0,0,0,0,0], [0,1,2,3,4,5,6,7], [1,0,1,0,0,0,0,0,1,0,1,0], [8,1,0,3,4,5,6,7,10,9,2,11],[3,0,2,5,4,1]], 28 "E" : [[0,0,0,0,0,0,0,0], [0,1,2,3,4,5,6,7], [0,0,0,0,1,1,1,1,0,0,0,0], [0,1,2,3,5,6,7,4,8,9,10,11], [0,4,1,2,3,5]],29 "E2": [[0,0,0,0,0,0,0,0], [0,1,2,3,4,5,6,7], [0,0,0,0,0,0,0,0,0,0,0,0], [0,1,2,3,6,7,4,5,8,9,10,11], [0,3,4,1,2,5]],30 "E'": [[0,0,0,0,0,0,0,0], [0,1,2,3,4,5,6,7], [0,0,0,0,1,1,1,1,0,0,0,0], [0,1,2,3,7,4,5,6,8,9,10,11], [0,2,3,4,1,5]],31 "S" : [[0,0,0,0,0,0,0,0], [0,1,2,3,4,5,6,7], [0,1,0,1,0,0,0,0,0,1,0,1], [0,9,2,1,4,5,6,7,8,11,10,3], [2,1,5,3,0,4]],32 "S2": [[0,0,0,0,0,0,0,0], [0,1,2,3,4,5,6,7], [0,0,0,0,0,0,0,0,0,0,0,0], [0,11,2,9,4,5,6,7,8,3,10,1], [5,1,4,3,2,0]],33 "S'": [[0,0,0,0,0,0,0,0], [0,1,2,3,4,5,6,7], [0,1,0,1,0,0,0,0,0,1,0,1], [0,3,2,11,4,5,6,7,8,1,10,9], [4,1,0,3,5,2]],34 "u" : [[0,0,0,0,0,0,0,0], [1,2,3,0,4,5,6,7], [0,0,0,0,1,1,1,1,0,0,0,0], [1,2,3,0,5,6,7,4,8,9,10,11], [0,4,1,2,3,5]],35 "u2": [[0,0,0,0,0,0,0,0], [2,3,0,1,4,5,6,7], [0,0,0,0,0,0,0,0,0,0,0,0], [2,3,0,1,6,7,4,5,8,9,10,11], [0,3,4,1,2,5]],36 "u'": [[0,0,0,0,0,0,0,0], [3,0,1,2,4,5,6,7], [0,0,0,0,1,1,1,1,0,0,0,0], [3,0,1,2,7,4,5,6,8,9,10,11], [0,2,3,4,1,5]],37 "r" : [[0,1,2,0,0,2,1,0], [0,5,1,3,4,6,2,7], [1,0,1,0,0,0,0,0,1,0,1,0], [8,5,0,3,4,9,1,7,10,6,2,11], [3,0,2,5,4,1]], 38 "r2": [[0,0,0,0,0,0,0,0], [0,6,5,3,4,2,1,7], [0,0,0,0,0,0,0,0,0,0,0,0], [10,9,8,3,4,6,5,7,2,1,0,11], [5,3,2,1,4,0]], 39 "r'": [[0,1,2,0,0,2,1,0], [0,2,6,3,4,1,5,7], [1,0,1,0,0,0,0,0,1,0,1,0], [2,6,10,3,4,1,9,7,0,5,8,11], [1,5,2,0,4,3]], 40 "f" : [[0,0,1,2,0,0,2,1], [0,1,6,2,4,5,7,3], [0,1,1,1,0,0,1,1,0,1,1,1], [0,9,6,1,4,5,10,2,8,11,7,3], [2,1,5,3,0,4]],41 "f2": [[0,0,0,0,0,0,0,0], [0,1,7,6,4,5,3,2], [0,0,0,0,0,0,0,0,0,0,0,0], [0,11,10,9,4,5,7,6,8,3,2,1], [5,1,4,3,2,0]],42 "f'": [[0,0,1,2,0,0,2,1], [0,1,3,7,4,5,2,6], [0,1,1,1,0,0,1,1,0,1,1,1], [0,3,7,11,4,5,2,10,8,1,6,9], [4,1,0,3,5,2]],43 "l" : [[2,0,0,1,1,0,0,2], [3,1,2,7,0,5,6,4], [1,0,1,0,0,0,0,0,1,0,1,0], [2,1,10,7,3,5,6,11,0,9,8,4], [1,5,2,0,4,3]],44 "l2": [[0,0,0,0,0,0,0,0], [7,1,2,4,3,5,6,0], [0,0,0,0,0,0,0,0,0,0,0,0], [10,1,8,11,7,5,6,4,2,9,0,3], [5,3,2,1,4,0]],45 "l'": [[2,0,0,1,1,0,0,2], [4,1,2,0,7,5,6,3], [1,0,1,0,0,0,0,0,1,0,1,0], [8,1,0,4,11,5,6,3,10,9,2,7], [3,0,2,5,4,1]],46 "b" : [[1,2,0,0,2,1,0,0], [4,0,2,3,5,1,6,7], [1,1,0,1,1,1,0,0,1,1,0,1], [4,3,2,11,8,0,6,7,5,1,10,9], [4,1,0,3,5,2]],47 "b2": [[0,0,0,0,0,0,0,0], [5,4,2,3,1,0,6,7], [0,0,0,0,0,0,0,0,0,0,0,0], [8,11,2,9,5,4,6,7,0,3,10,1], [5,1,4,3,2,0]],48 "b'": [[1,2,0,0,2,1,0,0], [1,5,2,3,0,4,6,7], [1,1,0,1,1,1,0,0,1,1,0,1], [5,9,2,1,0,8,6,7,4,11,10,3], [2,1,5,3,0,4]],49 "d" : [[0,0,0,0,0,0,0,0], [0,1,2,3,7,4,5,6], [0,0,0,0,1,1,1,1,0,0,0,0], [0,1,2,3,7,4,5,6,11,8,9,10], [0,2,3,4,1,5]],50 "d2": [[0,0,0,0,0,0,0,0], [0,1,2,3,6,7,4,5], [0,0,0,0,0,0,0,0,0,0,0,0], [0,1,2,3,6,7,4,5,10,11,8,9], [0,3,4,1,2,5]],51 "d'": [[0,0,0,0,0,0,0,0], [0,1,2,3,5,6,7,4], [0,0,0,0,1,1,1,1,0,0,0,0], [0,1,2,3,5,6,7,4,9,10,11,8], [0,4,1,2,3,5]],52 "x" : [[2,1,2,1, 1,2,1,2], [4,5,1,0, 7,6,2,3], [1,0,1,0,0,0,0,0,1,0,1,0], [8,5,0,4,11,9,1,3,10,6,2,7], [3,0,2,5,4,1]], 53 "x2": [[0,0,0,0, 0,0,0,0], [7,6,5,4, 3,2,1,0], [0,0,0,0,0,0,0,0,0,0,0,0], [10,9,8,11,7,6,5,4,2,1,0,3], [5,3,2,1,4,0]], 54 "x'": [[2,1,2,1, 1,2,1,2], [3,2,6,7, 0,1,5,4], [1,0,1,0,0,0,0,0,1,0,1,0], [2,6,10,7,3,1,9,11,0,5,8,4], [1,5,2,0,4,3]],55 "y" : [[0,0,0,0,0,0,0,0], [1,2,3,0,5,6,7,4], [0,0,0,0,1,1,1,1,0,0,0,0], [1,2,3,0,5,6,7,4,9,10,11,8], [0,4,1,2,3,5]], 56 "y2": [[0,0,0,0,0,0,0,0], [2,3,0,1,6,7,4,5], [0,0,0,0,0,0,0,0,0,0,0,0], [2,3,0,1,6,7,4,5,10,11,8,9], [0,3,4,1,2,5]], 57 "y'": [[0,0,0,0,0,0,0,0], [3,0,1,2,7,4,5,6], [0,0,0,0,1,1,1,1,0,0,0,0], [3,0,1,2,7,4,5,6,11,8,9,10], [0,2,3,4,1,5]],58 "z" : [[1,2,1,2,2,1,2,1], [1,5,6,2,0,4,7,3], [1,1,1,1,1,1,1,1,1,1,1,1], [5,9,6,1,0,8,10,2,4,11,7,3], [2,1,5,3,0,4]],59 "z2": [[0,0,0,0,0,0,0,0], [5,4,7,6,1,0,3,2], [0,0,0,0,0,0,0,0,0,0,0,0], [8,11,10,9,5,4,7,6,0,3,2,1], [5,1,4,3,2,0]],60 "z'": [[1,2,1,2,2,1,2,1], [4,0,3,7,5,1,2,6], [1,1,1,1,1,1,1,1,1,1,1,1], [4,3,7,11,8,0,2,10,5,1,6,9], [4,1,0,3,5,2]],61 62 "RLmirror": [[0,0,0,0,0,0,0,0], [1,0,3,2,5,4,7,6], [0,0,0,0,0,0,0,0,0,0,0,0], [0,3,2,1,5,4,7,6,8,11,10,9], [0,3,4,1,2,5]]63 // Not a real move, but useful for symmetry reductions64};65var moveAxes = {66 "U" : 0, "U2": 0, "U'": 0,67 "R" : 1, "R2": 1, "R'": 1, 68 "F" : 2, "F2": 2, "F'": 2, 69 "L" : 1, "L2": 1, "L'": 1, 70 "D" : 0, "D2": 0, "D'": 0, 71 "B" : 2, "B2": 2, "B'": 2,72 "M" : 1, "M2": 1, "M'": 1, 73 "E" : 0, "E2": 0, "E'": 0,74 "S" : 2, "S2": 2, "S'": 2,75 "u" : 0, "u2": 0, "u'": 0,76 "r" : 1, "r2": 1, "r'": 1, 77 "f" : 2, "f2": 2, "f'": 2,78 "l" : 1, "l2": 1, "l'": 1,79 "b" : 2, "b2": 2, "b'": 2,80 "d" : 0, "d2": 0, "d'": 0,81 "x" : 1, "x2": 1, "x'": 1,82 "y" : 0, "y2": 0, "y'": 0,83 "z" : 2, "z2": 2, "z'": 2 84};85/* 86Any naive search will search sequences containing consecutive moves on the same axis. 87If for example, one such sequence contains the sequence R L, then there is no point in88performing a search with L R, as the resulting state will be identical. The following89defines a hierarchy which specifies an arbitrarily chosen order to avoid searching 90duplicate move sequences.91*/92var trivialFollowSet = {93 "U" : 0, "U2": 0, "U'": 0,94 "R" : 1, "R2": 1, "R'": 1, 95 "F" : 2, "F2": 2, "F'": 2, 96 "L" : 3, "L2": 3, "L'": 3, 97 "D" : 4, "D2": 4, "D'": 4, 98 "B" : 5, "B2": 5, "B'": 5,99 "M" : 6, "M2": 6, "M'": 6, 100 "E" : 7, "E2": 7, "E'": 7,101 "S" : 8, "S2": 8, "S'": 8,102 "u" : 9, "u2": 9, "u'": 9,103 "r" : 10, "r2": 10, "r'": 10, 104 "f" : 11, "f2": 11, "f'": 11,105 "l" : 12, "l2": 12, "l'": 12,106 "b" : 13, "b2": 13, "b'": 13,107 "d" : 14, "d2": 14, "d'": 14,108 "x" : 15, "x2": 15, "x'": 15,109 "y" : 16, "y2": 16, "y'": 16,110 "z" : 17, "z2": 17, "z'": 17111};112var isTrivialMove = function (move, moveset) {113 // A move is trivial if it is preceded by the same type or a more dominant move 114 // on the same axis (see trivialFollowSet) 115 116 for (let i=moveset.length-1; i>=0; i--) {117 if (moveAxes[moveset[i]] === moveAxes[move]) {118 if (trivialFollowSet[moveset[i]] >= trivialFollowSet[move]) {119 return true; // Trivial turn120 }121 } 122 else { 123 return false; // Preceded by turn on a different axis124 }125 } 126 return false; // No trivial turns127};128var applyMoveCP = function (move, cpstate) {129 130 let moveCP = movesDef[move][1]; 131 let newState = cpstate.slice(); 132 for (let i=0; i < moveCP.length; i++) {133 newState[moveCP[i]] = cpstate[i];134 } 135 136 return newState; 137};138var applyMoveEP = function (move, epstate) {139 140 let moveEP = movesDef[move][3]; 141 let newState = epstate.slice(); 142 for (let i=0; i < moveEP.length; i++) {143 newState[moveEP[i]] = epstate[i];144 } 145 146 return newState; 147};148var applyMoveCentr = function (move, centrstate) {149 150 let moveCentr = movesDef[move][4]; 151 let newState = centrstate.slice();152 for (let i=0; i < moveCentr.length; i++) {153 newState[moveCentr[i]] = centrstate[i];154 } 155 156 return newState; 157};158var applyMoveCO = function (move, costate) {159 160 let moveCO = movesDef[move][0]; 161 let newState = applyMoveCP(move, costate); 162 163 for (let i=0; i < moveCO.length; i++) {164 newState[i] = (newState[i] + moveCO[i]) % 3;165 } 166 167 return newState;168};169var applyMoveEO = function (move, eostate) {170 171 let moveEO = movesDef[move][2]; 172 let newState = applyMoveEP(move, eostate); 173 174 for (let i=0; i < moveEO.length; i++) {175 newState[i] = (newState[i] + moveEO[i]) % 2;176 } 177 178 return newState;179};180//=======================================================================================181/*182Phase 1 simple coordinates183Three simple coordinates are used : CornerTwist, EdgeFlip and a ESlice coord184These specify the corner orientation, the edge orientation and the location 185of the four edges that belong on the E slice. 186These coordinates may be reduced using symmetry.187Adapted from: http://kociemba.org/math/twophase.htm188*/189var getCoordCornTwist = function (state) {190 // Corner orientation coordinate191 // Integer from 0 to 2186192 193 let coord = 0;194 for (let i=0; i<7; i++) {195 // corner orientation of all but last corner196 coord = coord*3 + state[i];197 } 198 return coord;199};200var getCoordEdgeFlip = function (state) {201 // Edge orientation coordinate202 // Integer from 0 to 2047203 204 let coord = 0;205 for (let i=0; i<11; i++) {206 // edge orientation of all but last corner207 coord = coord*2 + state[i];208 } 209 return coord;210};211var getCoordESlice = function (state) {212 // Permutation of the four E slice 213 // Integer from 0 to 494214 215 let coord = 0;216 217 let occupied = 0218 // Loop through in a custom order.219 // The four correct locations come last so that the coordinate of the solved state is 0220 let order = [0,1,2,3,8,9,10,11,4,5,6,7]; 221 for (let idx=0; idx<order.length; idx++) {222 let i = order[idx];223 if (state[i]>=5 && state[i]<=8) {224 occupied++; 225 }226 else if (occupied) {227 coord += nChooseK(idx, occupied-1);228 }229 } 230 return coord;231};232//---------------------------------------------------------------------------------------233/*234Inverses of the above four coordinates235*/236var invertCoordCornTwist =function (coord) {237 // Inverse function for corner orientation coordinate238 239 let state = new Array(8).fill(0);240 let temp = coord;241 let last = 15; // Smallest multiple of 3 such that (last >= 2*7)242 for (let i=6; i>=0; i--) {243 state[i] = temp % 3;244 last -= state[i];245 temp = Math.floor(temp / 3);246 }247 // Last corner is set such that the sum mod 3 is zero.248 state[7] = last % 3;249 return state250}251var invertCoordEdgeFlip =function (coord) {252 // Inverse function for edge orientation253 254 let state = new Array(12).fill(0);255 let temp = coord;256 let last = 12; // Smallest multiple of 2 such that (last >= 1*11)257 for (let i=10; i>=0; i--) {258 state[i] = temp % 2;259 last -= state[i];260 temp = Math.floor(temp / 2);261 }262 // Last edge is set such that the sum mod 2 is zero.263 state[11] = last % 2;264 return state265}266var invertCoordESlice = function (coord) {267 // Inverse function for permutation of the four E slice edges268 269 let state = new Array(12).fill(0);270 271 let tempCoord = coord;272 let nEdgesLeft = 4;273 274 let nextEdge = 8; // Count down since loop goes backward: 8,7,6,5275 276 let order = [0,1,2,3,8,9,10,11,4,5,6,7]; // E slice edges come last277 278 for (let idx=0; idx<order.length; idx++) {279 if (tempCoord >= nChooseK(11-idx, nEdgesLeft-1)) {280 tempCoord -= nChooseK(11-idx, nEdgesLeft-1);281 }282 else {283 state[order[11-idx]] = (nextEdge--);284 nEdgesLeft--;285 }286 if (nEdgesLeft === 0) {287 break;288 }289 290 }291 return state;292};293//=======================================================================================294/*295Phase 1 Move Tables296Functions for constructing move tables for each coordinate. 297*/298// Constants299const nCornTwist = 2187;300const nEdgeFlip = 2048;301const nESlice = 495;302//---------------------------------------------------------------------------------------303var buildCornerTwistMoveTable = function (move) {304 let moveTable = new Array(nCornTwist).fill(0);305 306 for (let coord=0; coord<nCornTwist; coord++) {307 let state = applyMoveCO(move, invertCoordCornTwist(coord)); 308 moveTable[coord] = getCoordCornTwist(state);309 }310 return moveTable;311};312var buildEdgeFlipMoveTable = function (move) {313 let moveTable = new Array(nEdgeFlip).fill(0);314 315 for (let coord=0; coord<nEdgeFlip; coord++) {316 let state = applyMoveEO(move, invertCoordEdgeFlip(coord)); 317 moveTable[coord] = getCoordEdgeFlip(state);318 }319 return moveTable;320};321var buildESliceMoveTable = function (move) {322 let moveTable = new Array(nESlice).fill(0);323 324 for (let coord=0; coord<nESlice; coord++) {325 let state = applyMoveEP(move, invertCoordESlice(coord)); 326 moveTable[coord] = getCoordESlice(state);327 }328 return moveTable;329};330//---------------------------------------------------------------------------------------331var buildTableForAllMoves = function (allowedMoves, tableFunction) {332 // Builds a move table for each of the move. allowedMoves is a list of moves333 // and tableFunction is a function which constructs the move table.334 let moveTables = {};335 for (let m in allowedMoves) {336 let move = allowedMoves[m];337 moveTables[move] = tableFunction(move);338 }339 return moveTables;340};341var phase1AllowedMoves = ["R","R'","R2","U","U'","U2","F","F'","F2","D","D'","D2","L","L'","L2","B","B'","B2"];342// Add some extra moves. These take up a little extra space in the move tables, 343// but make it easier and faster to calculate sym coordinates344var extendedAllowedMoves = phase1AllowedMoves.concat(['y', 'z2', 'RLmirror']);345// Build all three move tables for phase 1346var moveTableCornerTwist = buildTableForAllMoves(extendedAllowedMoves, buildCornerTwistMoveTable);347var moveTableEdgeFlip = buildTableForAllMoves(extendedAllowedMoves, buildEdgeFlipMoveTable);348var moveTableESlice = buildTableForAllMoves(extendedAllowedMoves, buildESliceMoveTable);349//=======================================================================================350/*351Symmetry reductions.352Coordinates can be reduced using symmetry.353The three symmetry transformations used are: y, z2, and RLmirror.354*/355var buildSymmetryMoveTable = function (allowedMoves, nCoordSize, moveTable) {356 let nextSymCoord = 0;357 358 let newMoveTable = 0;359 360 for (let i=0; i<nCoordSize; i++) {361 362 }363}364var getPhase1SymCoordMapTables = function (moveTables) {365 // Generate mapping tables to take raw EO and EsliceEdge coordinates to366 // a combined coordinate that is reduced by symmetry.367 368 let nextSymCoord = 0;369 let symCoordMap = [];//new Array(nPhase1Edges).fill(0);370 let symCoordInvMap = new Array(nEdgeFlip * nESliceEdgePerm).fill(0);371 372 let l = new Array(17).fill(0);373 374 for (let rawCoord=0; rawCoord < (nEdgeFlip * nESliceEdgePerm); rawCoord++) {375 let eoCoord = (rawCoord % nEdgeFlip);376 let eepCoord = Math.floor(rawCoord / nEdgeFlip);377// console.log(' Start', eoCoord, eepCoord)378 let rawStates = [];379 380 // For each type of symmetry, calculate the state reached381 // and populate the mapping tables382 let alreadyVisited = false;383 384 let newRawCoord = 0;385 386// console.log('start', rawCoord)387 388 for (let i=0; i<2; i++) { 389 390 if (alreadyVisited) break;391 392 eoCoord = moveTables[1]['RLmirror'][eoCoord];393 eepCoord = moveTables[2]['RLmirror'][eepCoord];394 for (let j=0; j<2; j++) {395 if (alreadyVisited) break;396 eoCoord = moveTables[1]['z2'][eoCoord];397 eepCoord = moveTables[2]['z2'][eepCoord];398 for (let k=0; k<4; k++) {399 400 if (alreadyVisited) break;401 402 eoCoord = moveTables[1]['y'][eoCoord];403 eepCoord = moveTables[2]['y'][eepCoord];404 newRawCoord = (eepCoord * nEdgeFlip) + eoCoord;405 406// console.log('', i,j,k,'--',rawCoord, '=>', newRawCoord, ' \tEO',eoCoord,'EP',eepCoord)407 408 if (newRawCoord < rawCoord) {409 alreadyVisited = true;410 break;411 }412 413 rawStates.push(newRawCoord); 414// console.log(rawCoord, newRawCoord);415 416 }417 }418 }419 420// console.log('end', newRawCoord)421 422 if (alreadyVisited) {423 continue;424 }425 426// let nUniqueSymmStates = 1;427// 428// for (let j=1; j<rawStates.length; j++) {429// if (rawStates[0] === rawStates[j]) {430// nUniqueSymmStates++;431// }432// }433// l[16/nUniqueSymmStates]++;434 435 for (let i=0; i<rawStates.length; i++) { 436 symCoordInvMap[rawStates[i]] = nextSymCoord; 437 }438 439 symCoordMap[nextSymCoord] = rawCoord;440 441 nextSymCoord++;442 443 }444 445// console.log(nEdgeOri * nESliceEdgePerm);446// console.log(nextSymCoord);447// console.log(64430);448// console.log(l);449 450// console.log(symCoordMap.length, symCoordInvMap.length)451 452 return [symCoordMap, symCoordInvMap];...

Full Screen

Full Screen

moves.js

Source:moves.js Github

copy

Full Screen

1var movesDef = {2 "U" : [[0,0,0,0, 0,0,0,0], [1,2,3,0, 4,5,6,7], [0,0,0,0, 0,0,0,0, 0,0,0,0], [1,2,3,0, 4,5,6,7, 8,9,10,11], [0,1,2,3,4,5]],3 "U2": [[0,0,0,0, 0,0,0,0], [2,3,0,1, 4,5,6,7], [0,0,0,0, 0,0,0,0, 0,0,0,0], [2,3,0,1, 4,5,6,7, 8,9,10,11], [0,1,2,3,4,5]],4 "U'": [[0,0,0,0, 0,0,0,0], [3,0,1,2, 4,5,6,7], [0,0,0,0, 0,0,0,0, 0,0,0,0], [3,0,1,2, 4,5,6,7, 8,9,10,11], [0,1,2,3,4,5]],5 "R" : [[0,1,2,0, 0,2,1,0], [0,5,1,3, 4,6,2,7], [0,0,0,0, 0,0,0,0, 0,0,0,0], [0,5,2,3, 4,9,1,7, 8,6,10,11], [0,1,2,3,4,5]],6 "R2": [[0,0,0,0, 0,0,0,0], [0,6,5,3, 4,2,1,7], [0,0,0,0, 0,0,0,0, 0,0,0,0], [0,9,2,3, 4,6,5,7, 8,1,10,11], [0,1,2,3,4,5]], 7 "R'": [[0,1,2,0, 0,2,1,0], [0,2,6,3, 4,1,5,7], [0,0,0,0, 0,0,0,0, 0,0,0,0], [0,6,2,3, 4,1,9,7, 8,5,10,11], [0,1,2,3,4,5]], 8 "F" : [[0,0,1,2, 0,0,2,1], [0,1,6,2, 4,5,7,3], [0,0,1,0, 0,0,1,1, 0,0,1,0], [0,1,6,3, 4,5,10,2, 8,9,7,11], [0,1,2,3,4,5]], 9 "F2": [[0,0,0,0, 0,0,0,0], [0,1,7,6, 4,5,3,2], [0,0,0,0, 0,0,0,0, 0,0,0,0], [0,1,10,3, 4,5,7,6, 8,9,2,11], [0,1,2,3,4,5]], 10 "F'": [[0,0,1,2, 0,0,2,1], [0,1,3,7, 4,5,2,6], [0,0,1,0, 0,0,1,1, 0,0,1,0], [0,1,7,3, 4,5,2,10, 8,9,6,11], [0,1,2,3,4,5]], 11 "L" : [[2,0,0,1, 1,0,0,2], [3,1,2,7, 0,5,6,4], [0,0,0,0, 0,0,0,0, 0,0,0,0], [0,1,2,7, 3,5,6,11, 8,9,10,4], [0,1,2,3,4,5]], 12 "L2": [[0,0,0,0, 0,0,0,0], [7,1,2,4, 3,5,6,0], [0,0,0,0, 0,0,0,0, 0,0,0,0], [0,1,2,11, 7,5,6,4, 8,9,10,3], [0,1,2,3,4,5]], 13 "L'": [[2,0,0,1, 1,0,0,2], [4,1,2,0, 7,5,6,3], [0,0,0,0, 0,0,0,0, 0,0,0,0], [0,1,2,4, 11,5,6,3, 8,9,10,7], [0,1,2,3,4,5]], 14 "D" : [[0,0,0,0, 0,0,0,0], [0,1,2,3, 7,4,5,6], [0,0,0,0, 0,0,0,0, 0,0,0,0], [0,1,2,3, 4,5,6,7, 11,8,9,10], [0,1,2,3,4,5]],15 "D2": [[0,0,0,0, 0,0,0,0], [0,1,2,3, 6,7,4,5], [0,0,0,0, 0,0,0,0, 0,0,0,0], [0,1,2,3, 4,5,6,7, 10,11,8,9], [0,1,2,3,4,5]], 16 "D'": [[0,0,0,0, 0,0,0,0], [0,1,2,3, 5,6,7,4], [0,0,0,0, 0,0,0,0, 0,0,0,0], [0,1,2,3, 4,5,6,7, 9,10,11,8], [0,1,2,3,4,5]], 17 "B" : [[1,2,0,0, 2,1,0,0], [4,0,2,3, 5,1,6,7], [1,0,0,0, 1,1,0,0, 1,0,0,0], [4,1,2,3, 8,0,6,7, 5,9,10,11], [0,1,2,3,4,5]], 18 "B2": [[0,0,0,0, 0,0,0,0], [5,4,2,3, 1,0,6,7], [0,0,0,0, 0,0,0,0, 0,0,0,0], [8,1,2,3, 5,4,6,7, 0,9,10,11], [0,1,2,3,4,5]], 19 "B'": [[1,2,0,0, 2,1,0,0], [1,5,2,3, 0,4,6,7], [1,0,0,0, 1,1,0,0, 1,0,0,0], [5,1,2,3, 0,8,6,7, 4,9,10,11], [0,1,2,3,4,5]],20 "M" : [[0,0,0,0,0,0,0,0], [0,1,2,3,4,5,6,7], [1,0,1,0,0,0,0,0,1,0,1,0], [2,1,10,3,4,5,6,7,0,9,8,11],[1,5,2,0,4,3]],21 "M2": [[0,0,0,0,0,0,0,0], [0,1,2,3,4,5,6,7], [0,0,0,0,0,0,0,0,0,0,0,0], [10,1,8,3,4,5,6,7,2,9,0,11],[5,3,2,1,4,0]], 22 "M'": [[0,0,0,0,0,0,0,0], [0,1,2,3,4,5,6,7], [1,0,1,0,0,0,0,0,1,0,1,0], [8,1,0,3,4,5,6,7,10,9,2,11],[3,0,2,5,4,1]], 23 "E" : [[0,0,0,0,0,0,0,0], [0,1,2,3,4,5,6,7], [0,0,0,0,1,1,1,1,0,0,0,0], [0,1,2,3,5,6,7,4,8,9,10,11], [0,4,1,2,3,5]],24 "E2": [[0,0,0,0,0,0,0,0], [0,1,2,3,4,5,6,7], [0,0,0,0,0,0,0,0,0,0,0,0], [0,1,2,3,6,7,4,5,8,9,10,11], [0,3,4,1,2,5]],25 "E'": [[0,0,0,0,0,0,0,0], [0,1,2,3,4,5,6,7], [0,0,0,0,1,1,1,1,0,0,0,0], [0,1,2,3,7,4,5,6,8,9,10,11], [0,2,3,4,1,5]],26 "S" : [[0,0,0,0,0,0,0,0], [0,1,2,3,4,5,6,7], [0,1,0,1,0,0,0,0,0,1,0,1], [0,9,2,1,4,5,6,7,8,11,10,3], [2,1,5,3,0,4]],27 "S2": [[0,0,0,0,0,0,0,0], [0,1,2,3,4,5,6,7], [0,0,0,0,0,0,0,0,0,0,0,0], [0,11,2,9,4,5,6,7,8,3,10,1], [5,1,4,3,2,0]],28 "S'": [[0,0,0,0,0,0,0,0], [0,1,2,3,4,5,6,7], [0,1,0,1,0,0,0,0,0,1,0,1], [0,3,2,11,4,5,6,7,8,1,10,9], [4,1,0,3,5,2]],29 "u" : [[0,0,0,0,0,0,0,0], [1,2,3,0,4,5,6,7], [0,0,0,0,1,1,1,1,0,0,0,0], [1,2,3,0,5,6,7,4,8,9,10,11], [0,4,1,2,3,5]],30 "u2": [[0,0,0,0,0,0,0,0], [2,3,0,1,4,5,6,7], [0,0,0,0,0,0,0,0,0,0,0,0], [2,3,0,1,6,7,4,5,8,9,10,11], [0,3,4,1,2,5]],31 "u'": [[0,0,0,0,0,0,0,0], [3,0,1,2,4,5,6,7], [0,0,0,0,1,1,1,1,0,0,0,0], [3,0,1,2,7,4,5,6,8,9,10,11], [0,2,3,4,1,5]],32 "r" : [[0,1,2,0,0,2,1,0], [0,5,1,3,4,6,2,7], [1,0,1,0,0,0,0,0,1,0,1,0], [8,5,0,3,4,9,1,7,10,6,2,11], [3,0,2,5,4,1]], 33 "r2": [[0,0,0,0,0,0,0,0], [0,6,5,3,4,2,1,7], [0,0,0,0,0,0,0,0,0,0,0,0], [10,9,8,3,4,6,5,7,2,1,0,11], [5,3,2,1,4,0]], 34 "r'": [[0,1,2,0,0,2,1,0], [0,2,6,3,4,1,5,7], [1,0,1,0,0,0,0,0,1,0,1,0], [2,6,10,3,4,1,9,7,0,5,8,11], [1,5,2,0,4,3]], 35 "f" : [[0,0,1,2,0,0,2,1], [0,1,6,2,4,5,7,3], [0,1,1,1,0,0,1,1,0,1,1,1], [0,9,6,1,4,5,10,2,8,11,7,3], [2,1,5,3,0,4]],36 "f2": [[0,0,0,0,0,0,0,0], [0,1,7,6,4,5,3,2], [0,0,0,0,0,0,0,0,0,0,0,0], [0,11,10,9,4,5,7,6,8,3,2,1], [5,1,4,3,2,0]],37 "f'": [[0,0,1,2,0,0,2,1], [0,1,3,7,4,5,2,6], [0,1,1,1,0,0,1,1,0,1,1,1], [0,3,7,11,4,5,2,10,8,1,6,9], [4,1,0,3,5,2]],38 "l" : [[2,0,0,1,1,0,0,2], [3,1,2,7,0,5,6,4], [1,0,1,0,0,0,0,0,1,0,1,0], [2,1,10,7,3,5,6,11,0,9,8,4], [1,5,2,0,4,3]],39 "l2": [[0,0,0,0,0,0,0,0], [7,1,2,4,3,5,6,0], [0,0,0,0,0,0,0,0,0,0,0,0], [10,1,8,11,7,5,6,4,2,9,0,3], [5,3,2,1,4,0]],40 "l'": [[2,0,0,1,1,0,0,2], [4,1,2,0,7,5,6,3], [1,0,1,0,0,0,0,0,1,0,1,0], [8,1,0,4,11,5,6,3,10,9,2,7], [3,0,2,5,4,1]],41 "b" : [[1,2,0,0,2,1,0,0], [4,0,2,3,5,1,6,7], [1,1,0,1,1,1,0,0,1,1,0,1], [4,3,2,11,8,0,6,7,5,1,10,9], [4,1,0,3,5,2]],42 "b2": [[0,0,0,0,0,0,0,0], [5,4,2,3,1,0,6,7], [0,0,0,0,0,0,0,0,0,0,0,0], [8,11,2,9,5,4,6,7,0,3,10,1], [5,1,4,3,2,0]],43 "b'": [[1,2,0,0,2,1,0,0], [1,5,2,3,0,4,6,7], [1,1,0,1,1,1,0,0,1,1,0,1], [5,9,2,1,0,8,6,7,4,11,10,3], [2,1,5,3,0,4]],44 "d" : [[0,0,0,0,0,0,0,0], [0,1,2,3,7,4,5,6], [0,0,0,0,1,1,1,1,0,0,0,0], [0,1,2,3,7,4,5,6,11,8,9,10], [0,2,3,4,1,5]],45 "d2": [[0,0,0,0,0,0,0,0], [0,1,2,3,6,7,4,5], [0,0,0,0,0,0,0,0,0,0,0,0], [0,1,2,3,6,7,4,5,10,11,8,9], [0,3,4,1,2,5]],46 "d'": [[0,0,0,0,0,0,0,0], [0,1,2,3,5,6,7,4], [0,0,0,0,1,1,1,1,0,0,0,0], [0,1,2,3,5,6,7,4,9,10,11,8], [0,4,1,2,3,5]],47 "x" : [[2,1,2,1, 1,2,1,2], [4,5,1,0, 7,6,2,3], [1,0,1,0,0,0,0,0,1,0,1,0], [8,5,0,4,11,9,1,3,10,6,2,7], [3,0,2,5,4,1]], 48 "x2": [[0,0,0,0, 0,0,0,0], [7,6,5,4, 3,2,1,0], [0,0,0,0,0,0,0,0,0,0,0,0], [10,9,8,11,7,6,5,4,2,1,0,3], [5,3,2,1,4,0]], 49 "x'": [[2,1,2,1, 1,2,1,2], [3,2,6,7, 0,1,5,4], [1,0,1,0,0,0,0,0,1,0,1,0], [2,6,10,7,3,1,9,11,0,5,8,4], [1,5,2,0,4,3]],50 "y" : [[0,0,0,0,0,0,0,0], [1,2,3,0,5,6,7,4], [0,0,0,0,1,1,1,1,0,0,0,0], [1,2,3,0,5,6,7,4,9,10,11,8], [0,4,1,2,3,5]], 51 "y2": [[0,0,0,0,0,0,0,0], [2,3,0,1,6,7,4,5], [0,0,0,0,0,0,0,0,0,0,0,0], [2,3,0,1,6,7,4,5,10,11,8,9], [0,3,4,1,2,5]], 52 "y'": [[0,0,0,0,0,0,0,0], [3,0,1,2,7,4,5,6], [0,0,0,0,1,1,1,1,0,0,0,0], [3,0,1,2,7,4,5,6,11,8,9,10], [0,2,3,4,1,5]],53 "z" : [[1,2,1,2,2,1,2,1], [1,5,6,2,0,4,7,3], [1,1,1,1,1,1,1,1,1,1,1,1], [5,9,6,1,0,8,10,2,4,11,7,3], [2,1,5,3,0,4]],54 "z2": [[0,0,0,0,0,0,0,0], [5,4,7,6,1,0,3,2], [0,0,0,0,0,0,0,0,0,0,0,0], [8,11,10,9,5,4,7,6,0,3,2,1], [5,1,4,3,2,0]],55 "z'": [[1,2,1,2,2,1,2,1], [4,0,3,7,5,1,2,6], [1,1,1,1,1,1,1,1,1,1,1,1], [4,3,7,11,8,0,2,10,5,1,6,9], [4,1,0,3,5,2]]56};57var moveAxes = {58 "U" : 0, "U2": 0, "U'": 0,59 "R" : 1, "R2": 1, "R'": 1, 60 "F" : 2, "F2": 2, "F'": 2, 61 "L" : 1, "L2": 1, "L'": 1, 62 "D" : 0, "D2": 0, "D'": 0, 63 "B" : 2, "B2": 2, "B'": 2,64 "M" : 1, "M2": 1, "M'": 1, 65 "E" : 0, "E2": 0, "E'": 0,66 "S" : 2, "S2": 2, "S'": 2,67 "u" : 0, "u2": 0, "u'": 0,68 "r" : 1, "r2": 1, "r'": 1, 69 "f" : 2, "f2": 2, "f'": 2,70 "l" : 1, "l2": 1, "l'": 1,71 "b" : 2, "b2": 2, "b'": 2,72 "d" : 0, "d2": 0, "d'": 0,73 "x" : 1, "x2": 1, "x'": 1,74 "y" : 0, "y2": 0, "y'": 0,75 "z" : 2, "z2": 2, "z'": 2 76};77exports.moveAxes = moveAxes;78var trivialFollowSet = {79 "U" : 0, "U2": 0, "U'": 0,80 "R" : 1, "R2": 1, "R'": 1, 81 "F" : 2, "F2": 2, "F'": 2, 82 "L" : 3, "L2": 3, "L'": 3, 83 "D" : 4, "D2": 4, "D'": 4, 84 "B" : 5, "B2": 5, "B'": 5,85 "M" : 6, "M2": 6, "M'": 6, 86 "E" : 7, "E2": 7, "E'": 7,87 "S" : 8, "S2": 8, "S'": 8,88 "u" : 9, "u2": 9, "u'": 9,89 "r" : 10, "r2": 10, "r'": 10, 90 "f" : 11, "f2": 11, "f'": 11,91 "l" : 12, "l2": 12, "l'": 12,92 "b" : 13, "b2": 13, "b'": 13,93 "d" : 14, "d2": 14, "d'": 14,94 "x" : 15, "x2": 15, "x'": 15,95 "y" : 16, "y2": 16, "y'": 16,96 "z" : 17, "z2": 17, "z'": 1797};98exports.trivialFollowSet = trivialFollowSet;99var isTrivialMove = function (move, moveset) {100 101 for (var i=moveset.length-1; i>=0; i--) {102 if (moveAxes[moveset[i]] === moveAxes[move]) {103 if (trivialFollowSet[moveset[i]] === trivialFollowSet[move]) {104 return true; // Trivial turn105 }106 } 107 else { 108 return false; // Turn on a different axis109 }110 } 111 return false; // No trivial turns112};113exports.isTrivialMove = isTrivialMove;114var applyMoveCP = function (move, cpstate) {115 116 var moveCP = movesDef[move][1]; 117 var newState = cpstate.slice(); 118 for (var i=0; i < moveCP.length; i++) {119 newState[moveCP[i]] = cpstate[i];120 } 121 122 return newState; 123};124var applyMoveEP = function (move, epstate) {125 126 var moveEP = movesDef[move][3]; 127 var newState = epstate.slice(); 128 for (var i=0; i < moveEP.length; i++) {129 newState[moveEP[i]] = epstate[i];130 } 131 132 return newState; 133};134var applyMoveCentr = function (move, centrstate) {135 136 var moveCentr = movesDef[move][4]; 137 var newState = centrstate.slice();138 for (var i=0; i < moveCentr.length; i++) {139 newState[moveCentr[i]] = centrstate[i];140 } 141 142 return newState; 143};144var applyMoveCO = function (move, costate) {145 146 var moveCO = movesDef[move][0]; 147 var newState = applyMoveCP(move, costate); 148 149 for (var i=0; i < moveCO.length; i++) {150 newState[i] = (newState[i] + moveCO[i]) % 3;151 } 152 153 return newState;154};155var applyMoveEO = function (move, eostate) {156 157 var moveEO = movesDef[move][2]; 158 var newState = applyMoveEP(move, eostate); 159 160 for (var i=0; i < moveEO.length; i++) {161 newState[i] = (newState[i] + moveEO[i]) % 2;162 } 163 164 return newState;165};166var applyMove = function (move, state) {167 return [168 applyMoveCO(move, state[0]),169 applyMoveCP(move, state[1]),170 applyMoveEO(move, state[2]),171 applyMoveEP(move, state[3]),172 applyMoveCentr(move, state[4])173 ];174};175exports.applyMoveCP = applyMoveCP;176exports.applyMoveEP = applyMoveEP;177exports.applyMoveCO = applyMoveCO;178exports.applyMoveEO = applyMoveEO;179exports.applyMoveCentr = applyMoveCentr;180exports.applyMove = applyMove;...

Full Screen

Full Screen

InformativeMoveBox.jsx

Source:InformativeMoveBox.jsx Github

copy

Full Screen

...78 };79 handleMove = (axis, sign) => {80 const { addNotification, webSocketSendMessage, tool } = this.props;81 const { stepSize} = this.state;82 webSocketSendMessage(moveAxes( axis, stepSize*sign ));83 // addNotification({ message: <FormattedMessage id="websocket.message.preheat.sended" values={{ tool, preHeatTemp }} />, variant: 'success', autoHide: true, autoHideDuration: 500 })84 // this.setState({preHeatTempLastSend: preHeatTemp})85 };86 handleExtrusion = (extruder, sign) => {87 const { addNotification, webSocketSendMessage, tool } = this.props;88 const { stepSize} = this.state;89 webSocketSendMessage(extrudeFilament( extruder, stepSize*sign ));90 }91 render() {92 const { classes, id } = this.props;93 const {94 value, dataType, lastUpdate, isInHome, inputEnabled, color95 } = this.props;96 const {stepSize} = this.state;...

Full Screen

Full Screen

status-indicator.js

Source:status-indicator.js Github

copy

Full Screen

...149 this.canvasContext.rotate(convertToRadian(ROTATION_ANGLE));150 this.canvasContext.translate(-this.spinnerCenter, -this.spinnerCenter);151 }152 _getRotatedGradientPoints (point) {153 var changedPoint = moveAxes(point, this.spinnerCenter);154 changedPoint = rotateAxes(changedPoint, this.rotationAngle);155 changedPoint = moveAxes(changedPoint, -this.spinnerCenter);156 return changedPoint;157 }158 _setSpinnerGradient () {159 var startGradientPoint = {160 x: Math.round(this.size * START_GRADIENT_POINT_OFFSET.x),161 y: Math.round(this.size * START_GRADIENT_POINT_OFFSET.y)162 };163 var endGradientPoint = {164 x: Math.round(this.size * END_GRADIENT_POINT_OFFSET.x),165 y: Math.round(this.size * END_GRADIENT_POINT_OFFSET.y)166 };167 if (this.rotationAngle !== 0) {168 startGradientPoint = this._getRotatedGradientPoints(startGradientPoint);169 endGradientPoint = this._getRotatedGradientPoints(endGradientPoint);...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

...79 }80 });81}82// Hack to move y-axes that were being cut off. Customizing axis placement appears to be impossible or poorly documented in mpld383function moveAxes(){84 labels = $('.mpld3-text[transform]') // add [transform] so we only catch rotated labels85 labels.attr('transform', (i, value) => `${value || ""} translate(0 10)`)86}87$( window ).on( "load", function (){88 moveAxes()89})90$( document ).ajaxComplete(function(){91 defineJQueryObjects()92 createTooltips()93 moveAxes()94})95function fillLow() {96 rule_out_agi_by_field.val(2020)97 virtual_successes_field.val(0.5)98 regime_start_year_field.val(1956)99 first_trial_probability_field.val(0.001)100 g_exp_field.val(4.3)101 g_act_field.val(7)102 init_weight_calendar_field.val(.5)103 init_weight_researcher_field.val(.3)104 init_weight_agi_impossible_field.val(.2)105 init_weight_comp_relative_res_field.val(0)106 init_weight_lifetime_field.val(0)107 init_weight_evolution_field.val(0)...

Full Screen

Full Screen

commands.js

Source:commands.js Github

copy

Full Screen

1/*2tool 'T0' 'T1' ''3 */4export const preHeatTool = (tool, temperature) => {5 if (tool === 'Bed') {6 return 'M140 S' + temperature + '\r\n';7 } else {8 return 'M104 S' + temperature + ' ' + tool + '\r\n';9 }10};11export const multipleStatRequest = () => {12 return 'M105\r\n' +13 'M997\r\n' + // M997 request printig status14 'M994\r\n' +15 'M992\r\n' + // M992 printing time16 'M27\r\n' + // M27 printing percentage17 '\r\n';18};19export const requestFileList = (path = '') => {20 return 'M20 1:' + path + '\r\n';21};22export const selectAndPrint = (file) => {23 return 'M23 ' + file + '\r\n' +24 'M24\r\n' +25 '\r\n';26};27export const printSelectFile = (file) => {28 return 'M23 ' + file + '\r\n';29};30export const printResumeStart = () => {31 return 'M24\r\n';32};33export const printPause = () => {34 return 'M25\r\n';35};36export const printStop = (file) => {37 return 'M26\r\n';38};39export const deleteFile = (file) => {40 return 'M30 1:' + file + '\r\n';41};42// From 0 to 25543export const setFanSpeed = (speed) => {44 return 'M106 S' + speed + '\r\n';45};46export const cooldown = () => {47 return 'M104 S0\r\n' +48 'M140 S0\r\n';49};50export const unlock = () => {51 return 'M84\r\n';52};53export const moveAxes = (axis, step) => {54 let xA = '0.0';55 let yA = '0.0';56 let zA = '0.0';57 if (axis.toUpperCase() === 'X') {58 xA = step + '.0';59 } else if (axis.toUpperCase() === 'Y') {60 yA = step + '.0';61 } else if (axis.toUpperCase() === 'Z') {62 zA = step + '.0';63 }64 return 'G91\r\n' +65 'G0 X' + xA + ' Y' + yA + '.0 Z' + zA + '.0 F3000\r\n' +66 'G90\r\n';67};68export const extrudeFilament = (extruder, step) => {69 return extruder + '\r\n' +70 'G91\r\n' +71 'G1 E' + step + ' F1000\r\n' +72 'G90\r\n';73};74export const homingXY = () => {75 return 'G28 X Y\r\n';76};77export const homingZ = () => {78 return 'G28 Z\r\n';79};80export const homingAll = () => {81 return 'G28 \r\n';82};83export const resetPrinter = () => {84 return 'M107\r\n' +85 'G1 Z10\r\n' +86 'M104 S0\r\n' +87 'M140 S0\r\n' +88 'M84\r\n';89};90export const coolDown = () => {91 return 'M104 S0\r\n' +92 'M140 S0\r\n' +93 'M106 S255\r\n';94};95export const unlockMotors = () => {96 return 'M84\r\n';...

Full Screen

Full Screen

joystick.js

Source:joystick.js Github

copy

Full Screen

...12 name: '/joy',13 messageType: 'sensor_msgs/Joy'14 })15 }16 moveAxes(axesValue, moveEnd = false) {17 this.axes = axesValue18 if (moveEnd) {19 window.clearInterval(this.intervalId)20 this._sendJoyEvent()21 } else if (this.publishImmidiately) {22 // TODO: refactor this with a debounce lib ?23 this.publishImmidiately = false24 this._sendJoyEvent()25 window.clearInterval(this.intervalId)26 this.intervalId = window.setInterval(this._sendJoyEvent.bind(this), 50)27 setTimeout(() => {28 this.publishImmidiately = true29 }, 50)30 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2test('My first test', async t => {3 .click('#populate')4 .click('#submit-button')5 .expect(Selector('#article-header').innerText).eql('Thank you, John Smith!');6});7export default class Helper {8 async moveAxes (t, selector, x, y) {9 .hover(selector)10 .drag(selector, x, y);11 }12}13import { Selector } from 'testcafe';14import Helper from './test.js';15test('My first test', async t => {16 const helper = new Helper();17 .click('#populate')18 .click('#submit-button')19 .expect(Selector('#article-header').innerText).eql('Thank you, John Smith!');20});21export default class Helper {22 async moveAxes (t, selector, x, y) {23 .hover(selector)24 .drag(selector, x, y);25 }26}

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2test('My first test', async t => {3 const slider = Selector('#tried-test-cafe');4 .click('#tried-test-cafe')5 .drag(slider, 360, 0, { offsetX: 10, offsetY: 10 });6});7import { Selector } from 'testcafe';8import { moveAxes } from 'testcafe-react-selectors';9test('My first test', async t => {10 const slider = Selector('#tried-test-cafe');11 .click('#tried-test-cafe')12 .drag(slider, moveAxes(360, 0, { offsetX: 10, offsetY: 10 }));13});14import React from 'react';15import { Selector } from 'testcafe';16import { moveAxes } from 'testcafe-react-selectors';17test('My first test', async t => {18 const slider = Selector('#tried-test-cafe');19 .click('#tried-test-cafe')20 .drag(slider, moveAxes(360, 0, { offsetX: 10, offsetY: 10 }));21});22import React from 'react';23import { Selector } from 'testcafe';24import { moveAxes } from 'testcafe-react-selectors';25test('My first test', async t => {26 const slider = Selector('#tried-test-cafe');27 .click('#tried-test-cafe')28 .drag(slider, moveAxes(360, 0, { offsetX: 10, offsetY: 10 }));29});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2test('My first test', async t => {3 .click('#tried-test-cafe')4 .click('#populate')5 .click('#submit-button')6 .click('#remote-testing')7 .click('#reusing-js-code')8 .click('#background-parallel-testing')9 .click('#continuous-integration-embedding')10 .click('#traffic-markup-analysis');11});12import { Selector } from 'testcafe';13test('My first test', async t => {14 .click('#tried-test-cafe')15 .click('#populate')16 .click('#submit-button')17 .click('#remote-testing')18 .click('#reusing-js-code')19 .click('#background-parallel-testing')20 .click('#continuous-integration-embedding')21 .click('#traffic-markup-analysis');22});23import { Selector } from 'testcafe';24test('My first test', async t => {25 .click('#tried-test-cafe')26 .click('#populate')27 .click('#submit-button')28 .click('#remote-testing')29 .click('#reusing-js-code')30 .click('#background-parallel-testing')31 .click('#continuous-integration-embedding')32 .click('#traffic-markup-analysis');33});34import { Selector } from 'testcafe';35test('My first test', async t => {36 .click('#tried-test-cafe')37 .click('#populate')38 .click('#submit-button')39 .click('#remote-testing')40 .click('#reusing-js-code')41 .click('#background-parallel-testing')42 .click('#continuous-integration-embedding')43 .click('#traffic-markup-analysis');44});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2test('My Test', async t => {3 const slider = Selector('#slider');4 .click(slider)5 .pressKey('right')6});7import { Selector } from 'testcafe';8test('My Test', async t => {9 const slider = Selector('#slider');10 .click(slider)11 .moveAxes(1, 0);12});13import { Selector } from 'testcafe';14test('My Test', async t => {15 const slider = Selector('#slider');16 .click(slider)17 .moveAxes(1, 0);18});19import { Selector } from 'testcafe';20test('My Test', async t => {21 const slider = Selector('#slider');22 .click(slider)23 .moveAxes(1, 0);24});25import { Selector } from 'testcafe';26test('My Test', async t => {27 const slider = Selector('#slider');28 .click(slider)29 .moveAxes(1, 0);30});31import { Selector } from 'testcafe';32test('My Test', async t => {33 const slider = Selector('#slider');34 .click(slider)35 .moveAxes(1, 0);36});37import { Selector } from 'testcafe';

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2test('My test', async t => {3 const slider = Selector('#slider');4 .click(slider)5 .drag(slider, 360, 0, { offsetX: 10, offsetY: 10 });6});7import { Selector } from 'testcafe';8test('My test', async t => {9 const slider = Selector('#slider');10 .click(slider)11 .drag(slider, 360, 0, { offsetX: 10, offsetY: 10 });12});13import { Selector } from 'testcafe';14test('My test', async t => {15 const slider = Selector('#slider');16 .click(slider)17 .drag(slider, 360, 0);18});19import { Selector } from 'testcafe';20test('My test', async t => {21 const slider = Selector('#slider');22 .click(slider)23 .drag(slider, 360, 0);24});25t.drag( target, dragOffsetX, dragOffsetY [, options] )26Name Type Description offsetX number (optional) Specifies

Full Screen

Using AI Code Generation

copy

Full Screen

1import { ClientFunction } from 'testcafe';2const moveAxes = ClientFunction((x, y) => window.testCafeDriver3 .move({ x, y })4 .wait(1000)5 .press()6 .wait(1000)7 .release()8 .wait(1000)9 .perform());10await moveAxes(200, 200);11await moveAxes(300, 300);12await moveAxes(400, 400);

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2test('My first test', async t => {3 .click('#target')4 .expect(Selector('#result').innerText).eql('Clicked!');5});6test('My second test', async t => {7 .click('#target')8 .expect(Selector('#result').innerText).eql('Clicked!');9});10test('My third test', async t => {11 .click('#target')12 .expect(Selector('#result').innerText).eql('Clicked!');13});14test('My fourth test', async t => {15 .click('#target')16 .expect(Selector('#result').innerText).eql('Clicked!');17});18test('My fifth test', async t => {19 .click('#target')20 .expect(Selector('#result').innerText).eql('Clicked!');21});22test('My sixth test', async t => {23 .click('#target')24 .expect(Selector('#result').innerText).eql('Clicked!');25});26test('My seventh test', async t => {27 .click('#target')28 .expect(Selector('#result').innerText).eql('Clicked!');29});30test('My eighth test', async t => {31 .click('#target')32 .expect(Selector('#result').innerText).eql('Clicked!');33});34test('My ninth test', async t => {35 .click('#target')36 .expect(Selector('#result').innerText).eql('Clicked!');37});38test('My tenth test', async t => {39 .click('#target')40 .expect(Selector('#result').innerText).eql('Clicked!');41});

Full Screen

Using AI Code Generation

copy

Full Screen

1import {Selector} from 'testcafe';2test('Move Axes Test', async t => {3 .click('#moveAxes')4 .expect(Selector('#axis1').innerText).eql('1')5 .expect(Selector('#axis2').innerText).eql('2')6 .expect(Selector('#axis3').innerText).eql('3')7 .expect(Selector('#axis4').innerText).eql('4')8 .expect(Selector('#axis5').innerText).eql('5')9 .expect(Selector('#axis6').innerText).eql('6')10 .expect(Selector('#axis7').innerText).eql('7')11 .expect(Selector('#axis8').innerText).eql('8')12 .expect(Selector('#axis9').innerText).eql('9')13 .expect(Selector('#axis10').innerText).eql('10')14 .expect(Selector('#axis11').innerText).eql('11')15 .expect(Selector('#axis12').innerText).eql('12')16 .expect(Selector('#axis13').innerText).eql('13')17 .expect(Selector('#axis14').innerText).eql('14')18 .expect(Selector('#axis15').innerText).eql('15')19 .expect(Selector('#axis16').innerText).eql('16')20 .expect(Selector('#axis17').innerText).eql('17')21 .expect(Selector('#axis18').innerText).eql('18')22 .expect(Selector('#axis19').innerText).eql('19')23 .expect(Selector('#axis20').innerText).eql('20')24 .expect(Selector('#axis21').innerText).eql('21')25 .expect(Selector('#axis22').innerText).eql('22')26 .expect(Selector('#axis23').innerText).eql('23')27 .expect(Selector('#axis24').innerText).eql('24')28 .expect(Selector('#axis25').innerText).eql('25')29 .expect(Selector('#axis26').innerText).eql('26')30 .expect(Selector('#axis27').innerText).eql('27')31 .expect(Selector('#axis28').innerText).eql('28')

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2test('Test', async t => {3 .click(Selector('#a'))4 .click(Selector('#b'))5 .click(Selector('#c'));6});7import { Selector } from 'testcafe';8test('Test', async t => {9 .click(Selector('#b'))10 .click(Selector('#a'))11 .click(Selector('#c'));12});13 .click(Selector('#a'))14 .click(Selector('#b'))15 .click(Selector('#c'));

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Testcafe automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful