for in range(boardwidth) for in range(boardheight) look for horizontal matches if getgemat(boardcopyxy=getgemat(boardcopyx =getgemat(boardcopyx yand getgemat(boardcopyxy!empty_space targetgem boardcopy[ ][ offset removeset [ while getgemat(boardcopyx offsety=targetgem keep checkingin case there' more than gems in row removeset append(( offsety) boardcopy[ offset][yempty_space offset + gemstoremove append(removeset look for vertical matches if getgemat(boardcopyxy=getgemat(boardcopyxy =getgemat(boardcopyxy and getgemat(boardcopyxy!empty_space targetgem boardcopy[ ][ offset removeset [ while getgemat(boardcopyxy offset=targetgem keep checking if there' more than gems in row removeset append((xy offset) boardcopy[ ][ offsetempty_space offset + gemstoremove append(removeset return gemstoremove def highlightspace(xy) pygame draw rect(displaysurfhighlightcolorboardrects[ ][ ] def getdroppinggems(board) find all the gems that have an empty space below them boardcopy copy deepcopy(board droppinggems [ for in range(boardwidth) for in range(boardheight - - ) if boardcopy[ ][ =empty_space and boardcopy[ ][ !empty_space this space drops if not empty but the space below it is