diff --git a/search/main.py b/search/main.py index f2c7e88873d1829140448723b50b7275a6925eba..2aeb11e961eb6b2129161b0641fdc00d15a54960 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 ed4d633eb340aaf7683e489c960e3b1fba02bb86..8f72f9a039a22039661b26b900fc5044721dbc1f 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 4a5ccc931dc73c2933d5afa4bedfd66a94df54e6..fbfd26fe48c6781ab080f0f6f6c66aa5e310939c 100644 --- a/search/movement_logic.py +++ b/search/movement_logic.py @@ -117,7 +117,7 @@ OUT_OF_BOARD = 0 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. @@ -238,7 +238,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