Block puzzle game loop

"Repetitively stacking or lining up objects is associated with autism."
 * —Wikipedia, "Autism"

"At least he has an excuse."
 * —Encyclopedia Dramatica, "Tetris"

A block puzzle game is a video game involving the manipulation of blocks in the playfield to form patterns. Such a game's core is a state machine that can be broken into two main modules: manipulation and field reaction.

Manipulation
Building games let the player manipulate the field by adding shapes made of blocks. After a short delay, a piece slowly descends into a playfield until it comes to rest on the floor or other blocks, after which it "locks" into place, becoming blocks.
 * In Tetris, Welltris, Blockout, Dr. Mario, Puyo Pop, Bombliss, Pac-Attack, and Super Puzzle Fighter II, the player can shift a piece sideways or rotate it in 90 degree increments as it descends into the playfield. Newer games allow for wall kicks, or slight nudges of a piece that rotates into the wall or into blocks.
 * A few building games, such as Tetris 2 and Hatris, have disjointed pieces. After part of a piece locks, the rest of the piece can still be manipulated.
 * In Columns and Hatris, the player cannot rotate pieces but can rotate the colors of blocks within a piece.
 * Lumines can be analyzed as either shape rotation or color rotation, as can the 180-degree rotations in Hatris and some versions of Puyo Pop and Super Puzzle Fighter II.
 * In Bubble Bath Babes, the player cannot rotate but can instead reflect a piece horizontally or vertically.
 * In WildSnake, the player can remove a block from the tail end of a piece and add it to the left, right, or bottom side of the front end of the piece.
 * In Bust-A-Move, the player chooses an angle before launching single round blocks into a hexagonal cell field.
 * Klax is two games running at once. The conveyor is a catch-and-toss switching game, and the bin is a building game simplified to just sliding and hard drop. Play involves grabbing tiles from the front of the conveyor belt, tossing them halfway up, and then adding them to the field. The challenge here is that both games use the same cursor.
 * Rampart, Pipe Dream, and Star Sweep allow placing blocks anywhere in the field except on top of something else. Pipe Dream also allows replacing any block that hasn't started changing (filling with liquid) yet. The control feels more like a switching game due to the 4-way freedom of movement, but it's still building a pipeline.

Switching games let the player manipulate blocks already in the field. Puzzle games designed for devices with a touch screen tend to be switching games far more often than not.
 * In Yoshi, the player can exchange one entire column of the field for another.
 * In Yoshi's Cookie, the player can shift an entire row or column up or down by one cell, and the piece that shifts off the edge of the rectangular play area wraps to the other side toroidally.
 * In Wario's Woods, the player manipulates a fungus creature that crawls around the left, top, and right edges of blocks and can pick up either a single block to its left or right from a stack or that block and all blocks above it. A creature holding blocks can move sideways with the stack, drop all carried blocks below it, or drop the lowest block or all blocks to the left or right.
 * In SameGame, the player can point at and activate any group of blocks that can react.
 * In Krazy Kreatures, the player can point at one piece and swap it with another.
 * In Puzzle League, the player can swap horizontal pairs of adjacent pieces.
 * In Meteos, the player can swap vertical pairs of adjacent pieces.
 * In Bejeweled, the player can swap horizontal or vertical pairs of pieces, but swaps are undone if they do not cause an immediate field reaction.
 * In Magical Drop, the player can pull a pile of identical pieces from the front of the advancing field or toss it back to the field.
 * In Zoop, the player holds a piece and can shoot it at the piece at the front of the advancing field.
 * In LAN Master, the player can rotate pieces of a pipeline.
 * In solitaire card games (Klondike, FreeCell, etc.), the player can move pieces from one pile to another.

Tetrisphere includes both building and switching elements: the player can move the piece under the cursor or drop another piece on top of it.

Field reaction
As blocks are added to or moved in the field, they react within the field. Most games alternate field reaction phases with manipulation phases, bringing manipulation to a halt until all reactions have cleared up. A few games, such as Puzzle League, Lumines, and Meteos, run reaction and manipulation continuously. A compromise is seen in Wario's Woods, which runs reaction after each step of manipulation, not just after a stack is put down.

Field reaction itself consists of several phases, which generally run in sequence:
 * 1) Pattern detection, such as finding n blocks in a row or n by n squares of one color that will be changed or removed. Also called "line detection".
 * 2) Change, a short delay to animate blocks that are members of patterns. Also called clearing because most blocks that are part of a pattern are removed from the field. But not all changes necessarily are clears.
 * 3) Collapse, moving blocks downward to fill spaces left by blocks that were cleared. Also called "clear gravity".

The most common pattern is n blocks of a specific color adjacent within a row, column, or sometimes diagonal, as seen in Columns, Klax, Dr. Mario, Yoshi's Cookie, Tetris 2, Krazy Kreatures, Wario's Woods, Puzzle League, Bejeweled, and Meteos. Another common pattern is at least n blocks of the same color adjacent, as seen in Puyo Pop, Bubble Bath Babes, Bust-A-Move, The Next Tetris, and Feevo. Some patterns require one of the blocks to be a bomb block, as in Bombliss, Wario's Woods, Super Puzzle Fighter II, and destroyers in Lumines. One rarely seen, perhaps to avoid the appearance of infringement, is blocks spanning the entire width of the screen regardless of color; apart from Tetris, only Pac-Attack seems to use this pattern and even then only on one of its block colors. A hot line is a pattern recognized only in part of the playfield; Tetris Worlds contains a mode where line clears are worth more if made on specific hot lines. A pattern is explosive if one pattern gives a set of blocks that are the "seed" of a change and then another pattern based on this seed determines which larger nearby set of blocks is changed, such as explosions in Bombliss, arrow blocks in Magical Drop, flashing viruses in Tetris 2, destroyers in Lumines, and to a lesser extent garbage clearing in Puyo Pop and Super Puzzle Fighter II. But the specific patterns are nearly as varied as the games themselves and are mostly discussed in articles about individual games.

In most games, all detected patterns will change at the same time, leading to one big collapse. In games with simultaneous manipulation and reaction, such as Klax and Lumines, this can lead to larger patterns as the player adds more blocks during change delay. But Puzzle League can run multiple change phases at once, one for each pattern that the player makes.

Most games produce a larger reward (points in single-player and attacks in multiplayer) for larger patterns or multiple patterns made with one action (a "combo" in the Puzzle League sense). A few reward patterns made with consecutive actions (a "combo" in the Tetris sense) or having consecutive patterns meet a certain threshold (a "back-to-back").

There are about five different kinds of collapse behavior:
 * None: Pieces do not collapse. Seen in Pipe Dream and Krazy Kreatures, whose graphics imply an overhead view, as well as games where all patterns are vertical such as Hatris and Yoshi.
 * Row: Entire rows or columns of blocks move if the row below them was removed in the previous change. Seen in Tetris, Welltris, Blockout, and Yoshi's Cookie, as well as column-wise in Yoshi's Cookie and SameGame. Also called naïve, especially when contrasting standard Tetris with variants that allow recursive line clears.
 * Block: Each individual block moves down if there is not a block below it. Seen in Columns, Klax, older versions of Puyo Pop, SameGame, Wario's Woods, Bejeweled, Lumines, and single-player Puzzle League.
 * Slab: A rectangular slab of blocks moves down if there is not a block below the entire bottom of the slab. Seen in Dr. Mario, multiplayer Puzzle League, Super Puzzle Fighter II, and new versions of Puyo Pop with the big garbage blocks.
 * General: A connected set of blocks with an arbitrary shape moves down if no blocks from a set that isn't also moving down are below it. Seen in Bombliss (all blocks glue together on lock), Tetris 2 and Quadra (only blocks from the same piece glue), and The Next Tetris (only blocks of the same color glue). General collapse often uses a flood fill to find connected sets after clear.

Some games with block gravity run a collapse before pattern detection. Some games repeat pattern detection after collapse to allow chain reactions; this behavior is sometimes called "recursive gravity", and games tend to reward chains formed in this way.