From 2fe7492b12d4c92e497bdf03abefe8ed86f43daf Mon Sep 17 00:00:00 2001 From: Xuan Trinh <xuan.trinh@student.unimelb.edu.au> Date: Sun, 28 Mar 2021 14:52:40 +1100 Subject: [PATCH] fixing the comment --- search/search_algorithm.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/search/search_algorithm.py b/search/search_algorithm.py index f970d67..c9c4943 100644 --- a/search/search_algorithm.py +++ b/search/search_algorithm.py @@ -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 :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: 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]] upperPiecesDict[piece] = targetsDict[piece] - board[targetsDict[piece]] = piece + else: + # this piece is not matching. 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]))) - # perform an action that does not result in a collision. + # from those remained piece, move the least option first. for piece in priority_list: index = HIGHEST_RANK moved = False + # each piece have to move once and only once while not moved: if index >= len(move_list[piece]): 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\ result_of_collision(board[move_list[piece][index]], piece) != DRAW: index += 1 continue - # perform the action + # Found a move that does not cause collision if upperPiecesDict[piece] in board.keys(): del board[upperPiecesDict[piece]] upperPiecesDict[piece] = move_list[piece][index] 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) - - + moved = True def take_turn(): """ -- GitLab