aboutsummaryrefslogtreecommitdiff
path: root/test/140_appendsolution/appendsolution_tests.c
blob: 483c2082a8205819fe6c62ca4861c314fa0949a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
Input format for appendsolution tests:

moves on normal (with NISS notation)
unniss flag (0=false, 1=true)
n = maximum number of moves for transformations + 1 (at most 20)
n times the following:
  number of transformations
  transformations, one per line
the orientation of the cube, as a number from 0 to 23

See below for the output format.
*/

#include "../test.h"

uint8_t readtrans(const char [NISSY_SIZE_TRANSFORMATION]);
int64_t readmoves(const char *, size_t n, size_t m,
    size_t *, size_t *, uint8_t [n], uint8_t [m]);
void solution_moves_reset(solution_moves_t [NON_NULL]);
bool solution_list_init(solution_list_t [NON_NULL], size_t n, char [n]);
int64_t appendsolution(const solution_moves_t [NON_NULL],
    size_t, const uint64_t *, const solution_settings_t [NON_NULL],
    solution_list_t [NON_NULL]);

void run(void) {
	int i, j, nnt, ntrans;
	int64_t tot;
	uint64_t tmask[20];
	size_t nm, np;
	char str[STRLENMAX], buf[STRLENMAX];
	solution_moves_t moves;
	solution_settings_t settings;
	solution_list_t list;

	solution_moves_reset(&moves);
	solution_list_init(&list, STRLENMAX, buf);
	settings = (solution_settings_t) {
		.unniss = false,
		.maxmoves = 20,
		.maxsolutions = 100,
		.optimal = -1,
	};

	fgets(str, STRLENMAX, stdin);
	tot = readmoves(str, 20, 20, &nm, &np, moves.moves, moves.premoves);
	if (tot < 0) {
		printf("Test error reading moves\n");
		return;
	}
	moves.nmoves = nm;
	moves.npremoves = np;
	fgets(str, STRLENMAX, stdin);
	settings.unniss = (bool)atoi(str);

	fgets(str, STRLENMAX, stdin);
	nnt = atoi(str);
	for (j = 0; j < nnt; j++) {
		fgets(str, STRLENMAX, stdin);
		ntrans = atoi(str);
		for (i = 0; i < ntrans; i++) {
			fgets(str, STRLENMAX, stdin);
			tmask[j] |= UINT64_C(1) << (uint64_t)readtrans(str);
		}
	}
	fgets(str, STRLENMAX, stdin);
	settings.orientation = atoi(str);

	appendsolution(&moves, nnt, tmask, &settings, &list);

	printf("%s", list.buf);
	printf("Number of solutions: %" PRIu64 "\n", list.nsols);
	printf("Shortest solution length: %" PRIu8 "\n", list.shortest_sol);
	printf("Used bytes: %zu\n", list.used);
}

Generated with cgit - Back to sebastiano.tronto.net