(move =left and blankx !len(board or (move =right and blankx ! def getrandommove(boardlastmove=none) start with full list of all four moves validmoves [updownleftright remove moves from the list as they are disqualified if lastmove =up or not isvalidmove(boarddown) validmoves remove(down if lastmove =down or not isvalidmove(boardup) validmoves remove(up if lastmove =left or not isvalidmove(boardright) validmoves remove(right if lastmove =right or not isvalidmove(boardleft) validmoves remove(left return random move from the list of remaining moves return random choice(validmoves def getlefttopoftile(tilextiley) left xmargin (tilex tilesize(tilex top ymargin (tiley tilesize(tiley return (lefttop def getspotclicked(boardxy) from the pixel coordinatesget the board coordinates for tilex in range(len(board)) for tiley in range(len(board[ ])) lefttop getlefttopoftile(tilextiley tilerect pygame rect(lefttoptilesizetilesize if tilerect collidepoint(xy) return (tilextiley return (nonenone def drawtile(tilextileynumberadjx= adjy= ) draw tile at board coordinates tilex and tileyoptionally few pixels over (determined by adjx and adjy lefttop getlefttopoftile(tilextiley pygame draw rect(displaysurftilecolor(left adjxtop adjytilesizetilesize) textsurf basicfont render(str(number)truetextcoloremail questions to the authoral@inventwithpython com