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
861daf36
Commit
861daf36
authored
Jun 14, 2022
by
Adrien Simon
Browse files
asp
parent
e38a8461
Changes
5
Hide whitespace changes
Inline
Side-by-side
asp/__pycache__/helltaker_utils.cpython-39.pyc
0 → 100644
View file @
861daf36
File added
asp/helltaker.lp
View file @
861daf36
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% HELLTAKER IN ASP %%%
%%% version: 0.1 %%%
%%% authors : Adrien Simon %%%
%%% Julie Pichon %%%
%%% Léo Peron %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% clingo -c maxstep=n -n0 helltaker.lp
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%% INITIALISATION %%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
step(0..maxstep-1).
cell(0, 1..7).
cell(1, 0..8).
cell(2, 0..8).
cell(3, 3..5). cell(3, 1). cell(3, 7).
cell(4, 3..5).
cell(5, 3..5).
%%%%%% INIT %%%%%%
% player
init(at(0, 1)).
% boxes
init(box(0, 3)). init(box(0, 6)).
init(box(1, 1..3)). init(box(1, 6..7)).
init(box(2, 1)). init(box(2, 3..5)).
init(box(3, 1)). init(box(3, 3)).
init(box(4, 3)). init(box(4, 5)).
% monsters
% spikes
% trap
state_trap(on; off).
% demoness
demoness(6, 3).
% chest & key
init(chest(4, 4)).
init(key(2, 8)).
init(has_key(0)).
fluent(F, 0) :- init(F).
%%%%%% ACTIONS %%%%%%
...
...
@@ -71,8 +23,6 @@ action(
%%%%%%% BUTS %%%%%%%
%%%%%%%%%%%%%%%%%%%%
goal(at(5, 4)).
achieved(T) :- fluent(F, T), goal(F).
:- not achieved(_).
...
...
asp/helltaker_plan.py
0 → 100644
View file @
861daf36
import
sys
from
helltaker_utils
import
grid_from_file
,
check_plan
import
time
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
=
""
with
open
(
"helltaker.lp"
,
"r"
,
encoding
=
"utf-8"
)
as
f
:
basis
=
f
.
read
()
# parse the grid in the level_specificities string
level_specificities
+=
f
"step(0..
{
infos
[
'max_steps'
]
}
).
\n
"
for
i
in
range
(
infos
[
"m"
]):
for
j
in
range
(
infos
[
"n"
]):
if
not
infos
[
"grid"
][
i
][
j
]
==
"#"
:
level_specificities
+=
f
"cell(
{
i
}
,
{
j
}
).
\n
"
if
infos
[
"grid"
][
i
][
j
]
==
"H"
:
level_specificities
+=
f
"init(at(
{
i
}
,
{
j
}
)).
\n
"
if
infos
[
"grid"
][
i
][
j
]
in
(
"B"
,
"O"
,
"P"
,
"Q"
):
level_specificities
+=
f
"init(block(
{
i
}
,
{
j
}
)).
\n
"
if
infos
[
"grid"
][
i
][
j
]
==
"D"
:
level_specificities
+=
f
"demoness(
{
i
}
,
{
j
}
).
\n
"
level_specificities
+=
f
"goal(at(
{
i
-
1
}
,
{
j
}
)).
\n
"
level_specificities
+=
f
"goal(at(
{
i
}
,
{
j
-
1
}
)).
\n
"
level_specificities
+=
f
"goal(at(
{
i
+
1
}
,
{
j
}
)).
\n
"
level_specificities
+=
f
"goal(at(
{
i
}
,
{
j
+
1
}
)).
\n
"
if
infos
[
"grid"
][
i
][
j
]
==
"K"
:
level_specificities
+=
f
"init(key(
{
i
}
,
{
j
}
)).
\n
"
if
infos
[
"grid"
][
i
][
j
]
==
"L"
:
level_specificities
+=
f
"init(chest(
{
i
}
,
{
j
}
)).
\n
"
if
infos
[
"grid"
][
i
][
j
]
in
(
"S"
,
"O"
):
level_specificities
+=
f
"spikes(
{
i
}
,
{
j
}
).
\n
"
if
infos
[
"grid"
][
i
][
j
]
in
(
"T"
,
"P"
):
level_specificities
+=
f
"{{trap(
{
i
}
,
{
j
}
, S, T) : state_trap(S)}} = 1 :- step(T). :- trap(
{
i
}
,
{
j
}
, S, 0), S != on.
\n
"
if
infos
[
"grid"
][
i
][
j
]
in
(
"U"
,
"Q"
):
level_specificities
+=
f
"{{trap(
{
i
}
,
{
j
}
, S, T) : state_trap(S)}} = 1 :- step(T). :- trap(
{
i
}
,
{
j
}
, S, 0), S != off.
\n
"
asp
=
level_specificities
+
basis
print
(
asp
)
ctl
=
clingo
.
Control
()
ctl
.
add
(
"base"
,
[],
asp
)
# ctl.ground([("base", [])])
print
(
"ouais3"
)
ctl
.
solve
()
print
(
"ouais4"
)
plan
=
[]
for
model
in
ctl
.
solve
():
for
atom
in
model
.
symbols
(
shown
=
True
):
if
atom
.
name
==
"do"
:
plan
.
append
(
atom
.
arguments
[
0
].
number
)
print
(
plan
)
return
"hbgd"
def
main
():
# récupération du nom du fichier depuis la ligne de commande
filename
=
sys
.
argv
[
1
]
# récupération de al grille et de toutes les infos
infos
=
grid_from_file
(
filename
)
# calcul du plan
plan
=
planify_asp
(
infos
)
# affichage du résultat
if
check_plan
(
plan
):
print
(
"[OK]"
,
plan
)
else
:
print
(
"[Err]"
,
plan
,
file
=
sys
.
stderr
)
sys
.
exit
(
2
)
main
()
python
/helltaker_utils.py
→
asp
/helltaker_utils.py
View file @
861daf36
File moved
python/helltaker_plan.py
deleted
100644 → 0
View file @
e38a8461
import
sys
from
helltaker_utils
import
grid_from_file
,
check_plan
def
monsuperplanificateur
(
infos
):
return
"hbgd"
def
main
():
# récupération du nom du fichier depuis la ligne de commande
filename
=
sys
.
argv
[
1
]
# récupération de al grille et de toutes les infos
infos
=
grid_from_file
(
filename
)
# calcul du plan
plan
=
monsuperplanificateur
(
infos
)
# affichage du résultat
if
check_plan
(
plan
):
print
(
"[OK]"
,
plan
)
else
:
print
(
"[Err]"
,
plan
,
file
=
sys
.
stderr
)
sys
.
exit
(
2
)
if
__name__
==
"__main__"
:
main
()
\ No newline at end of file
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