Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Adrien Simon
ia02-helltaker
Commits
2eef5bea
Commit
2eef5bea
authored
Jun 15, 2022
by
Adrien Simon
Browse files
added log catcher in asp
parent
78414eb4
Changes
2
Hide whitespace changes
Inline
Side-by-side
asp/helltaker_plan_asp.py
View file @
2eef5bea
...
...
@@ -5,18 +5,9 @@ import clingo
def
planify_asp
(
infos
):
"""
this function planifies the grid using the asp solver clingo
the grid is a file is in the infos argument
the basis og the asp file is in "helltaker.lp"
:param infos:
:return:
"""
basis
=
""
pb
=
(
"""
\
pb
=
"""
\
step(0..maxstep-1).
init(has_key(0)).
...
...
@@ -810,7 +801,6 @@ fluent(F, T + 1) :-
#show do/2.
"""
)
# parse the grid in the level_specificities string
...
...
@@ -847,24 +837,19 @@ fluent(F, T + 1) :-
asp
=
level_specificities
+
pb
print
(
level_specificities
)
ctl
=
clingo
.
Control
([
f
"-c maxstep=
{
infos
[
'max_steps'
]
}
"
])
ctl
=
clingo
.
Control
([
f
"-c maxstep=
{
infos
[
'max_steps'
]
}
"
],
logger
=
log
)
ctl
.
add
(
"base"
,
[],
asp
)
ctl
.
ground
([(
"base"
,
[])])
plan
=
[
0
]
*
infos
[
"max_steps"
]
with
ctl
.
solve
(
yield_
=
True
)
as
handle
:
with
ctl
.
solve
(
yield_
=
True
)
as
handle
:
for
model
in
handle
:
for
atom
in
model
.
symbols
(
atoms
=
True
):
if
atom
.
name
==
"do"
:
print
(
atom
)
for
atom
in
model
.
symbols
(
atoms
=
True
):
if
atom
.
name
==
"do"
:
plan
[
atom
.
arguments
[
1
].
number
]
=
atom
.
arguments
[
0
].
name
print
(
plan
)
plan_str
=
""
for
i
in
range
(
len
(
plan
)):
if
"up"
in
plan
[
i
]:
...
...
@@ -876,10 +861,20 @@ fluent(F, T + 1) :-
if
"right"
in
plan
[
i
]:
plan_str
+=
"d"
return
plan_str
def
log
(
code
,
message
):
"""Cette fonction permet de récupérer les logs et de ne rien en faire afin de ne pas
afficher des warnings inutiles dans la console lors du solving."""
pass
def
msg
():
"""Cette fonction récupère les messages des logs et n'en fait rien."""
return
def
main
():
# récupération du nom du fichier depuis la ligne de commande
filename
=
sys
.
argv
[
1
]
...
...
levels/level1.txt
View file @
2eef5bea
Level 1
23
###
### H#
# M #
# M M#
# ####
# B B #
######
###
##
### H#
#
#
# M #
#
#
# M M#
##
# ####
##
# B B #
#
# B B D#
#########
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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