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

gendata.c (1180B)


      1 #include "../tool.h"
      2 #include "../expected_distributions.h"
      3 
      4 char *solver;
      5 uint64_t *expected;
      6 
      7 static void
      8 run(void) {
      9 	int64_t size;
     10 	bool consistent, expected;
     11 	char *buf, filename[1024];
     12 	
     13 	size = generatetable(solver, &buf);
     14 	switch (size) {
     15 	case -1:
     16 		return;
     17 	case -2:
     18 		goto gendata_run_finish;
     19 	default:
     20 		nissy_datainfo(size, buf, write_stdout);
     21 		consistent = nissy_checkdata(size, buf) == 0;
     22 		expected = check_distribution(solver, size, buf);
     23 		if (consistent && expected) {
     24 			printf("\n");
     25 			printf("Generated %" PRId64 " bytes.\n", size);
     26 			sprintf(filename, "tables/%s", solver);
     27 			writetable(buf, size, filename);
     28 		}
     29 		if (!consistent)
     30 			printf("Error: table is not consistent with info"
     31 			    " (nissy_checkdata() failed)\n");
     32 		if (!expected)
     33 			printf("Error: distribution is not as expected\n");
     34 		break;
     35 	}
     36 
     37 gendata_run_finish:
     38 	free(buf);
     39 }
     40 
     41 int main(int argc, char **argv) {
     42 	uint8_t h, k;
     43 
     44 	if (argc < 2) {
     45 		printf("Error: not enough arguments. "
     46 		    "A solver must be given.\n");
     47 		return 1;
     48 	}
     49 
     50 	solver = argv[1];
     51 	parse_h48_solver(solver, &h, &k);
     52 	expected = expected_h48[h][k];
     53 
     54 	nissy_setlogger(log_stderr);
     55 
     56 	timerun(run);
     57 
     58 	return 0;
     59 }