validmoves depending on if the blank space is at the edge of the boardlines to will remove other directional values from the lastmove list of the values that are left in lastmoveone of them is randomly selected with call to random choice(and returned converting tile coordinates to pixel coordinates def getlefttopoftile(tilextiley) left xmargin (tilex tilesize(tilex top ymargin (tiley tilesize(tiley return (lefttopthe getlefttopoftile(function converts board coordinates to pixel coordinates for the board xy coordinates that are passed inthe function calculates and returns the pixel xy coordinates of the pixel at the top left of that board space converting from pixel coordinates to board coordinates 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 (nonenonethe getspotclicked(function does the opposite of getlefttopoftile(and converts from pixel coordinates to board coordinates the nested loops on lines and go through every possible xy board coordinateand if the pixel coordinates that were passed in are within that space on the boardit returns those board coordinates since all of the tiles have width and height that is set in the tilesize constantwe can create rect object that represents the space on the board by getting the pixel coordinates of the top left corner of the board spaceand then use the collidepoint(rect method to see if the pixel coordinates are inside that rect object' area if the pixel coordinates that were passed in were not over any board spacethen the value (nonenoneis returned drawing tile def drawtile(tilextileynumberadjx= adjy= )