Ejemplo n.º 1
0
// Check a cubiecube for solvability. Return the error code.
// 0: Cube is solvable
// -2: Not all 12 edges exist exactly once
// -3: Flip error: One edge has to be flipped
// -4: Not all corners exist exactly once
// -5: Twist error: One corner has to be twisted
// -6: Parity error: Two corners ore two edges have to be exchanged
int cubiecube_verify(CubieCube *cubie) {
	int edge_count[12] = {0};
	int corner_count[8] = {0};
	int sum, c, e, i;

	// edge
	for (e = 0; e < 12; e++) {
		edge_count[(int)(cubie->ep[e])]++;
	}
	for (i = 0; i < 12; i++) {
		if (edge_count[i] != 1) {
			return -2; // missing edges
		}
	}
	for (sum = 0, i = 0; i < 12; i++) {
		sum += cubie->eo[i];
	}
	if (sum % 2 != 0) {
		return -3; // fliped edge
	}

	// corner
	for (c = 0; c < 8; c++) {
		corner_count[(int)(cubie->cp[c])]++;
	}
	for (i = 0; i < 8; i++) {
		if (corner_count[i] != 1) {
			return -4; // missing corners
		}
	}
	for (sum = 0, i = 0; i < 8; i++) {
		sum += cubie->co[i];
	}
	if (sum % 3 != 0) {
		return -5; // twisted corner
	}

	// edges and corners parity check
	if ((edge_parity(cubie) ^ corner_parity(cubie)) != 0) {
		return -6; // parity error
	}
	return 0; // cube ok
}
Ejemplo n.º 2
0
bool Cube::valid() {
    return corner_parity() && permutation_parity() && edge_parity();
}