Skip to content

Commit

Permalink
2.6 - Remove tenta, deixa tenta2 como principal
Browse files Browse the repository at this point in the history
  • Loading branch information
vbuxbaum committed Apr 4, 2021
1 parent af5f184 commit 6d49300
Showing 1 changed file with 3 additions and 25 deletions.
28 changes: 3 additions & 25 deletions 2_paradigmas/6_passeio_cavalo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)

Expand All @@ -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)

0 comments on commit 6d49300

Please sign in to comment.