aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFranciszek Malinka <franciszek.malinka@gmail.com>2022-04-26 01:40:02 +0200
committerFranciszek Malinka <franciszek.malinka@gmail.com>2022-04-26 01:40:02 +0200
commitabadc0e24d7fd1ade52e3ced31892cf5037b9cf6 (patch)
treecab5d5cc672feeb83cb16dc3fe2610b72c0db454
parent5001e89f399dbd74dab054743f95c752b6f04bc6 (diff)
Small changes
-rw-r--r--scrambles.txt1
-rw-r--r--src/cube.h16
-rw-r--r--src/main.cpp16
-rw-r--r--src/solver.cpp5
4 files changed, 26 insertions, 12 deletions
diff --git a/scrambles.txt b/scrambles.txt
index 43a8f60..285409c 100644
--- a/scrambles.txt
+++ b/scrambles.txt
@@ -3,3 +3,4 @@ B U2 D L2 F D2 U2 R' U' R2 D' F L' D B D' L2 U2 R2 U' B' F2 D2 F2 U2
D R' B R2 B' L2 F2 D2 L2 R' B2 L D2 U2 L R2 D L R2 U2 F2 U' D' B U
B2 F2 D2 R2 D2 U' L2 R2 F2 D2 F L R' B L2 R' B R' F' R2 L' B2 R2 U' B2
D' B2 R' D' L' R' B2 U L' D' U2 R' F U2 L2 U2 F' D' B2 F' U' L D U L'
+F U' F2 D' B U R' F' L D' R' U' L U B' D2 R' F U2 D2
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";