h48

A prototype for an optimal Rubik's cube solver, work in progress.
git clone https://git.tronto.net/h48
Download | Log | Files | Refs | README | LICENSE

solve_small.c (1087B)


      1 #include <pthread.h>
      2 
      3 #include "../tool.h"
      4 
      5 const char *solver = "h48";
      6 const char *options = "0;4;20";
      7 const char *filename = "tables/h48h0k4";
      8 char *buf;
      9 
     10 char *scrambles[] = {
     11 	"R D' R2 D R U2 R' D' R U2 R D R'", /* 12 optimal */
     12 	"RLUD RLUD RLUD", /* 12 optimal */
     13 	NULL
     14 };
     15 
     16 void run(void) {
     17 	int i;
     18 	int64_t n;
     19 	char sol[100], cube[22];
     20 
     21 	printf("Solved the following scrambles:\n\n");
     22 	for (i = 0; scrambles[i] != NULL; i++) {
     23 		printf("%d. %s\n", i+1, scrambles[i]);
     24 		fprintf(stderr, "Solving scramble %s\n", scrambles[i]);
     25 		if (nissy_frommoves(scrambles[i], cube) == -1) {
     26 			fprintf(stderr, "Invalid scramble\n");
     27 			printf("Invalid\n");
     28 			continue;
     29 		}
     30 		n = nissy_solve(
     31 		    cube, "h48", options, "", 0, 20, 1, -1, buf, sol);
     32 		if (n == 0) {
     33 			printf("No solution\n");
     34 			fprintf(stderr, "No solution found\n");
     35 		} else {
     36 			printf("Solutions:\n%s\n", sol);
     37 		}
     38 	}
     39 }
     40 
     41 int main(void) {
     42 
     43 	srand(time(NULL));
     44 	nissy_setlogger(log_stderr);
     45 
     46 	if (getdata(solver, options, &buf, filename) != 0)
     47 		return 1;
     48 
     49 	timerun(run, "small solver benchmark");
     50 
     51 	free(buf);
     52 	return 0;
     53 }