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

appendsolution_tests.c (1659B)


      1 /*
      2 Input format for appendsolution tests:
      3 
      4 moves on normal
      5 moves on inverse (without parentheses)
      6 unniss flag (0=false, 1=true)
      7 number of transformations
      8 transformations, one per line
      9 
     10 See below for the output format.
     11 */
     12 
     13 #include "../test.h"
     14 
     15 uint8_t readtrans(const char [NISSY_SIZE_TRANSFORMATION]);
     16 int64_t readmoves(const char *, size_t n, uint8_t [n]);
     17 void solution_moves_reset(solution_moves_t [static 1]);
     18 bool solution_list_init(solution_list_t [static 1], size_t n, char [n]);
     19 int64_t appendsolution(const solution_moves_t [static 1],
     20     const solution_settings_t [static 1], solution_list_t [static 1]);
     21 
     22 void run(void) {
     23 	int i, ntrans;
     24 	char str[STRLENMAX], buf[STRLENMAX];
     25 	solution_moves_t moves;
     26 	solution_settings_t settings;
     27 	solution_list_t list;
     28 
     29 	solution_moves_reset(&moves);
     30 	solution_list_init(&list, STRLENMAX, buf);
     31 	settings = (solution_settings_t) {
     32 		.tmask = UINT64_C(0),
     33 		.unniss = false,
     34 		.maxmoves = 20,
     35 		.maxsolutions = 100,
     36 		.optimal = -1,
     37 	};
     38 
     39 	fgets(str, STRLENMAX, stdin);
     40 	moves.nmoves = (uint8_t)readmoves(str, 20, moves.moves);
     41 	fgets(str, STRLENMAX, stdin);
     42 	moves.npremoves = (uint8_t)readmoves(str, 20, moves.premoves);
     43 	fgets(str, STRLENMAX, stdin);
     44 	settings.unniss = (bool)atoi(str);
     45 	fgets(str, STRLENMAX, stdin);
     46 	ntrans = atoi(str);
     47 	for (i = 0; i < ntrans; i++) {
     48 		fgets(str, STRLENMAX, stdin);
     49 		settings.tmask |= UINT64_C(1) << (uint64_t)readtrans(str);
     50 	}
     51 
     52 	appendsolution(&moves, &settings, &list);
     53 
     54 	printf("%s", list.buf);
     55 	printf("Number of solutions: %" PRIu64 "\n", list.nsols);
     56 	printf("Shortest solution length: %" PRIu8 "\n", list.shortest_sol);
     57 	printf("Used bytes: %zu\n", list.used);
     58 }