aboutsummaryrefslogtreecommitdiff
path: root/tools/003_solve_small
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2024-08-29 15:51:33 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2024-08-29 15:51:33 +0200
commit7e6c14a2f6e9e9cbac3431f3085c42bbe474d13d (patch)
treee570ec2fd344d7251a89a0c9ec0da94162e62cfc /tools/003_solve_small
parentb1fc4886520762dfac016cae612da959078ae67e (diff)
downloadnissy-core-7e6c14a2f6e9e9cbac3431f3085c42bbe474d13d.tar.gz
nissy-core-7e6c14a2f6e9e9cbac3431f3085c42bbe474d13d.zip
Refactor tools to remove duplicate code
Diffstat (limited to 'tools/003_solve_small')
-rw-r--r--tools/003_solve_small/solve_small.c55
1 files changed, 6 insertions, 49 deletions
diff --git a/tools/003_solve_small/solve_small.c b/tools/003_solve_small/solve_small.c
index 406e255..dee2b55 100644
--- a/tools/003_solve_small/solve_small.c
+++ b/tools/003_solve_small/solve_small.c
@@ -1,12 +1,12 @@
1#include <pthread.h> 1#include <pthread.h>
2#include <time.h>
3#include "../timerun.h"
4#include "../../src/nissy.h"
5 2
6#define OPTIONS "0;4;20" 3#include "../tool.h"
7 4
5const char *solver = "h48";
6const char *options = "0;4;20";
8const char *filename = "tables/h48h0k4"; 7const char *filename = "tables/h48h0k4";
9char *buf; 8char *buf;
9
10char *scrambles[] = { 10char *scrambles[] = {
11 "R D' R2 D R U2 R' D' R U2 R D R'", /* 12 optimal */ 11 "R D' R2 D R U2 R' D' R U2 R D R'", /* 12 optimal */
12 "RLUD RLUD RLUD", /* 12 optimal */ 12 "RLUD RLUD RLUD", /* 12 optimal */
@@ -28,7 +28,7 @@ void run(void) {
28 continue; 28 continue;
29 } 29 }
30 n = nissy_solve( 30 n = nissy_solve(
31 cube, "h48", OPTIONS, "", 0, 20, 1, -1, buf, sol); 31 cube, "h48", options, "", 0, 20, 1, -1, buf, sol);
32 if (n == 0) 32 if (n == 0)
33 fprintf(stderr, "No solution found, " 33 fprintf(stderr, "No solution found, "
34 "continuing with next scramble\n"); 34 "continuing with next scramble\n");
@@ -36,56 +36,13 @@ void run(void) {
36 printf("\n"); 36 printf("\n");
37} 37}
38 38
39int getdata(int64_t size) {
40 int64_t s;
41 FILE *f;
42
43 buf = malloc(size);
44
45 if ((f = fopen(filename, "rb")) == NULL) {
46 fprintf(stderr, "Table file not found, generating them."
47 " This can take a while.\n");
48 s = nissy_gendata("h48", OPTIONS, buf);
49 if (s != size) {
50 fprintf(stderr, "Error generating table");
51 if (s != -1)
52 fprintf(stderr, " (got %" PRId64 " bytes)", s);
53 fprintf(stderr, "\n");
54 return 1;
55 }
56 if ((f = fopen(filename, "wb")) == NULL) {
57 fprintf(stderr, "Could not write tables to file %s"
58 ", will be regenerated next time.\n", filename);
59 } else {
60 fwrite(buf, size, 1, f);
61 fclose(f);
62 }
63 } else {
64 fprintf(stderr, "Reading tables from file %s\n", filename);
65 fread(buf, size, 1, f);
66 fclose(f);
67 }
68
69 return 0;
70}
71
72int main(void) { 39int main(void) {
73 int64_t size;
74 40
75 srand(time(NULL)); 41 srand(time(NULL));
76
77 nissy_setlogger(log_stderr); 42 nissy_setlogger(log_stderr);
78 size = nissy_datasize("h48", OPTIONS);
79 if (size == -1) {
80 printf("h48 stats: error in datasize\n");
81 return 1;
82 }
83 43
84 if (getdata(size) != 0) { 44 if (getdata(solver, options, &buf, filename) != 0)
85 printf("Error getting table, stopping\n");
86 free(buf);
87 return 1; 45 return 1;
88 }
89 46
90 timerun(run, "small solver benchmark"); 47 timerun(run, "small solver benchmark");
91 48

Generated with cgit - Back to sebastiano.tronto.net