Thistlethwaite 算法实现魔方复原 - 完成顶层十字
// 第一步:完成顶层十字 void solveTopCross(Cube& cube) { // 定义一个数组,存储需要旋转的面和旋转方式 pair<Color, Rotation> moves[] = { {GREEN, CLOCKWISE}, {GREEN, DOUBLE}, {GREEN, COUNTERCLOCKWISE}, {BLUE, CLOCKWISE}, {BLUE, DOUBLE}, {BLUE, COUNTERCLOCKWISE}, {ORANGE, CLOCKWISE}, {ORANGE, DOUBLE}, {ORANGE, COUNTERCLOCKWISE}, {RED, CLOCKWISE}, {RED, DOUBLE}, {RED, COUNTERCLOCKWISE} };
// 遍历所有可能的旋转方式,直到顶层十字完成
for (int i = 0; i < 12; i++) {
// 获取当前魔方状态
CubeState state = cube.getState();
// 获取需要旋转的面和旋转方式
Color face = moves[i].first;
Rotation rotation = moves[i].second;
// 执行旋转操作
cube.rotate(face, rotation);
// 判断是否完成顶层十字
if (state.up[0][1] == YELLOW && state.up[1][0] == YELLOW && state.up[1][2] == YELLOW && state.up[2][1] == YELLOW) {
break;
}
}
}
原文地址: https://www.cveoy.top/t/topic/nlNi 著作权归作者所有。请勿转载和采集!