From 6b7a5afc38ef710ab2349e72a58e533d69ff4ce4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?In=C3=AAs=20Costa?= <94355111+inesiscosta@users.noreply.github.com> Date: Fri, 15 Nov 2024 15:42:58 +0000 Subject: [PATCH] Changed function names to use get naming convention --- Go.py | 128 +++++++++++------------ tests/ADT_code/ADT_goban.py | 28 ++--- tests/ADT_code/ADT_intersection.py | 8 +- tests/ADT_code/HLF_calculate_points.py | 10 +- tests/ADT_code/HLF_legal_play.py | 4 +- tests/ADT_code/TF_goban.py | 66 ++++++------ tests/ADT_code/TF_intersection.py | 20 ++-- tests/test_private.py | 136 ++++++++++++------------- tests/test_public.py | 18 ++-- 9 files changed, 209 insertions(+), 209 deletions(-) diff --git a/Go.py b/Go.py index 98c2f14..9a215a0 100755 --- a/Go.py +++ b/Go.py @@ -42,9 +42,9 @@ def create_intersection(column:str,row:int) -> 'tuple[str,int]': return (column, row) # Selectors -def obtain_col(intersection: 'tuple[str,int]') -> str: +def get_col(intersection: 'tuple[str,int]') -> str: """ - Obtains the intersection's column. + gets the intersection's column. :param intersection: An intersection. :type intersection: tuple(str,int) @@ -54,9 +54,9 @@ def obtain_col(intersection: 'tuple[str,int]') -> str: """ return intersection[0] -def obtain_row(intersection: 'tuple[str,int]') -> int: +def get_row(intersection: 'tuple[str,int]') -> int: """ - Obtains the intersection's row. + gets the intersection's row. :param intersection: Any valid intersection. :type intersection: tuple(str,int) @@ -78,7 +78,7 @@ def is_intersection(arg: any) -> bool: :rtype: bool """ return isinstance(arg, tuple) and len(arg) == 2 and \ - is_valid_intersection_arguments(obtain_col(arg), obtain_row(arg)) + is_valid_intersection_arguments(get_col(arg), get_row(arg)) # Tests def equal_intersections(intersection1:any, intersection2:any) -> bool: @@ -94,8 +94,8 @@ def equal_intersections(intersection1:any, intersection2:any) -> bool: :rtype: bool """ return is_intersection(intersection1) and is_intersection(intersection2)\ - and obtain_col(intersection1) == obtain_col(intersection2)\ - and obtain_row(intersection1) == obtain_row(intersection2) + and get_col(intersection1) == get_col(intersection2)\ + and get_row(intersection1) == get_row(intersection2) # Transformers (mutators) def intersection_to_str(intersection: 'tuple[str,int]') -> str: @@ -108,7 +108,7 @@ def intersection_to_str(intersection: 'tuple[str,int]') -> str: :return: A string representing the intersection. (External Representation of an Intersection) :rtype: str """ - return obtain_col(intersection) + str(obtain_row(intersection)) + return get_col(intersection) + str(get_row(intersection)) def str_to_intersection(string: str) -> 'tuple[str,int]': """ @@ -123,9 +123,9 @@ def str_to_intersection(string: str) -> 'tuple[str,int]': return create_intersection(string[0], int(string[1:])) # High-Level Functions -def obtain_adjacent_intersections(intersection: 'tuple[str,int]', last_intersection: 'tuple[str,int]') -> 'tuple[tuple[str,int], ...]': +def get_adjacent_intersections(intersection: 'tuple[str,int]', last_intersection: 'tuple[str,int]') -> 'tuple[tuple[str,int], ...]': """ - Obtains the intersections adjacent to an intersection given the board's upmost intersection. + gets the intersections adjacent to an intersection given the board's upmost intersection. :param intersection: Any intersection on the board. :type intersection: tuple[str,int] @@ -136,8 +136,8 @@ def obtain_adjacent_intersections(intersection: 'tuple[str,int]', last_intersect sorted by the reading order of the Go board. :rtype: tuple(tuple(str,int), ...) """ - col, row = obtain_col(intersection), obtain_row(intersection) - max_col, max_row = obtain_col(last_intersection), obtain_row(last_intersection) + col, row = get_col(intersection), get_row(intersection) + max_col, max_row = get_col(last_intersection), get_row(last_intersection) adjacents = [] for x, y in [(0, -1), (-1, 0), (1, 0), (0, 1)]: if "A" <= chr(ord(col) + x) <= max_col and 1 <= row + y <= max_row: @@ -155,7 +155,7 @@ def sort_intersections(tuple_intersections: 'tuple[tuple[str,int], ...]') -> 'tu :rtype: tuple(tuple(str,int), ...) """ return tuple(sorted(tuple_intersections,key=lambda intersection: - (obtain_row(intersection), obtain_col(intersection)))) + (get_row(intersection), get_col(intersection)))) # Stone ADT # Constructors @@ -352,9 +352,9 @@ def create_copy_goban(goban: list) -> list: return [[stone for stone in row] for row in goban] # Deep Copy # Selectors -def obtain_last_intersection(goban: list) -> 'tuple[str,int]': +def get_last_intersection(goban: list) -> 'tuple[str,int]': """ - Obtains the intersection in the top right corner of the goban. + gets the intersection in the top right corner of the goban. :param goban: Any goban. :type goban: list @@ -364,9 +364,9 @@ def obtain_last_intersection(goban: list) -> 'tuple[str,int]': """ return create_intersection(chr(ord("A") + len(goban) - 1), len(goban)) -def obtain_stone(goban: list, intersection: 'tuple[str,int]') -> str: +def get_stone(goban: list, intersection: 'tuple[str,int]') -> str: """ - Obtains the stone at the intersection specified. + gets the stone at the intersection specified. :param goban: A goban. :type goban: list @@ -376,11 +376,11 @@ def obtain_stone(goban: list, intersection: 'tuple[str,int]') -> str: :return: The stone found in the given intersection. :rtype: str """ - return goban[obtain_row(intersection) - 1][ord(obtain_col(intersection)) - ord("A")] + return goban[get_row(intersection) - 1][ord(get_col(intersection)) - ord("A")] -def obtain_chain(goban: list, intersection: 'tuple[str,int]'): +def get_chain(goban: list, intersection: 'tuple[str,int]'): """ - Obtains a chain of intersections connected to the specified intersection. + gets a chain of intersections connected to the specified intersection. :param goban: A goban. :type goban: list @@ -394,9 +394,9 @@ def obtain_chain(goban: list, intersection: 'tuple[str,int]'): def _find_chain(goban, intersection, visited): visited.add(intersection) chain = [intersection] - for adj in obtain_adjacent_intersections(intersection, obtain_last_intersection(goban)): - if adj not in visited and equal_stones(obtain_stone(goban, adj), - obtain_stone(goban, intersection)): + for adj in get_adjacent_intersections(intersection, get_last_intersection(goban)): + if adj not in visited and equal_stones(get_stone(goban, adj), + get_stone(goban, intersection)): chain.extend(_find_chain(goban, adj, visited)) return chain return sort_intersections(tuple(_find_chain(goban, intersection, set()))) @@ -416,7 +416,7 @@ def place_stone(goban: list, intersection: 'tuple[str,int]', stone: str) -> list :return: A modified goban board with the stone placed. :rtype: list """ - goban[obtain_row(intersection)-1][ord(obtain_col(intersection))-ord("A")] = stone + goban[get_row(intersection)-1][ord(get_col(intersection))-ord("A")] = stone return goban def remove_stone(goban: list, intersection: 'tuple[str,int]') -> list: @@ -481,8 +481,8 @@ def is_valid_intersection(goban: list, intersection: 'tuple[str,int]') -> bool: :rtype: bool """ return is_goban(goban) and is_intersection(intersection) and \ - obtain_col(intersection) <= obtain_col(obtain_last_intersection(goban)) and \ - obtain_row(intersection) <= obtain_row(obtain_last_intersection(goban)) + get_col(intersection) <= get_col(get_last_intersection(goban)) and \ + get_row(intersection) <= get_row(get_last_intersection(goban)) # Test def equal_gobans(goban1: list, goban2: list) -> bool: @@ -499,13 +499,13 @@ def equal_gobans(goban1: list, goban2: list) -> bool: """ if not is_goban(goban1) or not is_goban(goban2): return False - last_intersection = obtain_last_intersection(goban1) - if last_intersection != obtain_last_intersection(goban2): + last_intersection = get_last_intersection(goban1) + if last_intersection != get_last_intersection(goban2): return False - dim = obtain_row(last_intersection) + dim = get_row(last_intersection) return all(equal_stones( - obtain_stone(goban1, create_intersection(chr(col + ord("A")), row + 1)), - obtain_stone(goban2, create_intersection(chr(col + ord("A")), row + 1))) + get_stone(goban1, create_intersection(chr(col + ord("A")), row + 1)), + get_stone(goban2, create_intersection(chr(col + ord("A")), row + 1))) for row in range(dim) for col in range(dim)) # Transformer (mutator) @@ -519,20 +519,20 @@ def goban_to_str(goban: list) -> str: :return: A string that represents the goban. :rtype: str """ - dim = obtain_row(obtain_last_intersection(goban)) + dim = get_row(get_last_intersection(goban)) columns = [chr(i) for i in range(ord('A'), ord('A') + dim)] string = ' ' + ' '.join(columns[:dim]) + '\n' for i in range(dim - 1, -1, -1): string += f'{i+1:2} ' + ' '\ - .join(stone_to_str(obtain_stone(goban, create_intersection(columns[col],i+1)))\ + .join(stone_to_str(get_stone(goban, create_intersection(columns[col],i+1)))\ for col in range(dim)) + f' {i+1:2}\n' string += ' ' + ' '.join(columns[:dim]) return string # High-Level Functions -def obtain_territories(goban: list) -> 'tuple[tuple[tuple[str,int], ...], ...]': +def get_territories(goban: list) -> 'tuple[tuple[tuple[str,int], ...], ...]': """ - Obtains the territories in a goban. + gets the territories in a goban. :param goban: A goban. :type goban: list @@ -543,20 +543,20 @@ def obtain_territories(goban: list) -> 'tuple[tuple[tuple[str,int], ...], ...]': """ territories = [] visited = set() - dim = obtain_row(obtain_last_intersection(goban)) + dim = get_row(get_last_intersection(goban)) for row in range(dim): for col in range(dim): intersection = create_intersection(chr(col + ord("A")), row + 1) if intersection not in visited and \ - not is_player_stone(obtain_stone(goban, intersection)): - chain = obtain_chain(goban, intersection) + not is_player_stone(get_stone(goban, intersection)): + chain = get_chain(goban, intersection) territories.append(chain) visited.update(chain) return tuple(sort_intersections(tuple(territory)) for territory in territories) -def obtain_different_adjacents(goban: list, tuple_intersections: 'tuple[tuple[str,int], ...]') -> 'tuple[tuple[str,int], ...]': +def get_different_adjacents(goban: list, tuple_intersections: 'tuple[tuple[str,int], ...]') -> 'tuple[tuple[str,int], ...]': """ - Obtains the adjacents intersections with different stone types. + gets the adjacents intersections with different stone types. :param goban: A goban :type goban: list @@ -570,10 +570,10 @@ def obtain_different_adjacents(goban: list, tuple_intersections: 'tuple[tuple[st """ return sort_intersections(tuple({ adjacent for intersection in tuple_intersections \ - for adjacent in obtain_adjacent_intersections(intersection, obtain_last_intersection(goban)) \ + for adjacent in get_adjacent_intersections(intersection, get_last_intersection(goban)) \ if adjacent not in tuple_intersections and \ - is_player_stone(obtain_stone(goban, adjacent)) != \ - is_player_stone(obtain_stone(goban, intersection))})) + is_player_stone(get_stone(goban, adjacent)) != \ + is_player_stone(get_stone(goban, intersection))})) def play(goban: list, intersection: 'tuple[str,int]', stone: str) -> list: """ @@ -587,17 +587,17 @@ def play(goban: list, intersection: 'tuple[str,int]', stone: str) -> list: """ goban = place_stone(goban, intersection, stone) - for adjacent in obtain_adjacent_intersections( - intersection, obtain_last_intersection(goban)): - if is_player_stone(obtain_stone(goban, adjacent)) and \ - not equal_stones(obtain_stone(goban, adjacent), stone) and \ - not obtain_different_adjacents(goban, obtain_chain(goban, adjacent)): - goban = remove_chain(goban, obtain_chain(goban, adjacent)) + for adjacent in get_adjacent_intersections( + intersection, get_last_intersection(goban)): + if is_player_stone(get_stone(goban, adjacent)) and \ + not equal_stones(get_stone(goban, adjacent), stone) and \ + not get_different_adjacents(goban, get_chain(goban, adjacent)): + goban = remove_chain(goban, get_chain(goban, adjacent)) return goban -def obtain_num_player_stones(goban: list) -> tuple: +def get_num_player_stones(goban: list) -> tuple: """ - Obtains the number of white and black stones in the Goban. + gets the number of white and black stones in the Goban. :param goban: A goban. :type goban: list @@ -605,11 +605,11 @@ def obtain_num_player_stones(goban: list) -> tuple: :return: A tuple containing the number of white and black stones, respectively. :rtype: tuple """ - dim = obtain_row(obtain_last_intersection(goban)) + dim = get_row(get_last_intersection(goban)) columns = [chr(i) for i in range(ord('A'), ord('A') + dim)] - white = sum(is_white_stone(obtain_stone(goban, create_intersection(col, row))) \ + white = sum(is_white_stone(get_stone(goban, create_intersection(col, row))) \ for col in columns[:dim] for row in range(1, dim + 1)) - black = sum(is_black_stone(obtain_stone(goban, create_intersection(col, row))) \ + black = sum(is_black_stone(get_stone(goban, create_intersection(col, row))) \ for col in columns[:dim] for row in range(1, dim + 1)) return (white, black) @@ -623,16 +623,16 @@ def calculate_points(goban: list) -> 'tuple[int, int]': :return: A tuple containing the number of points of the white and black player, respectively. :rtype: tuple """ - territories = obtain_territories(goban) - points = obtain_num_player_stones(goban) + territories = get_territories(goban) + points = get_num_player_stones(goban) white_territory = sum(len(territory) for territory in territories \ - if obtain_different_adjacents(goban, territory) and \ - all(is_white_stone(obtain_stone(goban, intersection)) \ - for intersection in obtain_different_adjacents(goban, territory))) + if get_different_adjacents(goban, territory) and \ + all(is_white_stone(get_stone(goban, intersection)) \ + for intersection in get_different_adjacents(goban, territory))) black_territory = sum(len(territory) for territory in territories \ - if obtain_different_adjacents(goban, territory) and \ - all(is_black_stone(obtain_stone(goban, intersection)) \ - for intersection in obtain_different_adjacents(goban, territory))) + if get_different_adjacents(goban, territory) and \ + all(is_black_stone(get_stone(goban, intersection)) \ + for intersection in get_different_adjacents(goban, territory))) return (points[0] + white_territory, points[1] + black_territory) def is_legal_play(goban: list, intersection: 'tuple[str,int]', stone: str, prev_goban: list) -> bool: @@ -653,7 +653,7 @@ def is_legal_play(goban: list, intersection: 'tuple[str,int]', stone: str, prev_ """ # Argument Validation. If they're invalid the play is illegal. if not is_valid_intersection(goban, intersection) or \ - is_player_stone(obtain_stone(goban, intersection)): + is_player_stone(get_stone(goban, intersection)): return False copy_goban = create_copy_goban(goban) play(copy_goban, intersection, stone) @@ -661,7 +661,7 @@ def is_legal_play(goban: list, intersection: 'tuple[str,int]', stone: str, prev_ if equal_gobans(copy_goban, prev_goban): return False # Checks the Suicide Rule - return obtain_different_adjacents(copy_goban,obtain_chain(copy_goban,intersection)) + return get_different_adjacents(copy_goban,get_chain(copy_goban,intersection)) def player_turn(goban: list, stone: str, prev_goban: list) -> bool: """ diff --git a/tests/ADT_code/ADT_goban.py b/tests/ADT_code/ADT_goban.py index 50cf10f..e177e1e 100644 --- a/tests/ADT_code/ADT_goban.py +++ b/tests/ADT_code/ADT_goban.py @@ -12,12 +12,12 @@ def create_goban(n, white_intersections, black_intersections): type(white_intersections) == tuple and all(is_intersection(i) and is_valid_intersection(goban, i) for i in white_intersections) and \ type(black_intersections) == tuple and all(is_intersection(i) and is_valid_intersection(goban, i) for i in black_intersections): for i in white_intersections: - if is_player_stone(obtain_stone(goban, i)): + if is_player_stone(get_stone(goban, i)): raise ValueError('create_goban: invalid arguments') place_stone(goban, i, create_white_stone()) for i in black_intersections: - if is_player_stone(obtain_stone(goban, i)): + if is_player_stone(get_stone(goban, i)): raise ValueError('create_goban: invalid arguments') place_stone(goban, i, create_black_stone()) return goban @@ -27,25 +27,25 @@ def create_goban(n, white_intersections, black_intersections): def create_copy_goban(board): return [board[0], (board[1][0], board[1][1].copy())] -def obtain_last_intersection(board): +def get_last_intersection(board): LETTERS = tuple('ABCDEFGHIJKLMNOPQRSTUVWXYZ') return create_intersection(LETTERS[board[1][0]-1], board[1][0]) -def obtain_stone(board, pos): +def get_stone(board, pos): if pos in board[1][1]: return board[1][1][pos] else: return create_neutral_stone() -def obtain_chain(board, pos): - state = obtain_stone(board, pos) - last = obtain_last_intersection(board) +def get_chain(board, pos): + state = get_stone(board, pos) + last = get_last_intersection(board) chain, to_check = [], [pos] while to_check: pos = to_check.pop() chain.append(pos) - for new_pos in obtain_adjacent_intersections(pos, last): - if equal_stones(obtain_stone(board, new_pos), state) and new_pos not in chain + to_check: + for new_pos in get_adjacent_intersections(pos, last): + if equal_stones(get_stone(board, new_pos), state) and new_pos not in chain + to_check: to_check.append(new_pos) return sort_intersections(tuple(chain)) @@ -65,17 +65,17 @@ def remove_chain(board, tuplo): def is_goban(arg): def intersection_within_limits(i1, i2): - return 'A' <= obtain_col(i1) <= obtain_col(i2) and 1 <= obtain_row(i1) <= obtain_row(i2) + return 'A' <= get_col(i1) <= get_col(i2) and 1 <= get_row(i1) <= get_row(i2) return isinstance(arg,list) and len(arg) == 2 and type(arg[0]) == int and \ type(arg[1]) == tuple and len(arg[1]) == 2 and type(arg[1][0]) == int and arg[1][0] in (9, 13, 19) \ and type(arg[1][1]) == dict and all(is_intersection(k) for k in arg[1][1]) and \ - all(intersection_within_limits(k, obtain_last_intersection(arg)) for k in arg[1][1]) and \ + all(intersection_within_limits(k, get_last_intersection(arg)) for k in arg[1][1]) and \ all(is_stone(arg[1][1][k]) for k in arg[1][1]) def is_valid_intersection(board, pos): def intersection_within_limits(i1, i2): - return 'A' <= obtain_col(i1) <= obtain_col(i2) and 1 <= obtain_row(i1) <= obtain_row(i2) - return intersection_within_limits(pos, obtain_last_intersection(board)) + return 'A' <= get_col(i1) <= get_col(i2) and 1 <= get_row(i1) <= get_row(i2) + return intersection_within_limits(pos, get_last_intersection(board)) def equal_gobans(g1, g2): if is_goban(g1) and is_goban(g2) and g1[1][0] == g2[1][0]: @@ -90,7 +90,7 @@ def goban_to_str(board): for i in range(n_h): res += '{:>2} '.format(n_h-i) for j in LETTERS[:n_v]: - res += stone_to_str(obtain_stone(board, create_intersection(j, n_h-i))) + ' ' + res += stone_to_str(get_stone(board, create_intersection(j, n_h-i))) + ' ' res += '{:>2}'.format(n_h-i) + '\n' res += ' ' + ''.join(f'{l} ' for l in LETTERS[:n_v]).rstrip() return res diff --git a/tests/ADT_code/ADT_intersection.py b/tests/ADT_code/ADT_intersection.py index d6ab2eb..3e49e26 100644 --- a/tests/ADT_code/ADT_intersection.py +++ b/tests/ADT_code/ADT_intersection.py @@ -5,10 +5,10 @@ def create_intersection(col, lin): raise ValueError("create_intersection: invalid arguments") -def obtain_col(pos): +def get_col(pos): return pos[2][0] -def obtain_row(pos): +def get_row(pos): return pos[1][1] def is_intersection(arg): @@ -18,10 +18,10 @@ def is_intersection(arg): and type(arg[2]) == tuple and len(arg[2]) == 1 and type(arg[2][0]) == str and len(arg[2][0]) == 1 and 'A' <= arg[2][0] <= 'S' def equal_intersections(pos1, pos2): - return is_intersection(pos1) and is_intersection(pos2) and obtain_col(pos1) == obtain_col(pos2) and obtain_row(pos1) == obtain_row(pos2) + return is_intersection(pos1) and is_intersection(pos2) and get_col(pos1) == get_col(pos2) and get_row(pos1) == get_row(pos2) def intersection_to_str(pos): - return f'{obtain_col(pos)}{obtain_row(pos)}' + return f'{get_col(pos)}{get_row(pos)}' def str_to_intersection(s): return create_intersection(s[0], int(s[1:])) \ No newline at end of file diff --git a/tests/ADT_code/HLF_calculate_points.py b/tests/ADT_code/HLF_calculate_points.py index f193cdc..f40fc93 100644 --- a/tests/ADT_code/HLF_calculate_points.py +++ b/tests/ADT_code/HLF_calculate_points.py @@ -1,11 +1,11 @@ def calculate_points(board): - white_points, black_points = obtain_player_stones(board) + white_points, black_points = get_player_stones(board) - for territory in obtain_territories(board): - limits = obtain_different_adjacents(board, territory) + for territory in get_territories(board): + limits = get_different_adjacents(board, territory) if limits: - if all(is_white_stone(obtain_stone(board,i)) for i in limits): + if all(is_white_stone(get_stone(board,i)) for i in limits): white_points += len(territory) - elif all(is_black_stone(obtain_stone(board,i)) for i in limits): + elif all(is_black_stone(get_stone(board,i)) for i in limits): black_points += len(territory) return white_points, black_points \ No newline at end of file diff --git a/tests/ADT_code/HLF_legal_play.py b/tests/ADT_code/HLF_legal_play.py index 5b0781f..f27bf0c 100644 --- a/tests/ADT_code/HLF_legal_play.py +++ b/tests/ADT_code/HLF_legal_play.py @@ -1,9 +1,9 @@ def is_legal_play(board, pos, stone, last_board): if is_valid_intersection(board, pos) and \ - not is_player_stone(obtain_stone(board, pos)): + not is_player_stone(get_stone(board, pos)): new_board = create_copy_goban(board) play(new_board, pos, stone) - if len(obtain_different_adjacents(new_board, obtain_chain(new_board, pos))) == 0: + if len(get_different_adjacents(new_board, get_chain(new_board, pos))) == 0: return False elif equal_gobans(new_board, last_board): return False diff --git a/tests/ADT_code/TF_goban.py b/tests/ADT_code/TF_goban.py index 8b21cd4..46301c0 100644 --- a/tests/ADT_code/TF_goban.py +++ b/tests/ADT_code/TF_goban.py @@ -12,12 +12,12 @@ def create_goban(n, white_intersections, black_intersections): type(white_intersections) == tuple and all(is_intersection(i) and is_valid_intersection(goban, i) for i in white_intersections) and \ type(black_intersections) == tuple and all(is_intersection(i) and is_valid_intersection(goban, i) for i in black_intersections): for i in white_intersections: - if is_player_stone(obtain_stone(goban, i)): + if is_player_stone(get_stone(goban, i)): raise ValueError('create_goban: invalid arguments') place_stone(goban, i, create_white_stone()) for i in black_intersections: - if is_player_stone(obtain_stone(goban, i)): + if is_player_stone(get_stone(goban, i)): raise ValueError('create_goban: invalid arguments') place_stone(goban, i, create_black_stone()) return goban @@ -27,28 +27,28 @@ def create_goban(n, white_intersections, black_intersections): def create_copy_goban(board): return [board[0], (board[1][0], board[1][1].copy())] -def obtain_last_intersection(board): +def get_last_intersection(board): LETTERS = tuple('ABCDEFGHIJKLMNOPQRSTUVWXYZ') return create_intersection(LETTERS[board[1][0]-1], board[1][0]) -def obtain_stone(board, pos): +def get_stone(board, pos): if pos in board[1][1]: return board[1][1][pos] else: return create_neutral_stone() -def obtain_chain(board, pos): +def get_chain(board, pos): - state = obtain_stone(board, pos) - last = obtain_last_intersection(board) + state = get_stone(board, pos) + last = get_last_intersection(board) chain, to_check = [], [pos] while to_check: pos = to_check.pop() chain.append(pos) - for new_pos in obtain_adjacent_intersections(pos, last): - if equal_stones(obtain_stone(board, new_pos), state) and new_pos not in chain + to_check: + for new_pos in get_adjacent_intersections(pos, last): + if equal_stones(get_stone(board, new_pos), state) and new_pos not in chain + to_check: to_check.append(new_pos) return sort_intersections(tuple(chain)) @@ -69,17 +69,17 @@ def remove_chain(board, tuplo): def is_goban(arg): def intersection_within_limits(i1, i2): - return 'A' <= obtain_col(i1) <= obtain_col(i2) and 1 <= obtain_row(i1) <= obtain_row(i2) + return 'A' <= get_col(i1) <= get_col(i2) and 1 <= get_row(i1) <= get_row(i2) return isinstance(arg,list) and len(arg) == 2 and type(arg[0]) == int and \ type(arg[1]) == tuple and len(arg[1]) == 2 and type(arg[1][0]) == int and arg[1][0] in (9, 13, 19) \ and type(arg[1][1]) == dict and all(is_intersection(k) for k in arg[1][1]) and \ - all(intersection_within_limits(k, obtain_last_intersection(arg)) for k in arg[1][1]) and \ + all(intersection_within_limits(k, get_last_intersection(arg)) for k in arg[1][1]) and \ all(is_stone(arg[1][1][k]) for k in arg[1][1]) def is_valid_intersection(board, pos): def intersection_within_limits(i1, i2): - return 'A' <= obtain_col(i1) <= obtain_col(i2) and 1 <= obtain_row(i1) <= obtain_row(i2) - return intersection_within_limits(pos, obtain_last_intersection(board)) + return 'A' <= get_col(i1) <= get_col(i2) and 1 <= get_row(i1) <= get_row(i2) + return intersection_within_limits(pos, get_last_intersection(board)) def equal_gobans(g1, g2): if is_goban(g1) and is_goban(g2) and g1[1][0] == g2[1][0]: @@ -94,22 +94,22 @@ def goban_to_str(board): for i in range(n_h): res += '{:>2} '.format(n_h-i) for j in LETTERS[:n_v]: - res += stone_to_str(obtain_stone(board, create_intersection(j, n_h-i))) + ' ' + res += stone_to_str(get_stone(board, create_intersection(j, n_h-i))) + ' ' res += '{:>2}'.format(n_h-i) + '\n' res += ' ' + ''.join(f'{l} ' for l in LETTERS[:n_v]).rstrip() return res -def obtain_different_adjacents(board, stone_chain): +def get_different_adjacents(board, stone_chain): if stone_chain: - state = obtain_stone(board, stone_chain[0]) + state = get_stone(board, stone_chain[0]) eh_diferente = (lambda x:not is_player_stone(x)) if is_player_stone(state) else is_player_stone liberties = [] for pos in stone_chain: - for new_pos in obtain_adjacent_intersections(pos, obtain_last_intersection(board)): - if eh_diferente(obtain_stone(board, new_pos)) and new_pos not in liberties: + for new_pos in get_adjacent_intersections(pos, get_last_intersection(board)): + if eh_diferente(get_stone(board, new_pos)) and new_pos not in liberties: liberties.append(new_pos) return sort_intersections(tuple(liberties)) @@ -117,44 +117,44 @@ def obtain_different_adjacents(board, stone_chain): def play(board, pos, stone): place_stone(board, pos, stone) - for new_pos in obtain_adjacent_intersections(pos, obtain_last_intersection(board)): - other_stone = obtain_stone(board, new_pos) + for new_pos in get_adjacent_intersections(pos, get_last_intersection(board)): + other_stone = get_stone(board, new_pos) if is_player_stone(other_stone) and not equal_stones(stone, other_stone): - chain = obtain_chain(board, new_pos) - if len(obtain_different_adjacents(board, chain)) == 0: + chain = get_chain(board, new_pos) + if len(get_different_adjacents(board, chain)) == 0: remove_chain(board, chain) return board -def obtain_player_stones(board): +def get_player_stones(board): LETTERS = tuple('ABCDEFGHIJKLMNOPQRSTUVWXYZ') num_w, num_b = 0, 0 white, black = create_white_stone(), create_black_stone() - last_pos = obtain_last_intersection(board) - last_h, last_v = LETTERS.index(obtain_col(last_pos)), obtain_row(last_pos) + last_pos = get_last_intersection(board) + last_h, last_v = LETTERS.index(get_col(last_pos)), get_row(last_pos) for h in LETTERS[:last_h+1]: for v in range(1, last_v+1): pos = create_intersection(h, v) - if equal_stones(white, obtain_stone(board, pos)): + if equal_stones(white, get_stone(board, pos)): num_w+=1 - elif equal_stones(black, obtain_stone(board, pos)): + elif equal_stones(black, get_stone(board, pos)): num_b += 1 return num_w, num_b -def obtain_territories(board): +def get_territories(board): LETTERS = tuple('ABCDEFGHIJKLMNOPQRSTUVWXYZ') all_chains, seen_chains = [], () - last_pos = obtain_last_intersection(board) - last_h, last_v = LETTERS.index(obtain_col(last_pos)), obtain_row(last_pos) + last_pos = get_last_intersection(board) + last_h, last_v = LETTERS.index(get_col(last_pos)), get_row(last_pos) for h in LETTERS[:last_h+1]: for v in range(1, last_v+1): pos = create_intersection(h, v) - if equal_stones(obtain_stone(board, pos), create_neutral_stone()) and pos not in seen_chains: - this_chain = obtain_chain(board, pos) + if equal_stones(get_stone(board, pos), create_neutral_stone()) and pos not in seen_chains: + this_chain = get_chain(board, pos) all_chains.append(this_chain) seen_chains += this_chain - return tuple(sorted(all_chains, key=lambda x:(obtain_row(x[0]), obtain_col(x[0])))) + return tuple(sorted(all_chains, key=lambda x:(get_row(x[0]), get_col(x[0])))) diff --git a/tests/ADT_code/TF_intersection.py b/tests/ADT_code/TF_intersection.py index 0453f1a..a800ae8 100644 --- a/tests/ADT_code/TF_intersection.py +++ b/tests/ADT_code/TF_intersection.py @@ -7,10 +7,10 @@ def create_intersection(col, lin): raise ValueError("create_intersection: invalid arguments") -def obtain_col(pos): +def get_col(pos): return pos[2][0] -def obtain_row(pos): +def get_row(pos): return pos[1][1] def is_intersection(arg): @@ -20,22 +20,22 @@ def is_intersection(arg): and type(arg[2]) == tuple and len(arg[2]) == 1 and type(arg[2][0]) == str and len(arg[2][0]) == 1 and 'A' <= arg[2][0] <= 'S' def equal_intersections(pos1, pos2): - return is_intersection(pos1) and is_intersection(pos2) and obtain_col(pos1) == obtain_col(pos2) and obtain_row(pos1) == obtain_row(pos2) + return is_intersection(pos1) and is_intersection(pos2) and get_col(pos1) == get_col(pos2) and get_row(pos1) == get_row(pos2) def intersection_to_str(pos): - return f'{obtain_col(pos)}{obtain_row(pos)}' + return f'{get_col(pos)}{get_row(pos)}' def str_to_intersection(s): return create_intersection(s[0], int(s[1:])) -def obtain_adjacent_intersections(pos, last_pos): +def get_adjacent_intersections(pos, last_pos): move = { - 'U': lambda x: 0 if obtain_row(x) == obtain_row(last_pos) else create_intersection(obtain_col(x), obtain_row(x)+1), - 'D': lambda x: 0 if obtain_row(x) == 1 else create_intersection(obtain_col(x), obtain_row(x)-1), - 'L': lambda x: '' if obtain_col(x) == 'A' else create_intersection(LETTERS[LETTERS.index(obtain_col(x))-1], obtain_row(x)), - 'R': lambda x: '' if obtain_col(x) == obtain_col(last_pos) else create_intersection(LETTERS[LETTERS.index(obtain_col(x))+1], obtain_row(x)) + 'U': lambda x: 0 if get_row(x) == get_row(last_pos) else create_intersection(get_col(x), get_row(x)+1), + 'D': lambda x: 0 if get_row(x) == 1 else create_intersection(get_col(x), get_row(x)-1), + 'L': lambda x: '' if get_col(x) == 'A' else create_intersection(LETTERS[LETTERS.index(get_col(x))-1], get_row(x)), + 'R': lambda x: '' if get_col(x) == get_col(last_pos) else create_intersection(LETTERS[LETTERS.index(get_col(x))+1], get_row(x)) } return tuple(move[d](pos) for d in ('D', 'L', 'R', 'U') if move[d](pos)) def sort_intersections(tup): - return tuple(sorted(tup, key=lambda x:(obtain_row(x), obtain_col(x)))) + return tuple(sorted(tup, key=lambda x:(get_row(x), get_col(x)))) diff --git a/tests/test_private.py b/tests/test_private.py index cae59ac..6f88be8 100644 --- a/tests/test_private.py +++ b/tests/test_private.py @@ -75,12 +75,12 @@ def test_12(self): class TestPrivateIntersectionColumn: def test_1(self): p = create_intersection('C', 4) - assert obtain_col(p) == 'C' + assert get_col(p) == 'C' class TestPrivateIntersectionLinha: def test_1(self): p = create_intersection('G', 18) - assert obtain_row(p) == 18 + assert get_row(p) == 18 class TestPrivateIntersectionIsInter: def test_1(self): @@ -138,48 +138,48 @@ class TestPrivateIntersectionAdjacentInter: def test_1(self): c = create_intersection('R', 8) l = create_intersection('S', 19) - t_adj = obtain_adjacent_intersections(c, l) + t_adj = get_adjacent_intersections(c, l) assert isinstance(t_adj, tuple) and all((is_intersection(a) for a in t_adj)) def test_2(self): c = create_intersection('R', 8) l = create_intersection('S', 19) - t_adj = obtain_adjacent_intersections(c, l) + t_adj = get_adjacent_intersections(c, l) ref = 'R7, Q8, S8, R9' assert ', '.join((intersection_to_str(a) for a in t_adj)) == ref def test_3(self): c = create_intersection('A', 1) l = create_intersection('S', 19) - t_adj = obtain_adjacent_intersections(c, l) + t_adj = get_adjacent_intersections(c, l) ref = 'B1, A2' assert ', '.join((intersection_to_str(a) for a in t_adj)) == ref def test_4(self): c = create_intersection('A', 7) l = create_intersection('I', 9) - t_adj = obtain_adjacent_intersections(c, l) + t_adj = get_adjacent_intersections(c, l) ref = 'A6, B7, A8' assert ', '.join((intersection_to_str(a) for a in t_adj)) == ref def test_5(self): c = create_intersection('S', 13) l = create_intersection('S', 19) - t_adj = obtain_adjacent_intersections(c, l) + t_adj = get_adjacent_intersections(c, l) ref = 'S12, R13, S14' assert ', '.join((intersection_to_str(a) for a in t_adj)) == ref def test_6(self): c = create_intersection('C', 1) l = create_intersection('S', 19) - t_adj = obtain_adjacent_intersections(c, l) + t_adj = get_adjacent_intersections(c, l) ref = 'B1, D1, C2' assert ', '.join((intersection_to_str(a) for a in t_adj)) == ref def test_7(self): c = create_intersection('S', 19) l = create_intersection('S', 19) - t_adj = obtain_adjacent_intersections(c, l) + t_adj = get_adjacent_intersections(c, l) ref = 'S18, R19' assert ', '.join((intersection_to_str(a) for a in t_adj)) == ref @@ -360,31 +360,31 @@ def test_3(self): c2 = create_copy_goban(c1) assert id(c1) != id(c2) and equal_gobans(c1, c2) -class TestPrivateGobanObtainLastInter: +class TestPrivateGobangetLastInter: def test_1(self): c = create_empty_goban(9) - assert obtain_last_intersection(c) == create_intersection('I',9) + assert get_last_intersection(c) == create_intersection('I',9) def test_2(self): c = create_empty_goban(19) - assert obtain_last_intersection(c) == create_intersection('S',19) + assert get_last_intersection(c) == create_intersection('S',19) def test_3(self): c = create_goban(13, (), ()) - assert obtain_last_intersection(c) == create_intersection('M',13) + assert get_last_intersection(c) == create_intersection('M',13) -class TestPrivateGobanObtainStone: +class TestPrivateGobangetStone: def test_1(self): g = create_empty_goban(9) - s1 = obtain_stone(g, create_intersection('A',1)) - s2 = obtain_stone(g, create_intersection('I',9)) + s1 = get_stone(g, create_intersection('A',1)) + s2 = get_stone(g, create_intersection('I',9)) assert equal_stones(s1, s2) and equal_stones(s1, create_neutral_stone()) def test_2(self): g = create_empty_goban(19) - s1 = obtain_stone(g, create_intersection('A',1)) - s2 = obtain_stone(g, create_intersection('S',19)) + s1 = get_stone(g, create_intersection('A',1)) + s2 = get_stone(g, create_intersection('S',19)) assert equal_stones(s1, s2) and equal_stones(s1, create_neutral_stone()) @@ -393,11 +393,11 @@ def test_3(self): black_intersections = create_intersection('E',1), create_intersection('E',3), create_intersection('F',4) g = create_goban(13, white_intersections, black_intersections) - assert all(is_white_stone(obtain_stone(g, i)) for i in white_intersections) and \ - all(is_black_stone(obtain_stone(g, i)) for i in black_intersections) and \ - all((not is_player_stone(obtain_stone(g, create_intersection(L,N))) for L in 'LM' for N in range(1,14,2))) + assert all(is_white_stone(get_stone(g, i)) for i in white_intersections) and \ + all(is_black_stone(get_stone(g, i)) for i in black_intersections) and \ + all((not is_player_stone(get_stone(g, create_intersection(L,N))) for L in 'LM' for N in range(1,14,2))) -class TestPrivateGobanObtainChain: +class TestPrivateGobangetChain: def test_1(self): g = create_empty_goban(9) ref = 'A1, B1, C1, D1, E1, F1, G1, H1, I1, A2, B2, C2, D2, E2, F2, G2, H2, '\ @@ -405,53 +405,53 @@ def test_1(self): 'H4, I4, A5, B5, C5, D5, E5, F5, G5, H5, I5, A6, B6, C6, D6, E6, F6, '\ 'G6, H6, I6, A7, B7, C7, D7, E7, F7, G7, H7, I7, A8, B8, C8, D8, E8, '\ 'F8, G8, H8, I8, A9, B9, C9, D9, E9, F9, G9, H9, I9' - assert ref == ', '.join(intersection_to_str(i) for i in obtain_chain(g, create_intersection('D',5))) + assert ref == ', '.join(intersection_to_str(i) for i in get_chain(g, create_intersection('D',5))) def test_2(self): white_intersections = 'D2', 'D3', 'D4', 'D5', 'D6', 'E6', 'E7', 'E8', 'F8', 'F9' black_intersections = 'D1', 'E2', 'E3', 'E4', 'E5', 'F6', 'F7', 'G5', 'G8', 'G9' g = create_goban(19, tuple(str_to_intersection(i) for i in white_intersections), tuple(str_to_intersection(i) for i in black_intersections)) ref = 'G5' - assert ref == ', '.join(intersection_to_str(i) for i in obtain_chain(g, create_intersection('G',5))) + assert ref == ', '.join(intersection_to_str(i) for i in get_chain(g, create_intersection('G',5))) def test_3(self): white_intersections = 'D2', 'D3', 'D4', 'D5', 'D6', 'E6', 'E7', 'E8', 'F8', 'F9' black_intersections = 'D1', 'E2', 'E3', 'E4', 'E5', 'F6', 'F7', 'G5', 'G8', 'G9' g = create_goban(9, tuple(str_to_intersection(i) for i in white_intersections), tuple(str_to_intersection(i) for i in black_intersections)) ref = 'E2, E3, E4, E5' - assert ref == ', '.join(intersection_to_str(i) for i in obtain_chain(g, create_intersection('E',3))) + assert ref == ', '.join(intersection_to_str(i) for i in get_chain(g, create_intersection('E',3))) def test_4(self): white_intersections = 'D2', 'D3', 'D4', 'D5', 'D6', 'E6', 'E7', 'E8', 'F8', 'F9' black_intersections = 'D1', 'E2', 'E3', 'E4', 'E5', 'F6', 'F7', 'G5', 'G8', 'G9' g = create_goban(13, tuple(str_to_intersection(i) for i in white_intersections), tuple(str_to_intersection(i) for i in black_intersections)) ref = 'F6, F7' - assert ref == ', '.join(intersection_to_str(i) for i in obtain_chain(g, create_intersection('F',7))) + assert ref == ', '.join(intersection_to_str(i) for i in get_chain(g, create_intersection('F',7))) def test_5(self): white_intersections = 'D2', 'D3', 'D4', 'D5', 'D6', 'E6', 'E7', 'E8', 'F8', 'F9' black_intersections = 'D1', 'E2', 'E3', 'E4', 'E5', 'F6', 'F7', 'G5', 'G8', 'G9' g = create_goban(9, tuple(str_to_intersection(i) for i in white_intersections), tuple(str_to_intersection(i) for i in black_intersections)) ref = 'E1, F1, G1, H1, I1, F2, G2, H2, I2, F3, G3, H3, I3, F4, G4, H4, I4, F5, H5, I5, G6, H6, I6, G7, H7, I7, H8, I8, H9, I9' - assert ref == ', '.join(intersection_to_str(i) for i in obtain_chain(g, create_intersection('G',6))) + assert ref == ', '.join(intersection_to_str(i) for i in get_chain(g, create_intersection('G',6))) def test_6(self): white_intersections = 'D2', 'D3', 'D4', 'D5', 'D6', 'E6', 'E7', 'E8', 'F8', 'F9' black_intersections = 'D1', 'E2', 'E3', 'E4', 'E5', 'F6', 'F7', 'G5', 'G8', 'G9' g = create_goban(9, tuple(str_to_intersection(i) for i in white_intersections), tuple(str_to_intersection(i) for i in black_intersections)) ref = 'D2, D3, D4, D5, D6, E6, E7, E8, F8, F9' - assert ref == ', '.join(intersection_to_str(i) for i in obtain_chain(g, create_intersection('E',6))) + assert ref == ', '.join(intersection_to_str(i) for i in get_chain(g, create_intersection('E',6))) class TestPrivateGobanPlaceStone: def test_1(self): g1 = create_empty_goban(13) g2 = place_stone(g1, create_intersection('A',1), create_white_stone()) - assert is_white_stone(obtain_stone(g1, create_intersection('A',1))) and id(g1) == id(g2) + assert is_white_stone(get_stone(g1, create_intersection('A',1))) and id(g1) == id(g2) def test_2(self): g = create_empty_goban(19) _ = place_stone(g, create_intersection('A',1), create_white_stone()) _ = place_stone(g, create_intersection('A',1), create_black_stone()) - assert is_black_stone(obtain_stone(g, create_intersection('A',1))) + assert is_black_stone(get_stone(g, create_intersection('A',1))) def test_3(self): white_intersections = 'D2', 'D3', 'D4', 'D5', 'D6', 'E6', 'E7', 'E8', 'F8', 'F9' @@ -460,7 +460,7 @@ def test_3(self): g2 = create_empty_goban(9) for i in white_intersections: place_stone(g2, str_to_intersection(i), create_white_stone()) for i in black_intersections: place_stone(g2, str_to_intersection(i), create_black_stone()) - assert all(equal_stones(obtain_stone(g1, str_to_intersection(i)),obtain_stone(g2, str_to_intersection(i))) for i in white_intersections + black_intersections) + assert all(equal_stones(get_stone(g1, str_to_intersection(i)),get_stone(g2, str_to_intersection(i))) for i in white_intersections + black_intersections) class TestPrivateGobanRemoveStone: def test_1(self): @@ -469,14 +469,14 @@ def test_1(self): g1 = create_goban(9, tuple(str_to_intersection(i) for i in white_intersections), tuple(str_to_intersection(i) for i in black_intersections)) g2 = create_copy_goban(g1) g3 = remove_stone(g1, create_intersection('D',2)) - assert is_white_stone(obtain_stone(g2, create_intersection('D',2))) and not is_player_stone(obtain_stone(g1, create_intersection('D',2))) and id(g1) == id(g3) + assert is_white_stone(get_stone(g2, create_intersection('D',2))) and not is_player_stone(get_stone(g1, create_intersection('D',2))) and id(g1) == id(g3) def test_2(self): g = create_empty_goban(13) _ = place_stone(g, create_intersection('A',1), create_black_stone()) _ = place_stone(g, create_intersection('A',2), create_black_stone()) _ = remove_stone(g, create_intersection('A',1)) - assert not is_player_stone(obtain_stone(g, create_intersection('A',1))) and is_black_stone(obtain_stone(g, create_intersection('A',2))) + assert not is_player_stone(get_stone(g, create_intersection('A',1))) and is_black_stone(get_stone(g, create_intersection('A',2))) def test_3(self): white_intersections = 'D2', 'D3', 'D4', 'D5', 'D6', 'E6', 'E7', 'E8', 'F8', 'F9' @@ -484,7 +484,7 @@ def test_3(self): g1 = create_goban(9, tuple(str_to_intersection(i) for i in white_intersections), tuple(str_to_intersection(i) for i in black_intersections)) g2 = create_empty_goban(9) for i in white_intersections+black_intersections: remove_stone(g1, str_to_intersection(i)) - assert all(equal_stones(obtain_stone(g1, str_to_intersection(i)),obtain_stone(g2, str_to_intersection(i))) for i in white_intersections + black_intersections) + assert all(equal_stones(get_stone(g1, str_to_intersection(i)),get_stone(g2, str_to_intersection(i))) for i in white_intersections + black_intersections) class TestPrivateGobanRemoveChain: def test_1(self): @@ -493,15 +493,15 @@ def test_1(self): g = create_goban(9, tuple(str_to_intersection(i) for i in white_intersections), tuple(str_to_intersection(i) for i in black_intersections)) g2 = remove_chain(g, tuple(str_to_intersection(i) for i in white_intersections[:5])) - assert all(not is_player_stone(obtain_stone(g, str_to_intersection(i))) for i in white_intersections[:5]) and id(g) == id(g2) + assert all(not is_player_stone(get_stone(g, str_to_intersection(i))) for i in white_intersections[:5]) and id(g) == id(g2) def test_2(self): white_intersections = 'D2', 'D3', 'D4', 'D5', 'D6', 'E6', 'E7', 'E8', 'F8', 'F9', 'B1', 'B2', 'B3', 'B4', 'A4', 'C4', 'D9' black_intersections = 'D1', 'E2', 'E3', 'E4', 'E5', 'F6', 'F7', 'G5', 'G8', 'G9' g = create_goban(9, tuple(str_to_intersection(i) for i in white_intersections), tuple(str_to_intersection(i) for i in black_intersections)) - _ = remove_chain(g, obtain_chain(g, create_intersection('D',2))) - assert all(not is_player_stone(obtain_stone(g, str_to_intersection(i))) for i in white_intersections[:-1]) + _ = remove_chain(g, get_chain(g, create_intersection('D',2))) + assert all(not is_player_stone(get_stone(g, str_to_intersection(i))) for i in white_intersections[:-1]) def test_3(self): white_intersections = 'D2', 'D3', 'D4', 'D5', 'D6', 'E6', 'E7', 'E8', 'F8', 'F9', 'B1', 'B2', 'B3', 'B4', 'A4', 'C4', 'D9' @@ -510,7 +510,7 @@ def test_3(self): _ = remove_chain(g, tuple(str_to_intersection(i) for i in white_intersections)) _ = remove_chain(g, tuple(str_to_intersection(i) for i in black_intersections)) - assert all(not is_player_stone(obtain_stone(g, str_to_intersection(L+N))) for L in 'ABCDEFGHI' for N in '123456789') + assert all(not is_player_stone(get_stone(g, str_to_intersection(L+N))) for L in 'ABCDEFGHI' for N in '123456789') def test_4(self): white_intersections = 'D2', 'D3', 'D4', 'D5', 'D6', 'E6', 'E7', 'E8', 'F8', 'F9', 'B1', 'B2', 'B3', 'B4', 'A4', 'C4', 'D9' @@ -518,7 +518,7 @@ def test_4(self): g = create_goban(13, tuple(str_to_intersection(i) for i in white_intersections), tuple(str_to_intersection(i) for i in black_intersections)) g2 = create_copy_goban(g) _ = remove_chain(g, ()) - assert all(equal_stones(obtain_stone(g, str_to_intersection(L+N)), obtain_stone(g2, str_to_intersection(L+N))) for L in 'ABCDEFGHI' for N in '123456789') and id(g) != id(g2) + assert all(equal_stones(get_stone(g, str_to_intersection(L+N)), get_stone(g2, str_to_intersection(L+N))) for L in 'ABCDEFGHI' for N in '123456789') and id(g) != id(g2) class TestPrivateGobanIsGoban: @@ -685,7 +685,7 @@ def test_1(self): 'A5, B5, C5, A6, B6, C6, A7, B7, C7, D7, A8, B8, C8, D8, A9, B9, C9', 'E9') hyp = () - for t in obtain_territories(g): + for t in get_territories(g): hyp += (', '.join(intersection_to_str(i) for i in t),) assert ref == hyp @@ -698,7 +698,7 @@ def test_2(self): place_stone(g, create_intersection(L,N), p[n]) ref = () hyp = () - for t in obtain_territories(g): + for t in get_territories(g): hyp += (', '.join(intersection_to_str(i) for i in t),) assert ref == hyp @@ -707,7 +707,7 @@ def test_3(self): g = create_empty_goban(9) ref = ('A1, B1, C1, D1, E1, F1, G1, H1, I1, A2, B2, C2, D2, E2, F2, G2, H2, I2, A3, B3, C3, D3, E3, F3, G3, H3, I3, A4, B4, C4, D4, E4, F4, G4, H4, I4, A5, B5, C5, D5, E5, F5, G5, H5, I5, A6, B6, C6, D6, E6, F6, G6, H6, I6, A7, B7, C7, D7, E7, F7, G7, H7, I7, A8, B8, C8, D8, E8, F8, G8, H8, I8, A9, B9, C9, D9, E9, F9, G9, H9, I9',) hyp = () - for t in obtain_territories(g): + for t in get_territories(g): hyp += (', '.join(intersection_to_str(i) for i in t),) assert ref == hyp @@ -725,7 +725,7 @@ def test_4(self): 'M5, L6, M6, K7, L7, M7, J8, K8, L8, I9, J9, K9, H10, I10, J10, G11, H11, I11, F12, G12, H12, E13, F13, G13', 'M10, L11, M11, K12, L12, M12, J13, K13, L13') hyp = () - for t in obtain_territories(g): + for t in get_territories(g): hyp += (', '.join(intersection_to_str(i) for i in t),) assert ref == hyp @@ -743,7 +743,7 @@ def test_5(self): 'S10, R11, S11, Q12, R12, S12, P13, Q13, R13, S13, O14, P14, Q14, R14, S14, N15, O15, P15, Q15, R15, M16, N16, O16, P16, Q16, L17, M17, N17, O17, P17, K18, L18, M18, N18, O18, J19, K19, L19, M19, N19', 'S17, R18, S18, Q19, R19, S19') hyp = () - for t in obtain_territories(g): + for t in get_territories(g): hyp += (', '.join(intersection_to_str(i) for i in t),) assert ref == hyp @@ -755,7 +755,7 @@ def test_1(self): t = tuple(str_to_intersection(i) for i in ('A1', 'A2', 'A3')) ref = 'B1, B2, B3, A4' - hyp = ', '.join(intersection_to_str(i) for i in obtain_different_adjacents(g, t)) + hyp = ', '.join(intersection_to_str(i) for i in get_different_adjacents(g, t)) assert ref == hyp def test_2(self): @@ -765,7 +765,7 @@ def test_2(self): t = tuple(str_to_intersection(i) for i in ('E9', 'D8', 'D7', 'G7', 'G6', 'E1')) ref = 'D1, E2, G5, D6, F6, E7, F7, E8, G8, D9, F9' - hyp = ', '.join(intersection_to_str(i) for i in obtain_different_adjacents(g, t)) + hyp = ', '.join(intersection_to_str(i) for i in get_different_adjacents(g, t)) assert ref == hyp def test_3(self): @@ -775,7 +775,7 @@ def test_3(self): t = tuple(str_to_intersection(i) for i in ('B1', 'B2', 'D2', 'B3', 'D3', 'A4', 'B4', 'C4', 'D4', 'D5', 'D6', 'E6', 'E7', 'E8', 'F8', 'F9')) ref = 'A1, C1, A2, C2, A3, C3, A5, B5, C5, C6, D7, D8, E9' - hyp = ', '.join(intersection_to_str(i) for i in obtain_different_adjacents(g, t)) + hyp = ', '.join(intersection_to_str(i) for i in get_different_adjacents(g, t)) assert ref == hyp def test_4(self): @@ -784,21 +784,21 @@ def test_4(self): g = create_goban(9, tuple(str_to_intersection(i) for i in white_intersections), tuple(str_to_intersection(i) for i in black_intersections)) t = tuple(str_to_intersection(i) for i in ('E2', 'E3', 'E4', 'E5')) ref = 'E1, F2, F3, F4, F5' - hyp = ', '.join(intersection_to_str(i) for i in obtain_different_adjacents(g, t)) + hyp = ', '.join(intersection_to_str(i) for i in get_different_adjacents(g, t)) assert ref == hyp def test_5(self): g = create_empty_goban(13) t = tuple(create_intersection(L,N) for L in 'ABCDEFGHIJKLM' for N in range(1,14)) ref = '' - hyp = ', '.join(intersection_to_str(i) for i in obtain_different_adjacents(g, t)) + hyp = ', '.join(intersection_to_str(i) for i in get_different_adjacents(g, t)) assert ref == hyp def test_6(self): t = tuple(create_intersection(L,N) for L in 'ABCDEFGHIJKLMNOPQRS' for N in range(1,20)) g = create_goban(19, t[::2], t[1::2]) ref = '' - hyp = ', '.join(intersection_to_str(i) for i in obtain_different_adjacents(g, t)) + hyp = ', '.join(intersection_to_str(i) for i in get_different_adjacents(g, t)) assert ref == hyp class TestPrivateGobanPlay: @@ -869,7 +869,7 @@ def test_1(self): black_intersections = 'D1', 'E2', 'E3', 'E4', 'E5', 'F6', 'F7', 'G5', 'G8', 'G9' g = create_goban(9, tuple(str_to_intersection(i) for i in white_intersections), tuple(str_to_intersection(i) for i in black_intersections)) ref = (17,10) - assert ref == obtain_num_player_stones(g) + assert ref == get_num_player_stones(g) def test_2(self): g = create_empty_goban(13) @@ -880,7 +880,7 @@ def test_2(self): if n < 2: place_stone(g, create_intersection(L,N), p[n]) ref = (42,42) - assert ref == obtain_num_player_stones(g) + assert ref == get_num_player_stones(g) def test_3(self): g = create_empty_goban(9) @@ -891,7 +891,7 @@ def test_3(self): if n < 3: place_stone(g, create_intersection(L,N), p[(1+n)%2]) ref = (11, 22) - assert ref == obtain_num_player_stones(g) + assert ref == get_num_player_stones(g) class TestPrivateCalculatePoints: @@ -986,17 +986,17 @@ class TestPrivatePlayerTurn: def test_1(self): g = create_empty_goban(9) ref = (True, "Write down an intersection or 'P' to pass the turn [X]:") - assert offline_player_turn(g, create_black_stone(), create_empty_goban(9), 'A1\n') == ref and is_black_stone(obtain_stone(g, create_intersection('A',1))) + assert offline_player_turn(g, create_black_stone(), create_empty_goban(9), 'A1\n') == ref and is_black_stone(get_stone(g, create_intersection('A',1))) def test_2(self): g = create_empty_goban(19) ref = (True, "Write down an intersection or 'P' to pass the turn [O]:Write down an intersection or 'P' to pass the turn [O]:Write down an intersection or 'P' to pass the turn [O]:Write down an intersection or 'P' to pass the turn [O]:") - assert offline_player_turn(g, create_white_stone(), create_empty_goban(19), 'L\n?1\nAA1\nA2\n') == ref and is_white_stone(obtain_stone(g, create_intersection('A',2))) + assert offline_player_turn(g, create_white_stone(), create_empty_goban(19), 'L\n?1\nAA1\nA2\n') == ref and is_white_stone(get_stone(g, create_intersection('A',2))) def test_3(self): g = create_empty_goban(13) ref = (True, "Write down an intersection or 'P' to pass the turn [O]:Write down an intersection or 'P' to pass the turn [O]:Write down an intersection or 'P' to pass the turn [O]:Write down an intersection or 'P' to pass the turn [O]:") - assert offline_player_turn(g, create_white_stone(), create_empty_goban(13), 'D99\nALO\nA?\nI8\n') == ref and is_white_stone(obtain_stone(g, create_intersection('I',8))) + assert offline_player_turn(g, create_white_stone(), create_empty_goban(13), 'D99\nALO\nA?\nI8\n') == ref and is_white_stone(get_stone(g, create_intersection('I',8))) def test_4(self): g = create_empty_goban(9) @@ -1120,7 +1120,7 @@ def test_1(self): c = create_intersection('A', 2) l = create_intersection('S',19) ref = ('A1', 'B2', 'A3') - assert ref == tuple(intersection_to_str(i) for i in obtain_adjacent_intersections(c, l)) + assert ref == tuple(intersection_to_str(i) for i in get_adjacent_intersections(c, l)) def test_2(self): exec(open(f'{ADT_CODE_PATH}/ADT_intersection.py', encoding="utf-8").read(), globals()) @@ -1158,9 +1158,9 @@ def test_3(self): black_intersections = create_intersection('E',1), create_intersection('E',3), create_intersection('F',4) g = create_goban(13, white_intersections, black_intersections) - assert all(is_white_stone(obtain_stone(g, i)) for i in white_intersections) and \ - all(is_black_stone(obtain_stone(g, i)) for i in black_intersections) and \ - all((not is_player_stone(obtain_stone(g, create_intersection(L,N))) for L in 'LM' for N in range(1,14,2))) + assert all(is_white_stone(get_stone(g, i)) for i in white_intersections) and \ + all(is_black_stone(get_stone(g, i)) for i in black_intersections) and \ + all((not is_player_stone(get_stone(g, create_intersection(L,N))) for L in 'LM' for N in range(1,14,2))) def test_4(self): exec(open(f'{ADT_CODE_PATH}/TF_intersection.py', encoding="utf-8").read(), globals()) @@ -1169,7 +1169,7 @@ def test_4(self): black_intersections = 'D1', 'E2', 'E3', 'E4', 'E5', 'F6', 'F7', 'G5', 'G8', 'G9' g = create_goban(9, tuple(str_to_intersection(i) for i in white_intersections), tuple(str_to_intersection(i) for i in black_intersections)) ref = 'E2, E3, E4, E5' - assert ref == ', '.join(intersection_to_str(i) for i in obtain_chain(g, create_intersection('E',3))) + assert ref == ', '.join(intersection_to_str(i) for i in get_chain(g, create_intersection('E',3))) def test_5(self): exec(open(f'{ADT_CODE_PATH}/TF_intersection.py', encoding="utf-8").read(), globals()) @@ -1178,7 +1178,7 @@ def test_5(self): _ = place_stone(g, create_intersection('A',1), create_black_stone()) _ = place_stone(g, create_intersection('A',2), create_black_stone()) _ = remove_stone(g, create_intersection('A',1)) - assert not is_player_stone(obtain_stone(g, create_intersection('A',1))) and is_black_stone(obtain_stone(g, create_intersection('A',2))) + assert not is_player_stone(get_stone(g, create_intersection('A',1))) and is_black_stone(get_stone(g, create_intersection('A',2))) def test_6(self): exec(open(f'{ADT_CODE_PATH}/TF_intersection.py', encoding="utf-8").read(), globals()) @@ -1198,7 +1198,7 @@ def test_7(self): g = create_goban(9, tuple(str_to_intersection(i) for i in white_intersections), tuple(str_to_intersection(i) for i in black_intersections)) g2 = remove_chain(g, tuple(str_to_intersection(i) for i in white_intersections[:5])) - assert all(not is_player_stone(obtain_stone(g, str_to_intersection(i))) for i in white_intersections[:5]) and id(g) == id(g2) + assert all(not is_player_stone(get_stone(g, str_to_intersection(i))) for i in white_intersections[:5]) and id(g) == id(g2) def test_8(self): exec(open(f'{ADT_CODE_PATH}/TF_intersection.py', encoding="utf-8").read(), globals()) @@ -1230,7 +1230,7 @@ def test_10(self): g = create_empty_goban(13) g2 = create_copy_goban(g) _ = place_stone(g, create_intersection('A',2), create_black_stone()) - assert is_black_stone(obtain_stone(g, create_intersection('A',2))) and not is_player_stone(obtain_stone(g2, create_intersection('A',2))) + assert is_black_stone(get_stone(g, create_intersection('A',2))) and not is_player_stone(get_stone(g2, create_intersection('A',2))) def test_11(self): exec(open(f'{ADT_CODE_PATH}/TF_intersection.py', encoding="utf-8").read(), globals()) @@ -1254,8 +1254,8 @@ def test_1(self): black_intersections = 'E4', 'E5', 'F4', 'F5', 'G6', 'G7' for i in white_intersections: place_stone(g, str_to_intersection(i), b) for i in black_intersections: place_stone(g, str_to_intersection(i), p) - chain = obtain_chain(g, create_intersection('F',5)) - liberdades = obtain_different_adjacents(g, chain) + chain = get_chain(g, create_intersection('F',5)) + liberdades = get_different_adjacents(g, chain) assert tuple(intersection_to_str(i) for i in liberdades) == ('E3', 'F3', 'G4', 'D5', 'G5', 'E6', 'F6') def test_2(self): @@ -1269,7 +1269,7 @@ def test_2(self): black_intersections = 'E4', 'E5', 'F4', 'F5', 'G6', 'G7' for i in white_intersections: place_stone(g, str_to_intersection(i), b) for i in black_intersections: place_stone(g, str_to_intersection(i), p) - terr = obtain_territories(g) + terr = get_territories(g) assert tuple(intersection_to_str(i) for i in terr[0]) == ('A1', 'B1', 'A2', 'B2') def test_3(self): @@ -1283,7 +1283,7 @@ def test_3(self): black_intersections = 'E4', 'E5', 'F4', 'F5', 'G6', 'G7' for i in white_intersections: place_stone(g, str_to_intersection(i), b) for i in black_intersections: place_stone(g, str_to_intersection(i), p) - assert obtain_num_player_stones(g) == (8, 6) + assert get_num_player_stones(g) == (8, 6) def test_4(self): exec(open(f'{ADT_CODE_PATH}/TF_intersection.py', encoding="utf-8").read(), globals()) diff --git a/tests/test_public.py b/tests/test_public.py index ac0d863..6fa243d 100644 --- a/tests/test_public.py +++ b/tests/test_public.py @@ -29,7 +29,7 @@ def test_4(self): def test_5(self): intersection1 = create_intersection('A', 2) - assert ('A1', 'B2', 'A3') == tuple(intersection_to_str(i) for i in obtain_adjacent_intersections(intersection1, create_intersection('S',19))) + assert ('A1', 'B2', 'A3') == tuple(intersection_to_str(i) for i in get_adjacent_intersections(intersection1, create_intersection('S',19))) def test_6(self): tup = (create_intersection('A',1), create_intersection('A',3), create_intersection('B',1), create_intersection('B',2)) @@ -62,7 +62,7 @@ def test_2(self): def test_3(self): goban = create_empty_goban(9) intersection1 = create_intersection('C',8) - assert stone_to_str(obtain_stone(goban,intersection1)) == '.' + assert stone_to_str(get_stone(goban,intersection1)) == '.' def test_4(self): goban = create_empty_goban(9) @@ -92,7 +92,7 @@ def test_5(self): black_intersections1 = 'E4', 'E5', 'F4', 'F5', 'G6', 'G7' for i in white_intersections1: place_stone(goban, str_to_intersection(i), white) for i in black_intersections1: place_stone(goban, str_to_intersection(i), black) - cad = obtain_chain(goban, create_intersection('F',5)) + cad = get_chain(goban, create_intersection('F',5)) assert tuple(intersection_to_str(i) for i in cad) == ('E4', 'F4', 'E5', 'F5') def test_6(self): @@ -102,8 +102,8 @@ def test_6(self): black_intersections1 = 'E4', 'E5', 'F4', 'F5', 'G6', 'G7' for i in white_intersections1: place_stone(goban, str_to_intersection(i), white) for i in black_intersections1: place_stone(goban, str_to_intersection(i), black) - chain = obtain_chain(goban, create_intersection('F',5)) - liberties = obtain_different_adjacents(goban, chain) + chain = get_chain(goban, create_intersection('F',5)) + liberties = get_different_adjacents(goban, chain) assert tuple(intersection_to_str(i) for i in liberties) == ('E3', 'F3', 'G4', 'D5', 'G5', 'E6', 'F6') def test_7(self): @@ -113,7 +113,7 @@ def test_7(self): black_intersections1 = 'E4', 'E5', 'F4', 'F5', 'G6', 'G7' for i in white_intersections1: place_stone(goban, str_to_intersection(i), white) for i in black_intersections1: place_stone(goban, str_to_intersection(i), black) - terr = obtain_territories(goban) + terr = get_territories(goban) assert tuple(intersection_to_str(i) for i in terr[0]) == ('A1', 'B1', 'A2', 'B2') def test_8(self): @@ -123,8 +123,8 @@ def test_8(self): black_intersections1 = 'E4', 'E5', 'F4', 'F5', 'G6', 'G7' for i in white_intersections1: place_stone(goban, str_to_intersection(i), b) for i in black_intersections1: place_stone(goban, str_to_intersection(i), p) - terr = obtain_territories(goban) - border = obtain_different_adjacents(goban, terr[0]) + terr = get_territories(goban) + border = get_different_adjacents(goban, terr[0]) assert tuple(intersection_to_str(i) for i in border) == ('C1', 'C2', 'A3', 'B3') def test_9(self): @@ -134,7 +134,7 @@ def test_9(self): black_intersections1 = 'E4', 'E5', 'F4', 'F5', 'G6', 'G7' for i in white_intersections1: place_stone(goban, str_to_intersection(i), b) for i in black_intersections1: place_stone(goban, str_to_intersection(i), p) - assert obtain_num_player_stones(goban) == (8, 6) + assert get_num_player_stones(goban) == (8, 6) def test_10(self): white_intersections1 = tuple(str_to_intersection(i) \