Skip to content
Snippets Groups Projects
Commit 2fe7492b authored by Xuan Trinh's avatar Xuan Trinh
Browse files

fixing the comment

parent 6fc704b6
No related branches found
No related tags found
No related merge requests found
...@@ -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 action. # sort the list of remained piece base on the number of option 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 action # Found a move that does not cause collision
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():
""" """
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment