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

appendsolution_tests.c (2088B)


      1 /*
      2 Input format for appendsolution tests:
      3 
      4 moves on normal (with NISS notation)
      5 unniss flag (0=false, 1=true)
      6 n = maximum number of moves for transformations + 1 (at most 20)
      7 n times the following:
      8   number of transformations
      9   transformations, one per line
     10 the orientation of the cube, as a number from 0 to 23
     11 
     12 See below for the output format.
     13 */
     14 
     15 #include "../test.h"
     16 
     17 uint8_t readtrans(const char [NISSY_SIZE_TRANSFORMATION]);
     18 int64_t readmoves(const char *, size_t n, size_t m,
     19     size_t *, size_t *, uint8_t [n], uint8_t [m]);
     20 void solution_moves_reset(solution_moves_t [static 1]);
     21 bool solution_list_init(solution_list_t [static 1], size_t n, char [n]);
     22 int64_t appendsolution(const solution_moves_t [static 1],
     23     size_t, const uint64_t *, const solution_settings_t [static 1],
     24     solution_list_t [static 1]);
     25 
     26 void run(void) {
     27 	int i, j, nnt, ntrans;
     28 	int64_t tot;
     29 	uint64_t tmask[20];
     30 	size_t nm, np;
     31 	char str[STRLENMAX], buf[STRLENMAX];
     32 	solution_moves_t moves;
     33 	solution_settings_t settings;
     34 	solution_list_t list;
     35 
     36 	solution_moves_reset(&moves);
     37 	solution_list_init(&list, STRLENMAX, buf);
     38 	settings = (solution_settings_t) {
     39 		.unniss = false,
     40 		.maxmoves = 20,
     41 		.maxsolutions = 100,
     42 		.optimal = -1,
     43 	};
     44 
     45 	fgets(str, STRLENMAX, stdin);
     46 	tot = readmoves(str, 20, 20, &nm, &np, moves.moves, moves.premoves);
     47 	if (tot < 0) {
     48 		printf("Test error reading moves\n");
     49 		return;
     50 	}
     51 	moves.nmoves = nm;
     52 	moves.npremoves = np;
     53 	fgets(str, STRLENMAX, stdin);
     54 	settings.unniss = (bool)atoi(str);
     55 
     56 	fgets(str, STRLENMAX, stdin);
     57 	nnt = atoi(str);
     58 	for (j = 0; j < nnt; j++) {
     59 		fgets(str, STRLENMAX, stdin);
     60 		ntrans = atoi(str);
     61 		for (i = 0; i < ntrans; i++) {
     62 			fgets(str, STRLENMAX, stdin);
     63 			tmask[j] |= UINT64_C(1) << (uint64_t)readtrans(str);
     64 		}
     65 	}
     66 	fgets(str, STRLENMAX, stdin);
     67 	settings.orientation = atoi(str);
     68 
     69 	appendsolution(&moves, nnt, tmask, &settings, &list);
     70 
     71 	printf("%s", list.buf);
     72 	printf("Number of solutions: %" PRIu64 "\n", list.nsols);
     73 	printf("Shortest solution length: %" PRIu8 "\n", list.shortest_sol);
     74 	printf("Used bytes: %zu\n", list.used);
     75 }