-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
164 lines (111 loc) · 3.52 KB
/
main.cpp
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#include <iostream>
#include "cube.hpp"
void show_main_menu() {
std::stringstream ss;
ss << "Choose the command\n"
<< "1 - Save and read current state of cube from the file\n"
<< "2 - Check if the cube is valid\n"
<< "3 - Output the current state of the cube\n"
<< "4 - Turn the cube's edges\n"
<< "5 - Generate a random valid Cube state\n"
<< "6 - Find the solution for the current state\n"
<< "7 - Exit the program\n";
std::cout << ss.str();
}
void show_menu_for_saving_or_reading() {
std::stringstream ss;
ss << "Choose the act:\n"
<< "1 - Save the current state in file\n"
<< "2 - Read the state from the file\n"
<< "3 - Get back to the main menu\n";
std::cout << ss.str();
}
void show_menu_for_turning_edges() {
std::stringstream ss;
ss << "Chose the edge you want to turn:\n"
<< "- L\n"
<< "- U\n"
<< "- R\n"
<< "- D\n"
<< "- F\n"
<< "- B\n"
<< "- Get back to the main menu(Write 'b')\n";
std::cout << ss.str();
}
void show_menu_where_to_turn() {
std::stringstream ss;
ss << "Choose where do you want to turn the edge to:\n"
<< "- Left\n"
<< "- Right\n";
std::cout << ss.str();
}
void run() {
int action = -1;
cube_ cube;
while (action != 7) {
show_main_menu();
std::cin >> action;
switch (action) {
case 1:
show_menu_for_saving_or_reading();
std::cin >> action;
switch (action) {
case 1:
cube.save_the_state();
std::cout << "Saved!\n";
break;
case 2:
cube.read_the_state();
std::cout << "Done!\n";
break;
default:
break;
}
break;
case 2:
if (cube.check_state_validness())
std::cout << "Cube's state is VALID!\n";
else
std::cout << "Cube's state is NOT VALID!\n";
break;
case 3:
cube.console_output();
break;
case 4:
while (true) {
show_menu_for_turning_edges();
std::string edge, where_turn;
std::cin >> edge;
if (edge == "b")
break;
show_menu_where_to_turn();
where_turn = "-1";
while (where_turn != "Right" && where_turn != "Left") {
std::cin >> where_turn;
if (where_turn != "Right" && where_turn != "Left") {
std::cout << "Invalid way, choose again\n";
}
}
if (where_turn == "Back")
continue;
cube.turn_edge(edge, where_turn);
}
break;
case 5:
cube.generate();
break;
case 6:
cube.find_solution();
std::cout << "Done!\nSolution: ";
cube.get_answer();
break;
case 7:
return;
default:
std::cout << "Invalid number of command\n";
}
}
}
int main() {
run();
}