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 (1873B)


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