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

allowednext_tests.c (728B)


      1 #include "../test.h"
      2 
      3 bool allowednextmove(uint8_t *, uint8_t);
      4 
      5 static char *moves[] = {
      6 	"U", "U2", "U'",
      7 	"D", "D2", "D'",
      8 	"R", "R2", "R'",
      9 	"L", "L2", "L'",
     10 	"F", "F2", "F'",
     11 	"B", "B2", "B'",
     12 };
     13 
     14 void run(void) {
     15 	char movestr[STRLENMAX];
     16 	uint8_t m[100];
     17 	int n, i, j;
     18 
     19 	fgets(movestr, STRLENMAX, stdin);
     20 	n = atoi(movestr);
     21 
     22 	for (i = 0; i < n; i++) {
     23 		fgets(movestr, STRLENMAX, stdin);
     24 		movestr[strcspn(movestr, "\n")] = 0;
     25 		for (j = 0; j < 18; j++)
     26 			if (!strcmp(movestr, moves[j]))
     27 				m[i] = j;
     28 	}
     29 
     30 	fprintf(stderr, "Last two: %s, %s\nNext: %s\n",
     31 	    n > 2 ? moves[m[n-3]] : "-",
     32 	    n > 1 ? moves[m[n-2]] : "-",
     33 	    n > 0 ? moves[m[n-1]] : "-");
     34 	printf("%s\n", allowednextmove(m, n) ? "true" : "false");
     35 }