nissy-core

The "engine" of nissy, including the H48 optimal solver.
git clone https://git.tronto.net/nissy-core
Download | Log | Files | Refs | README | LICENSE

solve_small.c (1559B)


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