added tests, expanding solution algorithm

This commit is contained in:
Daniel Ledda
2022-12-04 22:18:53 +01:00
parent 58c2b0a720
commit bd52c9a93f
5 changed files with 162 additions and 27 deletions

View File

@@ -43,11 +43,11 @@ namespace Voxel {
}
}
inline auto collides(uint64_t a, uint64_t b) -> bool {
auto collides(uint64_t a, uint64_t b) -> bool {
return (a | b) != (a ^ b);
}
inline auto collides(Space *a, Space *b) -> bool {
auto collides(Space *a, Space *b) -> bool {
return (a->space | b->space) != (a->space ^ b->space);
}
@@ -105,11 +105,12 @@ namespace Voxel {
}
auto rotate90X(Space *space) -> void {
auto new_space = 0ull;
for (int x = 0; x < space->dims[0]; x++) {
for (int y = 0; y < space->dims[1]; y++) {
for (int z = 0; z < space->dims[2]; z++) {
if (filledAt(space->space, space->dims, x, y, z)) {
space->space |= 1 << newIndexRotX(space->dims, x, y, z);
new_space |= 1 << newIndexRotX(space->dims, x, y, z);
}
}
}
@@ -117,14 +118,16 @@ namespace Voxel {
auto temp = space->dims[1];
space->dims[1] = space->dims[2];
space->dims[2] = temp;
space->space = new_space;
}
auto rotate90Y(Space *space) -> void {
auto new_space = 0ull;
for (int x = 0; x < space->dims[0]; x++) {
for (int y = 0; y < space->dims[1]; y++) {
for (int z = 0; z < space->dims[2]; z++) {
if (filledAt(space->space, space->dims, x, y, z)) {
space->space |= 1 << newIndexRotY(space->dims, x, y, z);
new_space |= 1 << newIndexRotY(space->dims, x, y, z);
}
}
}
@@ -132,14 +135,16 @@ namespace Voxel {
auto temp = space->dims[0];
space->dims[0] = space->dims[2];
space->dims[2] = temp;
space->space = new_space;
}
auto rotate90Z(Space *space) -> void {
auto new_space = 0ull;
for (int x = 0; x < space->dims[0]; x++) {
for (int y = 0; y < space->dims[1]; y++) {
for (int z = 0; z < space->dims[2]; z++) {
if (filledAt(space->space, space->dims, x, y, z)) {
space->space |= 1 << newIndexRotZ(space->dims, x, y, z);
new_space |= 1 << newIndexRotZ(space->dims, x, y, z);
}
}
}
@@ -147,6 +152,7 @@ namespace Voxel {
auto temp = space->dims[0];
space->dims[0] = space->dims[1];
space->dims[1] = temp;
space->space = new_space;
}
inline auto isMatch(Space *a, Space *b) -> bool {
@@ -203,6 +209,24 @@ namespace Voxel {
return rotations;
}
auto getUniqueRotations(Space *space) -> std::vector<Space> {
auto rotations = std::vector<Space>();
rotations.reserve(6*24);
auto dims = space->dims;
auto refSpace = *space;
pushNewUniqueSpins(&rotations, &refSpace);
rotate90Y(&refSpace);
pushNewUniqueSpins(&rotations, &refSpace);
rotate90Y(&refSpace);
pushNewUniqueSpins(&rotations, &refSpace);
rotate90Z(&refSpace);
pushNewUniqueSpins(&rotations, &refSpace);
rotate90Z(&refSpace);
rotate90Z(&refSpace);
pushNewUniqueSpins(&rotations, &refSpace);
return rotations;
}
auto getAllRotations(Space *space) -> std::vector<Space> {
auto rotations = std::vector<Space>();
rotations.reserve(6*24);
@@ -212,12 +236,12 @@ namespace Voxel {
rotate90Y(&refSpace);
pushXAxisSpins(&rotations, &refSpace);
rotate90Y(&refSpace);
pushXAxisSpins(&rotations, &refSpace);
pushNewUniqueSpins(&rotations, &refSpace);
rotate90Z(&refSpace);
pushXAxisSpins(&rotations, &refSpace);
pushNewUniqueSpins(&rotations, &refSpace);
rotate90Z(&refSpace);
rotate90Z(&refSpace);
pushXAxisSpins(&rotations, &refSpace);
pushNewUniqueSpins(&rotations, &refSpace);
return rotations;
}