Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Vicente Castellano Gómez
/
robotAmbientales
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
437e68e7
authored
May 05, 2024
by
almagosi
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Camino devuelve direccion y casillas
parent
d29bd8bc
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
84 additions
and
8 deletions
camino.py
camino.py
View file @
437e68e7
...
...
@@ -20,6 +20,12 @@ class Direccion(Enum):
Abajo
=
2
Izquierda
=
3
class
MovGiro
(
Enum
):
Izquierda
=
0
Recto
=
1
Derecha
=
2
class
Casilla
:
def
__init__
(
self
,
x
:
int
,
y
:
int
,
codigo_bloque
:
str
):
...
...
@@ -68,6 +74,11 @@ def encontrarCamino(matriz,posicionInicial, posicionFinal):
matriz
=
matrizAdyacencia
(
matriz
)
#print(f'filas {len(matriz)}')
#print(f'columnas {len(matriz[0])}')
#for fila in matriz:
# print(fila)
#print()
solOptima
=
[]
direcOptima
=
[]
...
...
@@ -77,6 +88,7 @@ def encontrarCamino(matriz,posicionInicial, posicionFinal):
def
caminoVueltraAtras
(
direccion
,
posicion
):
global
distOptima
#print(direccion,posicion)
#print(sol)
def
factible
(
direc
,
pos
):
...
...
@@ -153,7 +165,7 @@ def encontrarCamino(matriz,posicionInicial, posicionFinal):
if
(
factible
(
direccion
,
posicion
)):
#print("Factible")
sol
.
append
(
posicion
)
direcciones
.
append
(
direccion
)
...
...
@@ -195,12 +207,76 @@ def encontrarCamino(matriz,posicionInicial, posicionFinal):
caminoVueltraAtras
(
Direccion
.
Arriba
,(
posicionInicial
[
0
]
-
1
,
posicionInicial
[
1
]))
caminoVueltraAtras
(
Direccion
.
Abajo
,(
posicionInicial
[
0
]
+
1
,
posicionInicial
[
1
]))
caminoVueltraAtras
(
Direccion
.
Derecha
,(
posicionInicial
[
0
],
posicionInicial
[
1
]
+
1
))
caminoVueltraAtras
(
Direccion
.
Abajo
,(
posicionInicial
[
0
],
posicionInicial
[
1
]
-
1
))
caminoVueltraAtras
(
Direccion
.
Izquierda
,(
posicionInicial
[
0
],
posicionInicial
[
1
]
-
1
))
# Devuelve el recogido realizado tanto en posiciones como en direcciones
#return solOptima,direcOptima
return
direcOptima
def
arriba
(
posicion
):
return
(
posicion
[
0
]
-
1
,
posicion
[
1
])
def
abajo
(
posicion
):
return
(
posicion
[
0
]
+
1
,
posicion
[
1
])
def
izquierda
(
posicion
):
return
(
posicion
[
0
],
posicion
[
1
]
-
1
)
def
derecha
(
posicion
):
return
(
posicion
[
0
],
posicion
[
1
]
+
1
)
def
crearMov
(
orient
:
Direccion
,
dir
:
Direccion
):
if
(
orient
is
dir
):
return
MovGiro
.
Recto
if
(
orient
is
Direccion
.
Derecha
):
return
MovGiro
(
dir
.
value
)
if
(
orient
is
Direccion
.
Izquierda
):
return
MovGiro
((
dir
.
value
+
2
)
%
4
)
if
(
orient
is
Direccion
.
Arriba
):
return
MovGiro
((
dir
.
value
+
1
)
%
4
)
if
(
orient
is
Direccion
.
Abajo
):
return
MovGiro
((
dir
.
value
-
1
)
%
4
)
#print(f'Direcciones {len(direcOptima)}')
#print(f'Casillas {solOptima}')
pos
=
posicionInicial
listaCasillas
=
[]
orientacion
=
direcOptima
[
0
]
dirs
=
[]
for
direc
in
direcOptima
:
dirs
.
append
(
crearMov
(
orientacion
,
direc
))
if
(
direc
is
Direccion
.
Arriba
):
listaCasillas
.
append
(
arriba
(
pos
))
orientacion
=
Direccion
.
Arriba
if
(
direc
is
Direccion
.
Abajo
):
listaCasillas
.
append
(
abajo
(
pos
))
orientacion
=
Direccion
.
Abajo
if
(
direc
is
Direccion
.
Izquierda
):
listaCasillas
.
append
(
izquierda
(
pos
))
orientacion
=
Direccion
.
Izquierda
if
(
direc
is
Direccion
.
Derecha
):
listaCasillas
.
append
(
derecha
(
pos
))
orientacion
=
Direccion
.
Derecha
#for d in dirs:
# print(d)
#print()
solOptima
.
pop
(
0
)
#for d in solOptima:
# print(d)
#print()
return
dirs
,
solOptima
...
...
@@ -233,9 +309,9 @@ matriz = [["02","02","00","01","05"],
#pos = mAdy[6][0]
#mAdy[6][0] = 2
sol
=
encontrarCamino
(
matriz
,(
5
,
2
),(
6
,
0
))
direc
,
cas
=
encontrarCamino
(
matriz
,(
0
,
0
),(
0
,
3
))
#mAdy[6][0] = pos
for
s
in
sol
:
print
(
s
)
\ No newline at end of file
print
(
len
(
direc
),
len
(
cas
))
for
d
,
c
in
zip
(
direc
,
cas
):
print
(
d
,
c
)
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment