From 8bc241f97c3c87d372fe936574a31be19a57f17c Mon Sep 17 00:00:00 2001 From: Scott Wong <scottmw@student.unimelb.edu.au> Date: Sun, 21 Mar 2021 14:58:00 +1100 Subject: [PATCH] Can add non-dupe pieces to dict --- search/main.py | 34 +++++++++++++++++++++++++--------- search/method.py | 2 +- search/movement_logic.py | 4 ++-- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/search/main.py b/search/main.py index f2c7e88..2aeb11e 100644 --- a/search/main.py +++ b/search/main.py @@ -22,6 +22,22 @@ def main(): except IndexError: print("usage: python3 -m search path/to/input.json", file=sys.stderr) sys.exit(1) + # We can put the code to read the file NOT in the try/except statement because + # if the file couldn't be read the process would end anyway + # data is a dictionary with keys "upper", "lower" and "block" + # pieces in dictionary, blocks in set, we can use if position in setblocks + dictpieces = {} + setblocks = set() + initialpiecesupper = data["upper"] + initialpieceslower = data["lower"] + initialblocks = data["block"] + # Will edit to handle duplicate pieces soon + for piece in initialpiecesupper: + dictpieces[piece[0].upper] = (piece[1],piece[2]) + for piece in initialpieceslower: + dictpieces[piece[0]] = (piece[1],piece[2]) + for block in initialblocks: + setblocks.add((block[1],block[2])) # TODO: # Find and print a solution to the board configuration described @@ -38,20 +54,20 @@ def main(): def piece_collision(piecea, pieceb) -> int: piecea = piecea.lower() pieceb = pieceb.lower() - if (piecea == "r"): - if (pieceb == "s"): + if piecea == "r": + if pieceb == "s": return 1 - elif (pieceb == "p"): + elif pieceb == "p": return 2 - elif (piecea == "s"): - if (pieceb == "p"): + elif piecea == "s": + if pieceb == "p": return 1 - elif (pieceb == "r"): + elif pieceb == "r": return 2 - elif (piecea == "p"): - if (pieceb == "r"): + elif piecea == "p": + if pieceb == "r": return 1 - elif (pieceb == "s"): + elif pieceb == "s": return 2 return 0 # We may have to edit this to strip numbers later diff --git a/search/method.py b/search/method.py index ed4d633..8f72f9a 100644 --- a/search/method.py +++ b/search/method.py @@ -7,7 +7,7 @@ TYPE = 0 ROW = 1 COLUMN = 2 - +# This isn't reaaly needed, check main file def read_position_list(file): """ :argument file - of the JSON file diff --git a/search/movement_logic.py b/search/movement_logic.py index 267eb46..8660036 100644 --- a/search/movement_logic.py +++ b/search/movement_logic.py @@ -100,7 +100,7 @@ DOWN_RIGHT = 6 Swing action logic: x is the another token that current token swing from - -> token can only swing to adjcent tiles{1,2,3} to [x] that are not adjcent to itself + -> token can only swing to adjacent tiles{1,2,3} to [x] that are not adjacent to itself tile 1, 2 and 3 are those token can swing to. @@ -200,7 +200,7 @@ def get_relative_position(token, x): :argument token - the selected game object that is presented by its position on board { (row, column)} x - the adjacent game object :return the position of x relative to token - -> using the slide direction as the position defition. + -> using the slide direction as the position definition. e.g left,right, up_left, up_right,..etc """ # check if x is to the left of tile -- GitLab