Skip to content
Snippets Groups Projects
Commit 7e701cc3 authored by Scott Wong's avatar Scott Wong
Browse files

Debug for printing

parent 60f10344
No related branches found
No related tags found
No related merge requests found
{
"upper": [
[
"r",
2,
-4
],
[
"p",
2,
-3
],
[
"p",
3,
-4
]
],
"lower": [
[
"s",
4,
0
]
],
"block": []
}
\ No newline at end of file
File added
File added
File added
File added
File added
...@@ -22,17 +22,15 @@ def main(): ...@@ -22,17 +22,15 @@ def main():
sys.exit(1) sys.exit(1)
parse_input(data) parse_input(data)
# Add starting targets # Add starting targets
for piece in upperPiecesDict: for piece in upperPiecesDict:
find_target(piece) find_target(piece)
# keep moving until all the piece met its target # keep moving until all the piece met its target
make_board()
print_board(board)
while targetsDict: while targetsDict:
input() input()
take_turn() take_turn()
make_board()
print_board(board)
file.close() file.close()
......
...@@ -5,9 +5,12 @@ from typing import Dict, Set, List ...@@ -5,9 +5,12 @@ from typing import Dict, Set, List
from search.movement_logic import * from search.movement_logic import *
from search.search_algo import piece_collision from search.search_algo import piece_collision
import main
# Constant definition: # Constant definition:
from search.util import print_board from search.util import *
# Global variable turn is needed to print output
turn = 0
BLOCK = "[X]" BLOCK = "[X]"
UPPER_ROCK = 'R' UPPER_ROCK = 'R'
...@@ -285,17 +288,19 @@ def perform_optimal_combination(move_list: dict): ...@@ -285,17 +288,19 @@ def perform_optimal_combination(move_list: dict):
-> prioritise action that after complete bring piece to its target. -> prioritise action that after complete bring piece to its target.
-> then choose an action from those piece with the least choice. -> 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 -> 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 = [] priority_list = []
# For each piece who has a target, move all the piece that after take this action will lead directly to its target. # 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} # 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]):
print_move(upperPiecesDict[piece], targetsDict[piece])
# found a 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
...@@ -323,10 +328,14 @@ def perform_optimal_combination(move_list: dict): ...@@ -323,10 +328,14 @@ def perform_optimal_combination(move_list: dict):
continue continue
# Found a move that does not cause collision # 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(): 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
# log that this piece had visit this tile <- help with ranking its option. # log that this piece had visit this tile <- help with ranking its option.
...@@ -339,14 +348,15 @@ def take_turn(): ...@@ -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} 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 = {} possible_actions = {}
for piece in upperPiecesDict: for piece in upperPiecesDict:
possible_actions[piece] = make_ranked_move_list(piece) possible_actions[piece] = make_ranked_move_list(piece)
global turn
turn += 1
perform_optimal_combination(possible_actions) perform_optimal_combination(possible_actions)
make_board()
print_board(board)
update_target_dictionary() update_target_dictionary()
...@@ -387,3 +397,23 @@ def update_target_dictionary(): ...@@ -387,3 +397,23 @@ def update_target_dictionary():
continue continue
find_target(piece) 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment