void CloudsVisualSystemMemory::applyBiDirectionalSort() { int left = 0; int right = blocks.size()-1; int i, j; while (left < right){ for (int poz = left; poz < right; poz++){ if (blocks[poz] > blocks[poz+1]){ swapBlocks(poz, poz+1); } else { blocks[poz].bSelected = false; } right--; for (int pos = right; pos > left; pos--){ if (blocks[pos] < blocks[pos-1]){ swapBlocks(pos, pos-1); } else { blocks[pos].bSelected = false; } left++; } } } }
void CloudsVisualSystemMemory::applyRandomUp(){ int A = ofRandom(xBlocks,blocks.size()-1); int B = A - xBlocks; swapBlocks(A,B, false); }
void JPMiniGame::mixBlocks() { for (int i = 0; i < blocksNum; ++i) { const int r = rand() % blocksNum; swapBlocks(i, r); } }
void CloudsVisualSystemMemory::applyRandomSort(){ int randomCell = int(ofRandom(blocks.size()-1)); if (blocks[randomCell] > blocks[randomCell+1]) { swapBlocks(randomCell, randomCell+1); } else { blocks[randomCell].bSelected = false; } }
void CloudsVisualSystemMemory::applySort(){ for(float i = 0; i < blocks.size()-1; i++){ if ( blocks[i] > blocks[i+1]){ swapBlocks(i, i+1); } else { blocks[i].bSelected = false; } } }
static void sortBlocks(SWHirschbergBlock list[], int start, int end) { SWHirschbergBlock key; int frontIdx; int backIdx; int pivot; if (start < end) { pivot = (start + end) / 2; swapBlocks(&list[start], &list[pivot]); key = list[start]; frontIdx = start + 1; backIdx = end; while (frontIdx <= backIdx) { while ( frontIdx <= end && compareBlocks(&list[frontIdx], &key) <= 0 ) { frontIdx++; } while ( backIdx >= start && compareBlocks(&list[backIdx], &key) > 0 ) { backIdx--; } if (frontIdx < backIdx) { swapBlocks(&list[frontIdx], &list[backIdx]); } } swapBlocks(&list[start], &list[backIdx]); sortBlocks(list, start, backIdx - 1); sortBlocks(list, backIdx + 1, end); } }
void Board::shuffle() { int i, random1, random2; i=0; do { i = 0; while (i < lvl) { random1 = rand()%(DIM*DIM); random2 = rand()%(DIM*DIM); if (random1 != random2) { swapBlocks(random1, random2); i++; } } } while (!isCorrect()); }
void CloudsVisualSystemMemory::applyDeFrag() { // Let's start in a random place // int startIndex = ofRandom(blocks.size()-2); // Search for the first pair that are not sorted // for(float i = startIndex; i < blocks.size()-1; i++){ if ( blocks[i].value > blocks[i+1].value ){ blocks[i+1].bSelected = true; startIndex = i+1; break; } else { blocks[i].bSelected = false; } } // Define the header and what to search for // int searchFor = blocks[ startIndex ].value; int header = startIndex+1; // Search for all the elements that have that value // vector< int > indexes; for(float i = header; i < blocks.size(); i++){ if ( blocks[i].value == searchFor ){ blocks[i].bSelected = true; indexes.push_back(i); } else { blocks[i].bSelected = false; } } // Go one by one and put them continusly on right next to the beging of the header. // for (int i = 0; i < indexes.size(); i++){ if ( header < blocks.size() ){ swapBlocks( header, indexes[i]); header++; } else { break; } } }
void JPMiniGame::Click(float x, float y) { const int otherBlock = blockNum(x, y); // не двигать больше уже поставленные на место if (otherBlock == blocks[otherBlock]) { return; } // выбрать, если ничего не выбрано if (-1 == selectedBlock) { selectedBlock = otherBlock; return; } swapBlocks(selectedBlock, otherBlock); selectedBlock = -1; }
void CloudsVisualSystemMemory::applyRandomDown(){ int A = ofRandom(0,blocks.size()-1-xBlocks); int B = A + xBlocks; swapBlocks(A,B, false); }
void CloudsVisualSystemMemory::applyRandomMix(){ swapBlocks(ofRandom(blocks.size()-1), ofRandom(blocks.size()-1)); }