Skip to content

Instantly share code, notes, and snippets.

@pnakibar
Created May 22, 2015 17:41
Show Gist options
  • Save pnakibar/02d0b42ab41526864035 to your computer and use it in GitHub Desktop.
Save pnakibar/02d0b42ab41526864035 to your computer and use it in GitHub Desktop.
why does this fuck my pc
from random import randint
def novaPosAeatoriaGato(labirinto, tabelaCustos):
x = randint(0, len(labirinto[0]))
y = randint(0, len(labirinto))
if labirinto[y][x] == '0':
return aleatorioGato(labirinto, tabelaCustos)
return x,y
moverCima = lambda x,y: (x,y-1)
moverBaixo = lambda x,y: (x, y+1)
moverDireita = lambda x,y: (x+1, y)
moverEsquerda = lambda x,y: (x-1, y)
movimentos = [moverCima,moverBaixo,moverDireita,moverEsquerda]
def acharChar(labirinto, c):
c = c.upper()
for y in range(0, len(labirinto)):
for x in range(0, len(labirinto[y])):
if labirinto[y][x] == c:
return x,y
def acharInicio(labirinto): return acharChar(labirinto, 'S')
def acharFim(labirinto): return acharChar(labirinto, 'F')
def mover(posAtual, direcaoMovimento):
x,y = posAtual
return direcaoMovimento(x,y)
def possiveisMovimentos(posAtual, labirinto, gato):
possiveis = []
for mov in [moverCima, moverEsquerda]:
x, y = mover(posAtual, mov)
if labirinto[y][x] != '0' and (x,y) != gato:
possiveis.append( (x,y) )
return possiveis
def fazRota(posRato, labirinto, gato):
rotas = []
def loop(pos, rota):
r = rota
r.append(pos)
for p in possiveisMovimentos(pos, labirinto, gato):
loop(p, r)
rotas.append(r)
return loop(acharFim(labirinto), [])
def addAround(matrix):
zeroRoll = [ '0'*len(matrix[0]) ]
newMatrix = zeroRoll + matrix + zeroRoll
for e in newMatrix:
newMatrix.append('0' + e + '0')
return newMatrix
labirinto = ['S1100',
'01100',
'01F00']
tabelaCustos = ['12500',
'02100',
'01400']
rato = (1,1)
ratoVisitada = [rato] #adiciona a posicao (0,0 como ja visitada)
#gato = novaPosAeatoriaGato(labirinto, tabelaCustos)
#a = acharFim(labirinto)
#x,y = a
print(addAround(labirinto))
#print(fazRota(rato, labirinto, (1000,1000)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment