Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
comp30024-project-1
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Scott Wong
comp30024-project-1
Commits
2fe7492b
Commit
2fe7492b
authored
4 years ago
by
Xuan Trinh
Browse files
Options
Downloads
Patches
Plain Diff
fixing the comment
parent
6fc704b6
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
search/search_algorithm.py
+13
-10
13 additions, 10 deletions
search/search_algorithm.py
with
13 additions
and
10 deletions
search/search_algorithm.py
+
13
−
10
View file @
2fe7492b
...
@@ -287,48 +287,51 @@ def perform_optimal_combination(move_list: dict):
...
@@ -287,48 +287,51 @@ def perform_optimal_combination(move_list: dict):
-> then choose action from the remained piece in a way that not cause collision
-> then choose action from the remained piece in a way that not cause collision
:param move_list: contain all the pottential moved for all piece
:param move_list: contain all the pottential moved for all piece
"""
"""
# perform all the action that directly lead the piece to its target.
priority_list
=
[]
priority_list
=
[]
# For each piece who has a target, move all the piece that after take this action will lead directly to its target.
# Keep the rest in the another list {so that we can sort them and , move each of them}
for
piece
in
move_list
:
for
piece
in
move_list
:
if
piece
in
targetsDict
.
keys
()
and
compare_tile
(
move_list
[
piece
][
HIGHEST_RANK
],
targetsDict
[
piece
]):
if
piece
in
targetsDict
.
keys
()
and
compare_tile
(
move_list
[
piece
][
HIGHEST_RANK
],
targetsDict
[
piece
]):
# perform swap and update board
#
found a piece !!!
perform swap and update board
del
board
[
upperPiecesDict
[
piece
]]
del
board
[
upperPiecesDict
[
piece
]]
upperPiecesDict
[
piece
]
=
targetsDict
[
piece
]
upperPiecesDict
[
piece
]
=
targetsDict
[
piece
]
board
[
targetsDict
[
piece
]]
=
piece
board
[
targetsDict
[
piece
]]
=
piece
else
:
else
:
# this piece is not matching.
priority_list
.
append
(
piece
)
priority_list
.
append
(
piece
)
# sort the list base on number of
ac
tion
.
# sort the list
of remained piece
base on
the
number of
op
tion
they have {a.k.a move(s)}
priority_list
.
sort
(
key
=
(
lambda
key
:
len
(
move_list
[
key
])))
priority_list
.
sort
(
key
=
(
lambda
key
:
len
(
move_list
[
key
])))
#
perform an action that does not result in a collision
.
#
from those remained piece, move the least option first
.
for
piece
in
priority_list
:
for
piece
in
priority_list
:
index
=
HIGHEST_RANK
index
=
HIGHEST_RANK
moved
=
False
moved
=
False
# each piece have to move once and only once
while
not
moved
:
while
not
moved
:
if
index
>=
len
(
move_list
[
piece
]):
if
index
>=
len
(
move_list
[
piece
]):
break
break
# if current action lead to that piece collide with another piece, abandon it and go examine next action
if
move_list
[
piece
][
index
]
in
board
.
keys
()
and
\
if
move_list
[
piece
][
index
]
in
board
.
keys
()
and
\
result_of_collision
(
board
[
move_list
[
piece
][
index
]],
piece
)
!=
DRAW
:
result_of_collision
(
board
[
move_list
[
piece
][
index
]],
piece
)
!=
DRAW
:
index
+=
1
index
+=
1
continue
continue
#
perform the act
ion
#
Found a move that does not cause collis
ion
if
upperPiecesDict
[
piece
]
in
board
.
keys
():
if
upperPiecesDict
[
piece
]
in
board
.
keys
():
del
board
[
upperPiecesDict
[
piece
]]
del
board
[
upperPiecesDict
[
piece
]]
upperPiecesDict
[
piece
]
=
move_list
[
piece
][
index
]
upperPiecesDict
[
piece
]
=
move_list
[
piece
][
index
]
board
[
move_list
[
piece
][
index
]]
=
piece
board
[
move_list
[
piece
][
index
]]
=
piece
moved
=
True
# log that this piece had visit this tile <- help with ranking its option.
check_in
(
move_list
[
piece
][
index
],
piece
)
check_in
(
move_list
[
piece
][
index
],
piece
)
moved
=
True
def
take_turn
():
def
take_turn
():
"""
"""
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment