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
bde0d618
Commit
bde0d618
authored
Jun 15, 2022
by
Adrien Simon
Browse files
Merge branch 'main' of
https://gitlab.utc.fr/simonadr/ia02-helltaker
parents
2eef5bea
eb9a1f5e
Changes
1
Hide whitespace changes
Inline
Side-by-side
python/main.py
View file @
bde0d618
...
...
@@ -183,21 +183,21 @@ def free_factory(map_rules):
def
updating_state
(
map_rules
:
Dict
[
str
,
List
[
int
]],
state
:
State
,
newHero
:
List
[
int
],
mobs
:
Lis
t
[
Tuple
[
int
,
int
]]
=
[],
blocks
:
Lis
t
[
Tuple
[
int
,
int
]]
=
[],
newHero
:
Tuple
[
int
],
mobs
:
FrozenSe
t
[
Tuple
[
int
,
int
]]
=
[],
blocks
:
FrozenSe
t
[
Tuple
[
int
,
int
]]
=
[],
keyFinded
:
bool
=
False
,
lockOpenable
:
bool
=
False
,
mobCleared
:
bool
=
False
,
):
# KILLINGS MOBS
newMobs
=
list
(
state
.
mobs
)
newMobs
=
state
.
mobs
if
mobs
or
mobCleared
:
newMobs
=
lis
t
(
mobs
)
newMobs
=
frozense
t
(
mobs
)
for
mob
in
newMobs
:
if
(
mob
in
state
.
safeTraps
)
or
(
mob
in
map_rules
[
"S"
]):
newMobs
.
remove
(
mob
)
newMobs
=
moving_frozenset
(
newMobs
,
supr
=
mob
)
# KEY AND CHEST INTERACTIONS
newLock
=
state
.
lock
...
...
@@ -342,6 +342,8 @@ def succ_factory(map_rules: Dict[str, set]) -> Callable[[State], Dict[State, Act
# DEFINING HEURISTIC
# GLOUTON
def
manhattan_distance_factory
(
map_rules
:
Dict
[
str
,
set
])
->
Callable
:
def
dist_to_closest_demon
(
state
:
State
)
->
int
:
return
min
(
...
...
@@ -352,22 +354,26 @@ def manhattan_distance_factory(map_rules: Dict[str, set]) -> Callable:
return
dist_to_closest_demon
# A*
def
manhattan_distance_astar_factory
(
map_rules
:
Dict
[
str
,
set
])
->
Callable
:
def
dist_to_closest_demon
(
state
:
State
)
->
int
:
keyFactor
=
0
def
dist_to_closest_demon
(
state
:
State
,
action
:
Action
)
->
int
:
passedCost
=
(
1
/
(
1
+
map_rules
[
"max"
]
-
state
.
steps
))
booster
=
1
manDist
=
0
if
state
.
key
:
keyFactor
=
4
lockFactor
=
0
manDist
=
abs
(
state
.
key
[
0
]
-
state
.
hero
[
0
])
+
abs
(
state
.
key
[
1
]
-
state
.
hero
[
1
])
if
action
:
booster
=
(
0.8
,
0.6
)[
action
.
verb
==
"unlock/key"
]
if
state
.
lock
and
not
state
.
key
:
lockFactor
=
-
1
return
(
min
(
abs
(
state
.
hero
[
0
]
-
demon
[
0
])
+
abs
(
state
.
hero
[
1
]
-
demon
[
1
])
for
demon
in
map_rules
[
"D"
]
)
+
(
map_rules
[
"max"
]
-
state
.
steps
)
*
0.7
+
keyFactor
+
lockFactor
)
manDist
=
abs
(
state
.
lock
[
0
]
-
state
.
hero
[
0
])
+
abs
(
state
.
lock
[
1
]
-
state
.
hero
[
1
])
if
action
:
booster
=
(
0.4
,
0.2
)[
action
.
verb
==
"unlock/key"
]
else
:
manDist
=
min
(
abs
(
state
.
hero
[
0
]
-
demon
[
0
])
+
abs
(
state
.
hero
[
1
]
-
demon
[
1
]
)
for
demon
in
map_rules
[
"D"
]
)
return
manDist
*
1
+
passedCost
*
1.5
return
dist_to_closest_demon
...
...
@@ -381,7 +387,7 @@ def search_heuristic(
)
->
Tuple
[
State
,
Dict
[
State
,
Action
]]:
l
=
[]
heapq
.
heapify
(
l
)
heapq
.
heappush
(
l
,
(
heuristic
(
s0
),
s0
))
heapq
.
heappush
(
l
,
(
heuristic
(
s0
,
None
),
s0
))
save
=
{
s0
:
None
}
heapq
.
heapify
(
l
)
while
l
:
...
...
@@ -397,7 +403,7 @@ def search_heuristic(
save
[
s2
]
=
(
s
,
a
)
if
goals
(
s2
):
return
s2
,
save
heapq
.
heappush
(
l
,
(
heuristic
(
s2
),
s2
))
heapq
.
heappush
(
l
,
(
heuristic
(
s2
,
a
),
s2
))
return
None
,
save
...
...
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