Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include "Move.h"
#include <iostream>
#include "Controller.h"
#include "Printer.h"
#include "BasicFunctions.h"
bool isCubeSolved() {
for (const auto& face : cube) {
std::string color = face[0][0];
for (const auto& row : face) {
for (const auto& cell : row) {
if (cell != color) return false;
}
}
}
return true;
}
void manipulation() {
std::cout << "\nStart rotating the sides of the Rubik's cube, here are the commands you will need:\n"
"\"g\" for green clockwise\n"
"\"w\" for white clockwise\n"
"\"o\" for orange clockwise\n"
"\"y\" for yellow clockwise\n"
"\"r\" for red clockwise\n"
"\"b\" for blue clockwise\n"
"Add \"!\" to rotate counterclockwise\n"
"Add a number to set the amount of steps\n\n"
"For example, \"2g!\" will rotate the green side counterclockwise two times.\n"
"Type \"hint\" to get moves to solve.\n"
"Type \"x\" to cancel.\n\n";
std::string move;
while (true) {
if (!isCubeSolved()) {
std::cout << "Your move: ";
std::cin >> move;
if (move == "X" || move == "x") {
break;
} else if (move == "hint") {
printHint();
} else {
int steps = 1;
std::string direction = "clockwise";
std::string color;
size_t index = 0;
while (index < move.size() && isdigit(move[index])) {
index++;
}
if (index > 0) {
steps = std::stoi(move.substr(0, index));
}
if (index < move.size()) {
char colorChar = move[index];
switch (colorChar) {
case 'g': color = "green"; break;
case 'w': color = "white"; break;
case 'o': color = "orange"; break;
case 'y': color = "yellow"; break;
case 'r': color = "red"; break;
case 'b': color = "blue"; break;
default:
std::cout << "Invalid move\n";
continue;
}
index++;
}
if (index < move.size() && move[index] == '!') {
direction = "counterclockwise";
}
if (!color.empty()) {
rotateCubeFace(color, direction, steps);
printTemplate(cube);
} else {
std::cout << "Invalid move\n";
}
}
} else {
std::cout << "Congratulations!\nYou solved the rubik's cube";
break;
}
}
}