In order to occupy himself somehow on sleepless nights, he again sat down to write toys for Android. So as soon as the new year, I decided that the toy should be New Year's. For me, the garland is an integral part of the new year and the New Year tree, so the solution came to the idea itself - I will do a puzzle - collect a garland. In the development process, for me there were two interesting points:

public void init() { clearGarland(); // FIFOStack.clear(); // , FIFO Cell currentCell = new Cell(garlandWidth-1,garlandHeight-1,1); // , boolean generationtree = true; int garlandLength = 0; // int maxGarlandLength = 5; // do { switch(currentCell.Position) { // case 1: // garland[currentCell.X][currentCell.Y][0] = 4; break; case 2: // garland[currentCell.X][currentCell.Y][0] = 8; break; case 4: // garland[currentCell.X][currentCell.Y][0] = 1; break; case 8: // garland[currentCell.X][currentCell.Y][0] = 2; break; case 0: // break; } Cell[] neighbCells = searchNeighbours(currentCell); // , ; int neighbCount = 0; // // - X 0, 1 for(int z=0;z<4;z++) { if (neighbCells[z].X >= 0) { neighbCount++; } } // , if ((neighbCount>0)&&(garlandLength < maxGarlandLength)) { // , FIFOStack.push(currentCell); // int randomCell = randomizer.nextInt(neighbCount); // garland[currentCell.X][currentCell.Y][0] = garland[currentCell.X][currentCell.Y][0]+neighbCells[randomCell].Position; // , currentCell = neighbCells[randomCell]; // garlandLength++; // } else { // , garlandLength = 0; // currentCell = FIFOStack.get(); // ( - FIFO) currentCell.Position = 0; if (currentCell.X == -1) generationtree = false; // , false } } while (generationtree); // // , 1,2,4,8 , (3,5,6,7,9,10,11,12,13,14,15) ( ) . randomizeTree(); // , . } 
Source: https://habr.com/ru/post/344558/
All Articles