diff --git a/search/1.json b/search/1.json new file mode 100644 index 0000000000000000000000000000000000000000..7863e69b2783bec2cb71870b1640f97ade19cb00 --- /dev/null +++ b/search/1.json @@ -0,0 +1,27 @@ +{ + "upper": [ + [ + "r", + 2, + -4 + ], + [ + "p", + 2, + -3 + ], + [ + "p", + 3, + -4 + ] + ], + "lower": [ + [ + "s", + 4, + 0 + ] + ], + "block": [] +} \ No newline at end of file diff --git a/search/__pycache__/main.cpython-36.pyc b/search/__pycache__/main.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..ed2128540324288049c330e694cf547b243e103b Binary files /dev/null and b/search/__pycache__/main.cpython-36.pyc differ diff --git a/search/__pycache__/movement_logic.cpython-36.pyc b/search/__pycache__/movement_logic.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..305fec5019e20f268ffabc036afb2771d6ba711c Binary files /dev/null and b/search/__pycache__/movement_logic.cpython-36.pyc differ diff --git a/search/__pycache__/search_algo.cpython-36.pyc b/search/__pycache__/search_algo.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..74e6717fea605784a31ba0a6ad30a0e18e472015 Binary files /dev/null and b/search/__pycache__/search_algo.cpython-36.pyc differ diff --git a/search/__pycache__/search_algorithm.cpython-36.pyc b/search/__pycache__/search_algorithm.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..8b0b45f5d0ec70481f3df1dc34911ee8c1453abb Binary files /dev/null and b/search/__pycache__/search_algorithm.cpython-36.pyc differ diff --git a/search/__pycache__/util.cpython-36.pyc b/search/__pycache__/util.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..1ad4c8f7c814b8daa3f6b233e1e3e9f1f4811f7e Binary files /dev/null and b/search/__pycache__/util.cpython-36.pyc differ diff --git a/search/main.py b/search/main.py index d4a4f710b4a8f4e3fe22130d6e60578bce8df120..9c8bd5b1378c73eba8c2cf28a3c67103cd9984a5 100644 --- a/search/main.py +++ b/search/main.py @@ -22,17 +22,15 @@ def main(): sys.exit(1) parse_input(data) - # Add starting targets for piece in upperPiecesDict: find_target(piece) - # keep moving until all the piece met its target + make_board() + print_board(board) while targetsDict: input() take_turn() - make_board() - print_board(board) file.close() diff --git a/search/search_algorithm.py b/search/search_algorithm.py index c9c494335acef957132af036ac550be500fbe389..0bd0dda0e272c293615fe654f0c40619999b358b 100644 --- a/search/search_algorithm.py +++ b/search/search_algorithm.py @@ -5,9 +5,12 @@ from typing import Dict, Set, List from search.movement_logic import * from search.search_algo import piece_collision - +import main # Constant definition: -from search.util import print_board +from search.util import * + +# Global variable turn is needed to print output +turn = 0 BLOCK = "[X]" UPPER_ROCK = 'R' @@ -285,17 +288,19 @@ def perform_optimal_combination(move_list: dict): -> prioritise action that after complete bring piece to its target. -> then choose an action from those piece with the least choice. -> 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 potential moved for all piece """ - + global turn 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]): + print_move(upperPiecesDict[piece], targetsDict[piece]) # found a piece !!!perform swap and update board del board[upperPiecesDict[piece]] + upperPiecesDict[piece] = targetsDict[piece] board[targetsDict[piece]] = piece @@ -323,10 +328,14 @@ def perform_optimal_combination(move_list: dict): continue # Found a move that does not cause collision + + # This is print section + print(upperPiecesDict[piece], " to ", move_list[piece][index]) + print_move(upperPiecesDict[piece], move_list[piece][index]) + if upperPiecesDict[piece] in board.keys(): del board[upperPiecesDict[piece]] upperPiecesDict[piece] = move_list[piece][index] - board[move_list[piece][index]] = piece # log that this piece had visit this tile <- help with ranking its option. @@ -339,14 +348,15 @@ def take_turn(): choose a combination of move that is partially optimal {move all the piece <some time> closer to its target} """ - make_board() - print_board(board) possible_actions = {} for piece in upperPiecesDict: possible_actions[piece] = make_ranked_move_list(piece) - + global turn + turn += 1 perform_optimal_combination(possible_actions) + make_board() + print_board(board) update_target_dictionary() @@ -386,4 +396,24 @@ def update_target_dictionary(): if piece in targetsDict.keys(): continue - find_target(piece) \ No newline at end of file + find_target(piece) + +# Every tool in this document doesn't seem to be helpful. We're brute forcing this +def print_move(start: Tuple[int, int], finish: Tuple[int, int]): + # Go through every slide comparsion. If not printed already it's a swing. + # Three lines for readability + # Horizontal + global turn + if abs(start[0] - finish[0]) == 0 and abs(start[0] - finish[0]) <= 1: + print_slide(turn, start[0], start[1], finish[0], finish[1]) + # LL to UR diagonal or UR to LL diagonal + elif abs(start[0] - finish[0]) <= 1 and abs(start[1] - finish[1]) == 0: + print_slide(turn, start[0], start[1], finish[0], finish[1]) + # LR to UL diagonal + elif start[0] == (finish[0] - 1) and start[0] == (finish[0] + 1): + print_slide(turn, start[0], start[1], finish[0], finish[1]) + # UL to LR diagonal + elif start[0] == (finish[0] + 1) and start[0] == (finish[0] - 1): + print_slide(turn, start[0], start[1], finish[0], finish[1]) + else: + print_swing(turn, start[0], start[1], finish[0], finish[1]) \ No newline at end of file