def is_diagonal(width, tile): """ Check if the given tile is along the diagonal of the square grid. Assuming the tile number starts from 1,2, ..., width*height :param width: :param tile: :return: True if the given tile is along the diagonal of the grid. False otherwise """ row = (tile - 1) // width col = (tile - 1) % width if row == col: return True return False def is_edge(width, height, tile): """ Check if the given tile is along the edge of the given grid. Assuming the tile number starts from 1,2, ..., width*height :param width: :param height: :param tile: :return: """ row = (tile - 1) // width # row = 0,1,...,height-1 col = (tile - 1) % width # col = 0,1,...,width-1 if row == 0 or row == height-1: return True if col == 0 or col == width-1: return True return False