-
Notifications
You must be signed in to change notification settings - Fork 0
/
RubiksCube.h
189 lines (148 loc) · 3.92 KB
/
RubiksCube.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
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
//
// Created by ASUS on 08-07-2023.
//
#ifndef RUBIKSCUBESOLVERV1_RUBIKSCUBE_H
#define RUBIKSCUBESOLVERV1_RUBIKSCUBE_H
#include "bits/stdc++.h"
using namespace std;
/**
* A base class for all Rubik's Cube Model. There are various representation for Rubik's Cube.
* Each one has it's own special ways of definitions. This class provides a shared functionality
* between all models.
* We'll benchmark all models and observe which one is better for performance.
*/
class RubiksCube {
public:
enum class FACE {
UP,
LEFT,
FRONT,
RIGHT,
BACK,
DOWN
};
enum class COLOR {
WHITE,
GREEN,
RED,
BLUE,
ORANGE,
YELLOW
};
enum class MOVE {
L, LPRIME, L2,
R, RPRIME, R2,
U, UPRIME, U2,
D, DPRIME, D2,
F, FPRIME, F2,
B, BPRIME, B2
};
/*
* Returns the color of the cell at (row, col) in face.
* If Rubik's Cube face is pointing at you, then the row numbering starts from the
* top to bottom, and column numbering starts from the left to right.
* The rows and columns are 0-indexed.
* @param Face, row, and column index
*/
virtual COLOR getColor(FACE face, unsigned row, unsigned col) const = 0;
/*
* Returns the first letter of the given COLOR
* Eg: For COLOR::GREEN, it returns 'G'
*/
static char getColorLetter(COLOR color);
/*
* Returns true if the Rubik Cube is solved, otherwise returns false.
*/
virtual bool isSolved() const = 0;
/*
* Returns the move in the string format.
*/
static string getMove(MOVE ind);
/*
* Print the Rubik Cube in Planar format.
*
* The cube is laid out as follows.
*
* The sides:
* U
* L F R B
* D
*
* Color wise:
*
* W W W
* W W W
* W W W
*
* G G G R R R B B B O O O
* G G G R R R B B B O O O
* G G G R R R B B B O O O
*
* Y Y Y
* Y Y Y
* Y Y Y
*
* Row and Column Numberings:
* rx -> row numbering
* cx -> column numbering
* bx -> both row and column numbering
*
* b0 c1 c2
* r1 . .
* r2 . .
*
* b0 c1 c2 b0 c1 c2 b0 c1 c2 b0 c1 c2
* r1 . . r1 . . r1 . . r1 . .
* r2 . . r2 . . r2 . . r2 . .
*
* b0 c1 c2
* r1 . .
* r2 . .
*
*/
void print() const;
/*
* Randomly shuffle the cube with 'times' moves and returns the moves performed.
*/
vector<MOVE> randomShuffleCube(unsigned int times);
/*
* Perform moves on the Rubik Cube
*/
RubiksCube &move(MOVE ind);
/*
* Invert a move
*/
RubiksCube &invert(MOVE ind);
/*
* Rotational Moves on the Rubik Cubes
*
* F, F’, F2,
* U, U’, U2,
* L, L’, L2,
* D, D’, D2,
* R, R’, R2,
* B, B’, B2
*/
virtual RubiksCube &f() = 0;
virtual RubiksCube &fPrime() = 0;
virtual RubiksCube &f2() = 0;
virtual RubiksCube &u() = 0;
virtual RubiksCube &uPrime() = 0;
virtual RubiksCube &u2() = 0;
virtual RubiksCube &l() = 0;
virtual RubiksCube &lPrime() = 0;
virtual RubiksCube &l2() = 0;
virtual RubiksCube &r() = 0;
virtual RubiksCube &d() = 0;
virtual RubiksCube &dPrime() = 0;
virtual RubiksCube &d2() = 0;
virtual RubiksCube &rPrime() = 0;
virtual RubiksCube &r2() = 0;
virtual RubiksCube &b() = 0;
virtual RubiksCube &bPrime() = 0;
virtual RubiksCube &b2() = 0;
string getCornerColorString(uint8_t ind) const;
uint8_t getCornerIndex(uint8_t ind) const;
uint8_t getCornerOrientation(uint8_t ind) const;
};
#endif //RUBIKSCUBESOLVERV1_RUBIKSCUBE_H