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_multisol.c (1368B)


      1 #include "../tool.h"
      2 
      3 #define SOL_BUFFER_LEN 10000
      4 
      5 int nsol;
      6 char *solver;
      7 int64_t size = 0;
      8 char *buf;
      9 
     10 char *scrambles[] = {
     11 	"U2 D2 F2 B2 L2 R2",
     12 	"R' D R U R' D' R U'", /* Pure 8-move comm */
     13 	"R D' R2 D R U2 R' D' R U2 R D R'", /* 12 mover with sym */
     14 	NULL
     15 };
     16 
     17 void run(void) {
     18 	int i;
     19 	int64_t n;
     20 	long long stats[NISSY_SIZE_SOLVE_STATS];
     21 	char sol[SOL_BUFFER_LEN], cube[22];
     22 
     23 	printf("Solved the following scrambles:\n\n");
     24 	for (i = 0; scrambles[i] != NULL; i++) {
     25 		printf("%d. %s\n", i+1, scrambles[i]);
     26 		printf("Solving scramble %s\n", scrambles[i]);
     27 		if (nissy_applymoves(NISSY_SOLVED_CUBE, scrambles[i], cube)
     28 		     == -1) {
     29 			printf("Invalid scramble\n");
     30 			continue;
     31 		}
     32 		n = nissy_solve(cube, solver, NISSY_NISSFLAG_NORMAL,
     33 		    0, 20, nsol, -1, 0, size, buf, SOL_BUFFER_LEN, sol, stats);
     34 		if (n == 0)
     35 			printf("No solution found\n");
     36 		else
     37 			printf("Solutions:\n%s\n", sol);
     38 	}
     39 }
     40 
     41 int main(int argc, char **argv) {
     42 	char filename[255];
     43 
     44 	if (argc < 3) {
     45 		printf("Error: not enough arguments. "
     46 		    "A solver and a number of solutions must be given.\n");
     47 		return 1;
     48 	}
     49 
     50 	solver = argv[1];
     51 	nsol = atoi(argv[2]);
     52 	srand(time(NULL));
     53 	nissy_setlogger(log_stderr);
     54 
     55 
     56 	sprintf(filename, "tables/%s", solver);
     57 	if (getdata(solver, &buf, filename) != 0)
     58 		return 1;
     59 
     60 	size = nissy_datasize(solver);
     61 
     62 	timerun(run);
     63 
     64 	free(buf);
     65 	return 0;
     66 }