summaryrefslogtreecommitdiff
path: root/cube.h
diff options
context:
space:
mode:
authorOlivier Gayot <og@satcom1.com>2017-01-12 18:01:01 +0100
committerOlivier Gayot <og@satcom1.com>2017-01-12 18:01:01 +0100
commit43d8434bbc47a94f1505374398698b199a34fa08 (patch)
treee14b882b29713449fa2d4b1ae4b489c09297437e /cube.h
first commitHEADmaster
Signed-off-by: Olivier Gayot <og@satcom1.com>
Diffstat (limited to 'cube.h')
-rw-r--r--cube.h129
1 files changed, 129 insertions, 0 deletions
diff --git a/cube.h b/cube.h
new file mode 100644
index 0000000..690fe86
--- /dev/null
+++ b/cube.h
@@ -0,0 +1,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 |
+ * +---+---+---+
+ */
+};
+