void generateLink(unsigned short *buffer, int resolution, bool leftLod, bool rightLod, bool upLod, bool downLod, unsigned char *clipBuffer) { int startVertex = lodFactor; int endVertex = resolution - lodFactor - 1; if (!leftLod) { generateTriangles(buffer, resolution, 0, startVertex, startVertex, endVertex, clipBuffer); createFace(buffer, -1, 0, lodFactor * resolution, lodFactor * resolution + lodFactor, clipBuffer); createFace(buffer, -1, (resolution - 1 - lodFactor) * resolution, (resolution - 1) * resolution, (resolution - 1 - lodFactor) * resolution + lodFactor, clipBuffer); //createFace(buffer, -1, 0, lodFactor * resolution, lodFactor); //createFace(buffer, -1, (resolution - 1 - lodFactor) * resolution, (resolution - 1 ) * resolution, (resolution - 1 - lodFactor) * resolution + lodFactor); } else generateHorizontal(buffer, resolution, startVertex, -lodFactor, clipBuffer); if (!rightLod) { generateTriangles(buffer, resolution, endVertex, startVertex, resolution - 1, endVertex, clipBuffer); createFace(buffer, -1, resolution - 1, resolution * lodFactor + resolution - 1 - lodFactor, resolution * lodFactor + resolution - 1, clipBuffer); createFace(buffer, -1, (resolution - 1 - lodFactor) * resolution + resolution - 1 - lodFactor, (resolution - 1) * resolution + resolution - 1, (resolution - 1 - lodFactor) * resolution + resolution - 1, clipBuffer); //createFace(buffer, -1, resolution - 1, resolution * lodFactor + resolution - 1 - lodFactor, resolution * lodFactor + resolution - 1); //createFace(buffer, -1, (resolution - 1) * resolution + resolution - 1 - lodFactor, (resolution - 1) * resolution + resolution - 1, (resolution - 1 - lodFactor) * resolution + resolution - 1); } else generateHorizontal(buffer, resolution, endVertex, lodFactor, clipBuffer); if (!upLod) { generateTriangles(buffer, resolution, startVertex, 0, endVertex, startVertex, clipBuffer); createFace(buffer, -1, 0, resolution * lodFactor + lodFactor, lodFactor, clipBuffer); createFace(buffer, -1, resolution - 1, endVertex, lodFactor * resolution + endVertex, clipBuffer); //createFace(buffer, -1, resolution * lodFactor, resolution * lodFactor + lodFactor, lodFactor); //createFace(buffer, -1, resolution - 1, endVertex, lodFactor * resolution + endVertex); } else generateVertical(buffer, resolution, startVertex, -lodFactor, clipBuffer); if (!downLod) { generateTriangles(buffer, resolution, startVertex, endVertex, endVertex, resolution - 1, clipBuffer); createFace(buffer, -1, (resolution - 1) * resolution, (resolution - 1) * resolution + lodFactor, (resolution - 1 - lodFactor) * resolution + lodFactor, clipBuffer); createFace(buffer, -1, (resolution - 1) * resolution + resolution - 1 - lodFactor, (resolution - 1) * resolution + resolution - 1, (resolution - 1 - lodFactor) * resolution + resolution - 1 - lodFactor, clipBuffer); //createFace(buffer, -1, (resolution - 1) * resolution, (resolution - 1) * resolution + lodFactor, (resolution - 1 - lodFactor) * resolution + lodFactor); //createFace(buffer, -1, (resolution - 1) * resolution + resolution - 1 - lodFactor, (resolution - 1 - lodFactor) * resolution + resolution - 1, (resolution - 1 - lodFactor) * resolution + resolution - 1 - lodFactor); } else generateVertical(buffer, resolution, endVertex, lodFactor, clipBuffer); }
int main() { int restoreState = 1; if (restoreState == 0) { generateVertical(""); printf("LeftBlock count: %d\n",leftBlock.size()); printf("RightBlock count: %d\n",rightBlock.size()); printf("MidBlock count: %d\n",midBlock.size()); for (int i=0; i<2; i++) { printf("Running iteration %d...\n",i); combiner(LEFT); combiner(RIGHT); combiner(MIDDLE); } printf("sorting...\n"); std::sort(leftBlock.begin(), leftBlock.end()); std::sort(rightBlock.begin(), rightBlock.end()); std::sort(midBlock.begin(), midBlock.end()); // Output blocks to file to speed up startup saveBlocks(); } else { // Load blocks from last run loadBlocks(); // Load last iteration loadRootIt(); } printf("\nLeftBlock count: %d\n",leftBlock.size()); printf("RightBlock count: %d\n",rightBlock.size()); printf("MidBlock count: %d\n",midBlock.size()); printf("L: %d M: %d R: %d\n",leftWidth,midWidth,rightWidth); maxLevel = (puzzleWidth-leftWidth-rightWidth)/midWidth + 2; printf("Max Level: %d\n",maxLevel); solver("",0); // Close solutions file outFile.close(); return 0; }
// Recursively create every possible column // Will check to make sure that the column does not have a self // contained island void generateVertical(std::string in) { // Time to add! if (in.length() >= puzzleHeight) { // Check bottom if (pieceHasBottom( getPiece(in,puzzleHeight-1) )) { return; } int r=0, l=0; for (int i=0; i<in.length(); i++) { int piece = getPiece(in,i); // Figure out whether left, right, or middle piece if (pieceHasRight(piece)) { r = 1; } if (pieceHasLeft(piece)) { l = 1; } } // If it's neither left or right, then it's a bad piece if (r==0 && l==0) { return; } // Check if right block if (r==0) { rightBlock.push_back(in); return; } // Check if left block if (l==0) { leftBlock.push_back(in); return; } midBlock.push_back(in); return; } for (int i=1; i<15; i++) { // Check if the piece matches the above state int abovePiece = 0; if (in.length() != 0) { abovePiece = getPiece(in,in.length()-1); } if ( pieceHasBottom(abovePiece) != pieceHasTop(i) ) { continue; } // Check that A is not below B if (i==1 && abovePiece==2) { continue; } // Check if we have too many of a piece int counts[16] = {0}; int broken = 0; for (int j=0; j<in.length(); j++) { int temp = getPiece(in,j); counts[temp]++; if (counts[temp] > numCounts[temp]) { broken = 1; break; } } if (broken == 1) { continue; } // No errors occured, so recurse! generateVertical( in + (char)(i+96) ); } return; }