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

common.h (1264B)


      1 STATIC void append_coord_name(const coord_t *, char *);
      2 STATIC bool solution_lastqt_cw(const solution_moves_t [static 1]);
      3 STATIC bool coord_can_switch(
      4     const coord_t [static 1], const void *, size_t n, const uint8_t [n]);
      5 
      6 STATIC void
      7 append_coord_name(const coord_t *coord, char *str)
      8 {
      9 	int i, j;
     10 
     11 	i = 0;
     12 	j = strlen(str);
     13 	while (coord->name[i]) str[j++] = coord->name[i++];
     14 
     15 	str[j] = '\0';
     16 }
     17 
     18 STATIC bool
     19 solution_lastqt_cw(const solution_moves_t s[static 1])
     20 {
     21 	return are_lastmoves_singlecw(s->nmoves, s->moves) &&
     22 	    are_lastmoves_singlecw(s->npremoves, s->premoves);
     23 }
     24 
     25 STATIC bool
     26 coord_can_switch(
     27 	const coord_t coord[static 1],
     28 	const void *data,
     29 	size_t n,
     30 	const uint8_t moves[n]
     31 )
     32 {
     33 	/*
     34 	This function checks that the last move (or two moves, if parallel)
     35 	have a non-trivial effect on the coordinate of the solved cube. This
     36 	works in general for all coordinates that have been used so far, but
     37 	in more general cases that have not been considered yet it may fail.
     38 	*/
     39 
     40 	uint64_t i;
     41 
     42 	if (n == 0)
     43 		return true;
     44 
     45 	i = coord->coord(move(SOLVED_CUBE, moves[n-1]), data);
     46 	if (i == 0)
     47 		return false;
     48 
     49 	if (n == 1 || !parallel(moves[n-1], moves[n-2]))
     50 		return true;
     51 
     52 	i = coord->coord(move(SOLVED_CUBE, moves[n-1]), data);
     53 	return i != 0;
     54 }