// Solve the puzzle! void solver(std::string in, int level) { if (level >= maxLevel) { printf("Found a solution %s\n",in.c_str()); solutions.push_back(in); // Write solutions to a file if (outFile.is_open()) { outFile << in << "\n"; } return; } // Check if we're at a middle level, because those are the most common if (level>0 && level+1<maxLevel) { // Middle levels // Get counts of the base level so that we can save time later std::vector<int> baseCounts = getPieceCounts(in); for (int i=0; i<midBlock.size(); i++) { if (checkAddition(in, leftWidth+(level*midWidth), midBlock.at(i), midWidth, baseCounts) == 0) { if (level==1) { printf("Level... %d %d/%d \tLevel 2 valid count: %d\n",level,i,midBlock.size(),itCount); itCount=0; } else { itCount++; } solver(in+midBlock.at(i) , level+1); } } } else if (level==0) { // Root level for (int i=0; i<leftBlock.size(); i++) { if ( i <= rootIt ) { continue; } printf("Root level... %d/%d\tSolutions: %d\n",i,leftBlock.size(),solutions.size()); solver(leftBlock.at(i), 1); saveRootIt(i); } } else if (level<maxLevel){ // Final level // Get counts of the base level so that we can save time later std::vector<int> baseCounts = getPieceCounts(in); for (int i=0; i<rightBlock.size(); i++) { if (checkAddition(in, puzzleWidth-rightWidth, rightBlock.at(i), rightWidth, baseCounts) == 0) { solver(in+rightBlock.at(i),level+1); } } } return; }
void Game::timerEvent(QTimerEvent*) { // check to see if any addition is necessary checkAddition(); // advance the scene myScene.advance(); // check to see if the score should be increased checkScore(); // check to see if he wants to jump (and can) checkJump(); // check to see if he is stuck in a wall checkWall(); // check to see if he has hit an obstacle checkLose(); // check to see if removal of items is necessary checkDeath(); }
void combiner(Combine com) { std::vector<std::string> leftIn; int leftInWidth; std::vector<std::string> rightIn; int rightInWidth; std::vector<std::string> output; // Figure out which one is used for left/right blocks switch (com) { case LEFT: leftIn = leftBlock; leftInWidth = leftWidth; rightIn = midBlock; rightInWidth = midWidth; break; case MIDDLE: leftIn = midBlock; leftInWidth = midWidth; rightIn = midBlock; rightInWidth = midWidth; break; case RIGHT: leftIn = midBlock; leftInWidth = midWidth; rightIn = rightBlock; rightInWidth = rightWidth; break; default: break; } // Check that we're not getting bigger than the puzzle if ( (leftWidth+rightWidth == puzzleWidth) && (com == LEFT) ) { rightIn = rightBlock; rightInWidth = rightWidth; } else if ( leftWidth+rightWidth > puzzleWidth ) { return; } for (int i=0; i<leftIn.size(); i++) { for (int j=0; j<rightIn.size(); j++) { // Check whether it's good to combine these if ( checkAddition( leftIn.at(i), leftInWidth, rightIn.at(j), rightInWidth) != 0 ) { continue; } // Otherwise, add it back in output.push_back(leftIn.at(i)+rightIn.at(j)); } } switch (com) { case LEFT: leftBlock = output; leftWidth += rightInWidth; break; case MIDDLE: midBlock = output; midWidth += rightInWidth; break; case RIGHT: rightBlock = output; rightWidth += leftInWidth; break; default: break; } }