generating garbage lines - xale/iTetrinet GitHub Wiki

Under certain circumstances, (specifically, the “addline” special block and the creation of a field with a non-zero initial stack size) you will need to generate lines of “random garbage” to add to the field. The GTetrinet source code, which claims in a comment to be imitating the official TetriNET client behavior, uses this algorithm:

1. At random, set each cell in the row to contain a colored block or empty space.
2. To ensure there is at least one empty cell, randomly select a cell in the row and set it to empty.

Note that this algorithm can result in a completely empty row.

Example implementation (in C, using BSD’s random(); substitute your favorite language and RNG):

for (int column = 0; column < NUM_COLUMNS; column++)
{
    field_contents[garbage_row][column] = random() % (NUM_CELL_COLORS + 1);
}
field_contents[garbage_row][random() % NUM_COLUMNS] = 0;

A different garbage-line algorithm is used for classic-style adds.

⚠️ **GitHub.com Fallback** ⚠️