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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
|
#include "cube.h"
std::string
to_string(color c)
{
switch (c) {
case color::none:
return "none";
case color::white:
return "white";
case color::yellow:
return "yellow";
case color::orange:
return "orange";
case color::red:
return "red";
case color::blue:
return "blue";
case color::green:
return "green";
default:
return "error";
}
}
abstract_face::abstract_face(const abstract_cube &parent):
_parent_cube(parent)
{ }
face1::face1(const cube1 &parent, color c):
abstract_face(parent), _color(c)
{ }
std::string
face1::to_string() const
{
return std::string("'") + ::to_string(_color) + "'";
}
face3::face3(const cube3 &parent):
abstract_face(parent)
{ }
std::string
face3::to_string() const
{
std::ostringstream ss;
ss << "{" << std::endl;
ss << " " << _faces[0]->to_string() << ",";
ss << " " << _faces[1]->to_string() << ",";
ss << " " << _faces[2]->to_string() << ",";
ss << std::endl;
ss << " " << _faces[3]->to_string() << "," << std::endl;
ss << " " << _faces[4]->to_string() << ",";
ss << " " << _faces[5]->to_string() << ",";
ss << std::endl;
ss << " " << _faces[6]->to_string() << "," << std::endl;
ss << " " << _faces[7]->to_string() << ",";
ss << " " << _faces[8]->to_string() << ",";
ss << "}" << std::endl;
return ss.str();
}
const std::shared_ptr<abstract_face>
abstract_cube::front() const
{
return _faces[0];
}
const std::shared_ptr<abstract_face>
abstract_cube::back() const
{
return _faces[1];
}
const std::shared_ptr<abstract_face>
abstract_cube::left() const
{
return _faces[2];
}
const std::shared_ptr<abstract_face>
abstract_cube::right() const
{
return _faces[3];
}
const std::shared_ptr<abstract_face>
abstract_cube::up() const
{
return _faces[4];
}
const std::shared_ptr<abstract_face>
abstract_cube::down() const
{
return _faces[5];
}
void
abstract_cube::flip_right()
{
/* front = left */
/* left = back */
/* back = right */
/* right = front */
std::shared_ptr<abstract_face> front_save(_faces[0]);
_faces[0] = _faces[2];
_faces[2] = _faces[1];
_faces[1] = _faces[3];
_faces[3] = front_save;
}
void
abstract_cube::flip_left()
{
/* front = right */
/* right = back */
/* back = left */
/* left = front */
std::shared_ptr<abstract_face> front_save(_faces[0]);
_faces[0] = _faces[3];
_faces[3] = _faces[1];
_faces[1] = _faces[2];
_faces[2] = front_save;
}
void
abstract_cube::flip_up()
{
/* front = down */
/* down = back */
/* back = up */
/* up = front */
std::shared_ptr<abstract_face> front_save(_faces[0]);
_faces[0] = _faces[5];
_faces[5] = _faces[1];
_faces[1] = _faces[4];
_faces[4] = front_save;
}
void
abstract_cube::flip_down()
{
/* front = up */
/* up = back */
/* back = down */
/* down = front */
std::shared_ptr<abstract_face> front_save(_faces[0]);
_faces[0] = _faces[4];
_faces[4] = _faces[1];
_faces[1] = _faces[5];
_faces[5] = front_save;
}
std::string
abstract_cube::to_string() const
{
std::ostringstream ss;
ss << "{" << std::endl;
ss << " 'front': " << front()->to_string() << "," << std::endl;
ss << " 'back': " << back()->to_string() << "," << std::endl;
ss << " 'left': " << left()->to_string() << "," << std::endl;
ss << " 'right': " << right()->to_string() << "," << std::endl;
ss << " 'up': " << up()->to_string() << "," << std::endl;
ss << " 'down': " << down()->to_string() << std::endl;
ss << "}" << std::endl;
return ss.str();
}
cube3::cube3(color, color, color, color, color, color):
abstract_cube()
{
/* TODO use the colors to set everything. */
_faces[0].reset(new face3(*this));
_faces[1].reset(new face3(*this));
_faces[2].reset(new face3(*this));
_faces[3].reset(new face3(*this));
_faces[4].reset(new face3(*this));
_faces[5].reset(new face3(*this));
}
|