Background
Tetris Grand Master 3 has a hidden grading system based on the shape of the stack at the end of the game, which is called Secret ">" Stacking Challenge. It consists of entirely filling the lowest rows except for the zigzag pattern which starts at the left bottom cell and spans the entire width:
#
.#########
#.########
##.#######
###.######
####.#####
#####.####
######.###
#######.##
########.#
#########.
########.#
#######.##
######.###
#####.####
####.#####
###.######
##.#######
#.########
.#########
The board is graded by how many lines follow this exact pattern from the bottom line. Note that the topmost hole in the pattern must be blocked by an extra piece of block. If you consider the #
s and .
s as the mandatory pattern (blanks can be anything), you can get the score of 19 only if the exact pattern above is matched from the bottom line. Analogously, if the board matches this pattern
#
###.######
##.#######
#.########
.#########
but not
#
####.#####
###.######
##.#######
#.########
.#########
then the score is 4.
For this challenge, consider a board of arbitrary size (other than 20 cells high and 10 cells wide). We can grade the board for the same pattern: for example, if the board has width 4, this is the pattern for score 3:
#
##.#
#.##
.###
and this is the pattern for score 10:
#
###.
##.#
#.##
.###
#.##
##.#
###.
##.#
#.##
.###
Challenge
Given the final state of the Tetris board of arbitrary size, grade the board using the system above.
You can take the board using any sensible format for a rectangular matrix, where every cell contains one of two distinct values (for empty and filled respectively). You can assume the grid is a valid Tetris board (no row is entirely filled). Also, the width of the grid is at least 2.
Standard code-golf rules apply. The shortest code in bytes wins.
Test cases
In order to prevent possible confusion, the test cases here use O
for the blocks and .
for empty spaces.
Input:
..O.O
OOOO.
OOO..
OO.OO
O.OOO
.OOOO
Output: 3
Input:
..
O.
.O
.O
O.
.O
O.
.O
Output: 4
Input:
.OOO
O.OO
OO.O
OO.O
OO.O
O.OO
.OOO
Output: 2 (any lines above the first non-conforming line are ignored;
doesn't get 3 because 3rd line's hole is not capped)
Input:
OOO.
.OOO
O.OO
OO.O
OOO.
OO.O
O.OO
Output: 0 (Wrong starting hole)
Input:
.OOO
O.OO
OO.O
OOO.
Output: 0 (Wrong starting hole)
Input:
.OOO
.OOO
Output: 0 (Hole is not covered)
Input:
OOO...O..O
.OOOOOOOOO
O.OOOOOOOO
OO.OOOOOOO
OOO.OOOOOO
OOOO.OOOOO
OOOOO.OOOO
OOOOOO.OOO
OOOOOOO.OO
OOOOOOOO.O
OOOOOOOOO.
OOOOOOOO.O
OOOOOOO.OO
OOOOOO.OOO
OOOOO.OOOO
OOOO.OOOOO
OOO.OOOOOO
OO.OOOOOOO
O.OOOOOOOO
.OOOOOOOOO
Output: 19