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
|
#pragma once
#include <sstream>
#include <memory>
#include <unordered_map>
enum class color {
none,
white,
yellow,
orange,
red,
blue,
green,
};
std::string to_string(color c);
class abstract_cube;
class abstract_face {
public:
abstract_face(const abstract_cube &);
virtual std::string to_string() const = 0;
private:
const abstract_cube &_parent_cube;
};
class cube1;
class face1 final: public abstract_face {
public:
face1(const cube1 &parent, color);
std::string to_string() const;
private:
const color _color;
};
class cube3;
class face3 final: public abstract_face {
public:
face3(const cube3 &parent);
std::string to_string() const;
private:
std::array<std::shared_ptr<face1>, 9> _faces;
};
class abstract_cube {
public:
void flip_right();
void flip_left();
void flip_up();
void flip_down();
/* Return a new face. */
const std::shared_ptr<abstract_face> front() const;
const std::shared_ptr<abstract_face> back() const;
const std::shared_ptr<abstract_face> left() const;
const std::shared_ptr<abstract_face> right() const;
const std::shared_ptr<abstract_face> up() const;
const std::shared_ptr<abstract_face> down() const;
std::string to_string() const;
protected:
abstract_cube() = default;
std::array<std::shared_ptr<abstract_face>, 6> _faces;
};
class cube1 final: public abstract_cube {
};
class cube3 final: public abstract_cube {
public:
cube3(color, color, color, color, color, color);
cube3(const cube3 &) = default;
cube3(cube3 &&) = default;
/* Front face 90 deg clockwise. */
void f();
/* Front face 90 deg counter-clockwise. */
void F();
/* Back face 90 deg clockwise. */
void b();
/* Back face 90 deg counter-clockwise. */
void B();
/* Left face 90 deg clockwise. */
void l();
/* Left face 90 deg counter-clockwise. */
void L();
/* Right face 90 deg clockwise. */
void r();
/* Right face 90 deg counter-clockwise. */
void R();
/* Up face 90 deg clockwise. */
void u();
/* Up face 90 deg counter-clockwise. */
void U();
/* Down face 90 deg clockwise. */
void d();
/* Down face 90 deg counter-clockwise. */
void D();
/*
* +---+---+---+
* | 0 | 1 | 2 |
* +---+---+---+
* | 3 | 4 | 5 |
* +---+---+---+
* | 6 | 7 | 8 |
* +---+---+---+
*/
};
|