def getHeuristic(board): moves = 0 for number in range(1,10): #for each of the 9 numbers targetLocation=number-1 #where SHOULD it be in the string targetRow = targetLocation//3 #what row would that be? targetColumn = targetLocation%3 #What column would that be? currentLocation = board.find(str(number)) #but where is it currentRow = currentLocation//3 #what row currentColumn = currentLocation%3 #what column rowMoves = abs(currentRow-targetRow) #How many moves up/down do I need? columnMoves = abs(currentColumn-targetColumn) #How many moves left/right do I need? moves += rowMoves + columnMoves #Add these moves to the total return moves/4 #remember to divide by 4 because every rotation moves four numbers one place