of the linethis will let us split up --line of code|across multiple lines to look prettyrather than just have one very long unreadable line because the parts of this expression in parentheses are joined by or operatorsonly one of them needs to be true for the entire expression to be true each of these parts checks what the intended move is and then sees if the coordinate of the blank space allows that move getting not-so-random move 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(validmovesat the beginning of the gamewe start with the board data structure in the solvedordered state and create the puzzle by randomly sliding around tiles to decide which of the four directions we should slidewe'll call our getrandommove(function normally we could just use the random choice(function and pass it tuple (updownleftrightto have python simply randomly choose direction value for us but the sliding puzzle game has small restriction that prevents us from choosing purely random number if you had slide puzzle and slid tile to leftand then slid tile to the rightyou would end up with the exact same board you had at the start it' pointless to make slide followed by the opposite slide alsoif the blank space is in the lower right corner than it is impossible to slide tile up or to the left the code in getrandommove(will take these factors into account to prevent the function from selecting the last move that was madethe caller of the function can pass directional value for the lastmove parameter line starts with list of all four directional values stored in the validmoves variable the lastmove value (if not set to noneis removed from email questions to the authoral@inventwithpython com