def is_diagonal(width, tile): """ This function determines if a given tile is along the diagonal of the square grid. Assuming the tile numbers starting at the top-left corner are 1, 2, 3, ..., 49 :param width: width of a square grid :type width: int :param tile: tile to check if it is along the diagonal of the grid :type tile: int :return: True - a tile is along diagonal, False - otherwise :rtype: bool """ row = (tile - 1) // width col = (tile - 1) % width ############# # the following lines of code are to show alternative ways to write code # if row == col: # return True # else: # return False return row == col def is_edge(width, height, tile): """ This function determines if a given tile is on the edge of a grid. Assuming the tile numbers starting at the top-left corner are 1, 2, 3, ..., 49 :param width: width of a grid :type width: int :param height: height of a grid :type height: int :param tile: tile to check if it is on the edge :type tile: int :return: True - a tile is on the edge, False - otherwise :rtype: """ row = (tile - 1) // width col = (tile - 1) % width ############# # the following lines of code are to show alternative ways to write code # if row == 0 or row == height - 1: # return True # if col == 0 or col == width - 1: # return True # # return False # alternative way to write code # if (row == 0 or row == height - 1) or (col == 0 or col == width -1 ): # return True # return False return (row == 0 or row == height - 1) or (col == 0 or col == width - 1) def is_middle(width, height, tile): """ This function determines if a given tile is in the middle row of the grid. :param width: width of a grid :param height: height of a grid :param tile: tile to check if it is in the middle :return: True - a tile is in the middle, False - otherwise """ row = (tile - 1) // width def is_corner(): print(is_diagonal(7, 24)) print(is_diagonal(7, 25)) print(is_edge(7, 8, 4)) print(is_edge(7, 8, 36)) print(is_edge(7, 8, 23)) print(is_middle(7, 8, 23)) print(is_middle(7, 8, 35)) print(is_middle(7, 8, 20)) print(is_middle(7, 7, 24)) print(is_middle(7, 7, 19)) print(is_middle(7, 7, 32))