def number_of_goats_that_can_be_captured(self): cnt = 0 board = deepcopy(self.board) for i in range(5): for j in range(5): if board[i][j] == 'T': operations = x_not_equals_y_operations if i % 2 == j % 2: operations = x_equals_y_operations for offset_x, offset_y in operations: next_i, next_j = i + offset_x, j + offset_y if is_inside_board( next_i, next_j) and board[next_i][next_j] == 'G': next_next_i, next_next_j = i + 2 * offset_x, j + 2 * offset_y if is_inside_board(next_next_i, next_next_j) and \ board[next_next_i][next_next_j] == '_': board[next_i][next_j] = '_' cnt += 1 return cnt
def eat_goats(self): moves = [] for i in range(5): for j in range(5): if self.board[i][j] == 'T': operations = x_not_equals_y_operations if i % 2 == j % 2: operations = x_equals_y_operations for offset_x, offset_y in operations: next_i, next_j = i + offset_x, j + offset_y if is_inside_board( next_i, next_j) and self.board[next_i][next_j] == 'G': next_next_i, next_next_j = i + 2 * offset_x, j + 2 * offset_y if is_inside_board( next_next_i, next_next_j ) and self.board[next_next_i][next_next_j] == '_': moves.append( Move('e', (i, j), (next_next_i, next_next_j), (next_i, next_j))) return moves
def move_goats(self): moves = [] for i in range(5): for j in range(5): if self.board[i][j] == 'G': operations = x_not_equals_y_operations if i % 2 == j % 2: operations = x_equals_y_operations for offset_x, offset_y in operations: next_i, next_j = i + offset_x, j + offset_y if is_inside_board(next_i, next_j) and self.is_vacant( next_i, next_j): moves.append( Move("m", (i, j), (next_i, next_j), None)) return moves
def number_of_movable_tigers(self): cnt = 0 for i in range(5): for j in range(5): operations = x_not_equals_y_operations if i % 2 == j % 2: operations = x_equals_y_operations if self.board[i][j] == 'T': for offset_x, offset_y in operations: next_i, next_j = i + offset_x, j + offset_y if is_inside_board(next_i, next_j) and self.is_vacant( next_i, next_j): cnt += 1 break assert (cnt <= 4) return cnt