for in range(templateheight) if shapes[piece['shape']][piece['rotation']][ ][ !blank board[ piece[' ']][ piece[' ']piece['color' def getblankboard() create and return new blank board data structure board [ for in range(boardwidth) board append([blankboardheight return board def isonboard(xy) return > and boardwidth and boardheight def isvalidposition(boardpieceadjx= adjy= ) return true if the piece is within the board and not colliding for in range(templatewidth) for in range(templateheight) isaboveboard piece[' 'adjy if isaboveboard or shapes[piece['shape']][piece['rotation']][ ][ =blank continue if not isonboard( piece[' 'adjxy piece[' 'adjy) return false if board[ piece[' 'adjx][ piece[' 'adjy!blank return false return true def iscompleteline(boardy) return true if the line filled with boxes with no gaps for in range(boardwidth) if board[ ][ =blank return false return true def removecompletelines(board) remove any completed lines on the boardmove everything above them downand return the number of complete lines numlinesremoved boardheight start at the bottom of the board