aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cube.h16
-rw-r--r--src/main.cpp16
-rw-r--r--src/solver.cpp5
3 files changed, 25 insertions, 12 deletions
diff --git a/src/cube.h b/src/cube.h
index ccc83d2..e25dce4 100644
--- a/src/cube.h
+++ b/src/cube.h
@@ -149,6 +149,13 @@ typedef enum {
NULL_ROT
} rotations;
+static char *rot_strings[] = {
+ "R", "L", "U", "D", "F", "B",
+ "R'", "L'", "U'", "D'", "F'", "B'",
+ "R2", "L2", "U2", "D2", "F2", "B2",
+ "",
+};
+
typedef void (*rot_f)(cube_t *);
static const rot_f rot_func[] = {
@@ -158,7 +165,8 @@ static const rot_f rot_func[] = {
rotation_d,
rotation_f,
rotation_b,
- rotation_rp, rotation_lp,
+ rotation_rp,
+ rotation_lp,
rotation_up,
rotation_dp,
rotation_fp,
@@ -247,7 +255,7 @@ static rotations* parse_scramble(char **str) {
}
static char **tokenize_rot_str(char *str) {
- const char *delims = " \n\t";
+ const char *delims = " \n\t,";
ssize_t capacity = 20;
char **tokens = (char **)calloc(sizeof(char *), capacity);
int tok_cnt = 0;
@@ -298,6 +306,10 @@ static void init_cube(cube_t *cube) {
}
}
+static char *rot_to_str(rotations rot) {
+ return rot_strings[(int)rot];
+}
+
/******************************************************************************/
/* Printint cube state ********************************************************/
diff --git a/src/main.cpp b/src/main.cpp
index 3144b0b..0822a4c 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -14,25 +14,23 @@ int main() {
while (getline(&buf, &sz, stdin) != -1) {
init_cube(&cube);
if (sz == 0) break;
- printf("> %s\n", buf);
rotate_from_str(&cube, buf);
dump_cube_grid(&cube);
timer = clock();
auto result = solver.solve(cube);
timer = clock() - timer;
- std::cerr << "Time: " << (float)timer/CLOCKS_PER_SEC << "\n";
-
+ std::cerr << "Time: " << (float)timer/CLOCKS_PER_SEC << "s\n";
for (auto rot: result) {
- std::cerr << rot << " ";
+ std::cerr << rot_to_str(rot) << " ";
}
- std::cerr << "\n";
+ std::cerr << "len: " << result.size() << "\n";
- for (auto rot: result) {
- perform_rotation(&cube, rot);
- }
- dump_cube_grid(&cube);
+ // for (auto rot: result) {
+ // perform_rotation(&cube, rot);
+ // }
+ // dump_cube_grid(&cube);
}
if (buf)
diff --git a/src/solver.cpp b/src/solver.cpp
index d05771a..0625bf6 100644
--- a/src/solver.cpp
+++ b/src/solver.cpp
@@ -83,10 +83,13 @@ std::vector<rotations> Solver::get_solve_pruning(cube_t cube) {
#define TILE_VAL(i) (face>>((i)<<2)&0xf)
#define CMP_TILES(i, j) (uint32_t)(!!(TILE_VAL(i)==TILE_VAL(j)))
+#define MAX_MOVES_CNT 20
/* Count number of neibourgh tiles of the same color */
__attribute__((optimize("unroll-loops")))
heur_t Solver::heuristic(const cube_t cube, const uint16_t moves_cnt) {
+ if (moves_cnt > MAX_MOVES_CNT)
+ return INT32_MIN;
heur_t value = 0;
int i, j;
face_t face;
@@ -194,7 +197,7 @@ std::vector<rotations> Solver::solve(const cube_t cube) {
}
}
- std::cerr << "Found solution!\n" << "\n";
+ // std::cerr << "Found solution!\n";
auto res = retrieve_solution(state);
auto prun_res = get_solve_pruning(state);
//std::cerr << prun_res.size() << "\n";