diff --git a/2_paradigmas/6_passeio_cavalo.py b/2_paradigmas/6_passeio_cavalo.py index 2eea9ea..a7c7e63 100644 --- a/2_paradigmas/6_passeio_cavalo.py +++ b/2_paradigmas/6_passeio_cavalo.py @@ -21,7 +21,7 @@ def __init__(self, tamanho_tabuleiro, inicio=(0, 0)): ] self.tabuleiro[inicio[0]][inicio[1]] = 1 - def tenta2(self, passo_n, pos_x, pos_y): + def tenta(self, passo_n, pos_x, pos_y): for direcao in self.PASSOS: ctrl_sucesso = False @@ -39,32 +39,10 @@ def tenta2(self, passo_n, pos_x, pos_y): def resolve_sucesso(self, passo_n, x, y): if passo_n - 1 < self.tamanho_tabuleiro ** 2: - return self.tenta2(passo_n, x, y) + return self.tenta(passo_n, x, y) else: return True - def tenta(self, passo_n, pos_x, pos_y): - selec_movimento = -1 - while True: - ctrl_sucesso = False - selec_movimento += 1 - direcao = self.PASSOS[selec_movimento] - pos_u = pos_x + direcao[0] - pos_v = pos_y + direcao[1] - - if self.dentro_do_tabuleiro(pos_u, pos_v): - if self.posicao_vazia(pos_u, pos_v): - self.preenche(passo_n, pos_u, pos_v) - if passo_n < self.tamanho_tabuleiro ** 2: - ctrl_sucesso = self.tenta(passo_n + 1, pos_u, pos_v) - if not ctrl_sucesso: - self.limpa(pos_u, pos_v) - else: - ctrl_sucesso = True - if not (not ctrl_sucesso and (selec_movimento != 7)): - break - return ctrl_sucesso - def posicao_valida(self, x, y): return self.dentro_do_tabuleiro(x, y) and self.posicao_vazia(x, y) @@ -85,5 +63,5 @@ def limpa(self, x, y): if __name__ == "__main__": p = PasseioCavalo(5) - if p.tenta2(2, 0, 0): + if p.tenta(2, 0, 0): pprint(p.tabuleiro)