-
Notifications
You must be signed in to change notification settings - Fork 0
/
rubik.cpp
64 lines (55 loc) · 1.43 KB
/
rubik.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
#include "face_2d.h"
#include "cube.h"
#include <fstream>
#include <iostream>
#include <stdexcept>
const std::string default_path_to_cube = "cube.in";
Cube load_cube_from_file() {
std::ifstream file(default_path_to_cube);
if (!file.is_open())
throw new std::exception();
std::string face;
const unsigned int face_nr = 6;
std::vector<Face_2d> faces;
for (unsigned int i = 0; i < face_nr; ++i) {
file >> face;
std::vector<char> v;
if (face.size() != FACE_2D_FIELDS_NUM)
throw new std::exception();
for (unsigned int j = 0; j < face.size(); ++j)
v.push_back(face[j]);
faces.push_back(Face_2d(v));
}
return Cube(faces);
}
Cube load_cube_from_input() {
// TODO: implement
return Cube();
}
Cube load_cube_from_file_or_input() {
try {
return load_cube_from_file();
}
catch (...) {
return load_cube_from_input();
}
}
template<class T>
auto operator<<(std::ostream& os, const T& t) -> decltype(t.print(os), os) {
t.print(os);
return os;
}
int main() {
try {
Cube c = load_cube_from_file_or_input();
std::cout << c;
//c.print_cubixons();
//Cube d = Cube::move(c, 1);
//c.print_cubixons();
//c.cubixons_to_faces();
std::cout << " \nbfs: " << c.bfs() << std::endl;
}
catch (...) {
std::cerr << "Error in loading cube." << std::endl;
}
}