-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCubesStorage.cpp
69 lines (57 loc) · 1.55 KB
/
CubesStorage.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
#include "CubesStorage.hpp"
CubesStorage::CubesStorage(vector<Cube> cubes) {
for (int i = 0; i < cubes.size(); i++) {
this->cubes.push_back(cubes[i]);
}
}
CubesStorage::CubesStorage(const CubesStorage* other, const Cube* cube) {
if (other == nullptr) {
this->cubes.push_back(*cube);
}
else if (cube == nullptr) {
cout << "No cube to add.\n";
}
else {
int size = other->cubes.size();
for (int i = 0; i < size; i++) {
this->cubes.push_back(other->cubes[i]);
}
this->cubes.push_back(*cube);
}
}
Cube CubesStorage::get_cube(int pos) {
if (pos < cubes.size()) {
return cubes[pos];
}
return Cube();
}
bool CubesStorage::is_valid(const Cube& next) {
int size = this->cubes.size();
bool is_valid = true;
for (int i = 0; i < size; i++) {
is_valid = true;
if (cubes[i].get_left() != next.get_left() && cubes[i].get_right() != next.get_right()
&& cubes[i].get_back() != next.get_back() && cubes[i].get_front() != next.get_front()) {
is_valid = true;
}
else {
is_valid = false;
break;
}
}
if (is_valid) {
return true;
}
return false;
}
vector<Cube> CubesStorage::get_cubes() const {
return this->cubes;
}
ostream& operator<<(std::ostream& out, const CubesStorage& obj) {
for (auto c : obj.cubes) {
out << c.enumToStr(c.get_front()) << " " << c.enumToStr(c.get_back()) << " ";
out << c.enumToStr(c.get_left()) << " " << c.enumToStr(c.get_right()) << " ";
out << c.enumToStr(c.get_top()) << " " << c.enumToStr(c.get_bottom()) << endl;
}
return out;
}