-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcube.h
executable file
·129 lines (105 loc) · 1.95 KB
/
cube.h
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
#ifndef CUBE_H
#define CUBE_H
#include <iostream>
// move a->b, b->c, c->d, d->a
template <typename T>
void quarterTurn(T& a, T& b, T& c, T& d) {
T temp(a);
a = b;
b = c;
c = d;
d = temp;
}
// move a->c, c->a, b->d, d->b
template <typename T>
void halfTurn(T& a, T& b, T& c, T& d)
{
T tmp(a);
a = c;
c = tmp;
T tmp2(b);
b = d;
d = tmp2;
}
// a class representing the states of a Rubik's Cube
class Cube {
public:
enum corner : int{
WOG = 1, WGR = 3, WRB = 5, WBO = 7,
YOG = 13, YGR = 15, YRB = 17, YBO = 19
};
enum edge_piece : int {
WG = 2, WR = 4, WB = 6, WO = 8,
OG = 9, GR = 10, RB = 11, BO = 12,
GY = 14, RY = 16, BY = 18, OY = 20
};
private:
corner mCorners[8];
edge_piece mEdges[12];
bool _isSolved;
void checkSolved();
using Rot = Cube& (Cube::*)(void);
void randomPermute();
public:
Cube();
Cube(bool);
Cube(const int (&_corners)[8], const int (&_edges)[12]);
Cube(const Cube&) = default;
Cube(Cube&&) = default;
Cube& operator=(Cube&&) = default;
Cube& operator=(const Cube&) = default;
~Cube() = default;
const corner (& get_corners() const)[8] ;
const edge_piece (& get_edges() const)[12];
bool isSolved() const;
bool operator==(const Cube& rhs) const;
Cube& turnUp();
Cube& turnUp2();
Cube& turnUpI();
Cube& turnDown();
Cube& turnDown2();
Cube& turnDownI();
Cube& turnFront();
Cube& turnFront2();
Cube& turnFrontI();
Cube& turnBack();
Cube& turnBack2();
Cube& turnBackI();
Cube& turnLeft();
Cube& turnLeft2();
Cube& turnLeftI();
Cube& turnRight();
Cube& turnRight2();
Cube& turnRightI();
/*
CORNER INDEX CORRESPONDENCE FOR CW TURN
Top
{0,1,2,3}
Bottom
{7,6,5,4}
Front
{4,5,1,0}
Back
{6,7,3,2}
Left
{7,4,0,3}
Right
{5,6,2,1}
*/
/*
EDGE INDEX CORRESPONDENCE FOR CW TURN
Top
{0,1,2,3}
Bottom
{10,9,8,11}
Front
{8,5,0,4}
Back
{10,7,2,6}
Left
{11,4,3,7}
Right
{9,6,1,5}
*/
};
#endif