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
864e9503
authored
Apr 23, 2024
by
Alfonso Manuel
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
update camino
parent
ddf6cd86
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
184 additions
and
2 deletions
busqueda.py
casilla.py
busqueda.py
View file @
864e9503
...
...
@@ -120,8 +120,7 @@ def ordenar(posicionActual : Posicion,lista : list):
posicionInicio
=
Posicion
(
6
,
0
)
...
...
casilla.py
0 → 100644
View file @
864e9503
from
enum
import
Enum
from
sys
import
maxsize
class
Bloque
(
Enum
):
Edificio
=
0
Calle_Izquierda_Derecha
=
1
Calle_Arriba_Abajo
=
2
Calle_Arriba_Derecha
=
3
Calle_Derecha_Abajo
=
4
Calle_Abajo_Izquierda
=
5
Calle_Izquierda_Arriba
=
6
Calle_Izquierda_Arriba_Derecha
=
7
Calle_Arriba_Derecha_Abajo
=
8
Calle_Derecha_Abajo_Izquierda
=
9
Calle_Abajo_Izquierda_Arriba
=
10
Calle_Arriba_Derecha_Abajo_Izquierda
=
11
class
Direccion
(
Enum
):
Arriba
=
0
Derecha
=
1
Abajo
=
2
Izquierda
=
3
def
movimientoAceptado
(
direccion
:
Direccion
,
bloquePosterio
:
Bloque
):
if
(
direccion
==
Direccion
.
Arriba
):
arriba
=
[
2
,
4
,
5
,
8
,
9
,
11
]
if
(
bloquePosterio
.
value
==
2
or
bloquePosterio
.
value
==
4
or
bloquePosterio
.
value
==
5
or
bloquePosterio
.
value
==
8
or
bloquePosterio
.
value
==
9
or
bloquePosterio
.
value
==
11
):
return
True
return
False
if
(
direccion
==
Direccion
.
Abajo
):
if
(
bloquePosterio
.
value
==
2
or
bloquePosterio
.
value
==
3
or
bloquePosterio
.
value
==
6
or
bloquePosterio
.
value
==
7
or
bloquePosterio
.
value
==
10
or
bloquePosterio
.
value
==
11
):
return
True
return
False
if
(
direccion
==
Direccion
.
Izquierda
):
if
(
bloquePosterio
.
value
==
1
)
class
Casilla
:
def
__init__
(
self
,
x
:
int
,
y
:
int
,
codigo_bloque
:
str
):
self
.
x
=
x
self
.
y
=
y
self
.
bloque
=
Bloque
(
int
(
codigo_bloque
))
def
__str__
(
self
):
return
f
'x : {self.x} | y : {self.y} | {self.bloque}'
def
convertirMatrizCasillas
(
matriz
):
matCas
=
[]
for
i
in
range
(
len
(
matriz
)):
fila
=
[]
for
j
in
range
(
len
(
matriz
[
0
])):
fila
.
append
(
Casilla
(
i
,
j
,
matriz
[
i
][
j
]))
matCas
.
append
(
fila
)
return
matCas
distOptima
=
100
def
encontrarCamino
(
matriz
,
posicionInicial
,
posicionFinal
):
solOptima
=
[]
direcOptima
=
[]
sol
=
[]
direcciones
=
[]
def
caminoVueltraAtras
(
direccion
,
posicion
):
global
distOptima
def
factible
(
pos
):
#pos = sol[-1]
if
(
pos
[
0
]
<
0
or
pos
[
0
]
>=
len
(
matriz
)
or
pos
[
1
]
<
0
or
pos
[
1
]
>=
len
(
matriz
[
0
])):
return
False
if
(
matriz
[
pos
[
0
]][
pos
[
1
]]
==
0
):
return
False
if
(
len
(
sol
)
+
1
>=
distOptima
):
return
False
return
True
if
(
factible
(
posicion
)):
sol
.
append
(
posicion
)
direcciones
.
append
(
direccion
)
pos
=
sol
[
-
1
]
bq
=
mAdy
[
pos
[
0
]][
pos
[
1
]]
mAdy
[
pos
[
0
]][
pos
[
1
]]
=
0
if
(
pos
!=
posicionFinal
):
caminoVueltraAtras
(
Direccion
.
Arriba
,(
pos
[
0
]
-
1
,
pos
[
1
]))
caminoVueltraAtras
(
Direccion
.
Abajo
,(
pos
[
0
]
+
1
,
pos
[
1
]))
caminoVueltraAtras
(
Direccion
.
Derecha
,(
pos
[
0
],
pos
[
1
]
+
1
))
caminoVueltraAtras
(
Direccion
.
Abajo
,(
pos
[
0
],
pos
[
1
]
-
1
))
else
:
if
(
len
(
sol
)
<
distOptima
):
distOptima
=
len
(
sol
)
solOptima
.
clear
()
direcOptima
.
clear
()
for
i
in
range
(
len
(
sol
)):
solOptima
.
append
(
sol
[
i
])
direcOptima
.
append
(
direcciones
[
i
])
mAdy
[
pos
[
0
]][
pos
[
1
]]
=
bq
sol
.
pop
()
direcciones
.
pop
()
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
))
return
solOptima
,
direcOptima
def
matrizAdyacencia
(
matriz
):
def
dentroTablero
(
coord
):
if
(
coord
[
0
]
<
len
(
matriz
)
and
coord
[
0
]
>=
0
and
coord
[
1
]
<
len
(
matriz
[
0
])
and
coord
[
1
]
>=
0
):
return
True
return
False
matrizCasillas
=
convertirMatrizCasillas
(
matriz
=
matriz
)
matrizAdy
=
[]
for
i
in
range
(
len
(
matriz
)):
fila
=
[]
for
j
in
range
(
len
(
matriz
[
0
])):
if
(
matrizCasillas
[
i
][
j
]
.
bloque
.
value
==
0
):
fila
.
append
(
0
)
else
:
fila
.
append
(
1
)
matrizAdy
.
append
(
fila
)
return
matrizAdy
#02 02 00 01 05
#03 07 05 00 02
#00 04 11 09 06
#01 10 03 10 00
#00 02 00 08 01
#01 10 01 10 00
#01 06 01 07 01
matriz
=
[[
"02"
,
"02"
,
"00"
,
"01"
,
"05"
],
[
"03"
,
"07"
,
"05"
,
"00"
,
"02"
],
[
"00"
,
"04"
,
"11"
,
"09"
,
"06"
],
[
"01"
,
"10"
,
"03"
,
"10"
,
"00"
],
[
"00"
,
"02"
,
"00"
,
"08"
,
"01"
],
[
"01"
,
"10"
,
"01"
,
"10"
,
"00"
],
[
"01"
,
"06"
,
"01"
,
"07"
,
"01"
]]
mAdy
=
matrizAdyacencia
(
matriz
)
mAdy
[
6
][
0
]
=
2
sol
=
encontrarCamino
(
mAdy
,(
6
,
0
),(
4
,
4
))
print
(
sol
[
0
])
print
(
sol
[
1
])
\ 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