Skip to content

Instantly share code, notes, and snippets.

@tebriel
Forked from visualmotive/README.md
Last active August 29, 2015 13:59
Show Gist options
  • Save tebriel/10539324 to your computer and use it in GitHub Desktop.
Save tebriel/10539324 to your computer and use it in GitHub Desktop.

Sticky gravity is explained in depth here: http://tetrisconcept.net/wiki/Line_clear#Sticky

The playfield is divided into connected segments using flood fill. Any blocks that are adjacent horizontally or vertically are marked as one segment, that is, they are treated as having "stuck" together. Each segment falls independently until it meets the floor or another block. Additional line clears may result.

Sample input and expected output are included in this Gist.

..........
..........
..........
..........
..........
..........
..........
..........
..........
..........
..........
....XX....
....X.....
....X.....
..........
XXXX..XXXX
XXXX.XXXXX
X........X
X........X
XXXX.XXXXX
..........
..........
..........
..........
..........
..........
..........
..........
..........
..........
..........
..........
X.........
XXX.......
..........
......XX..
...XXXXXXX
..XXXX..XX
.XXXXXX.XX
.XXXXXXXXX
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment