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

Can add non-dupe pieces to dict

parent 60858f5f
No related branches found
No related tags found
No related merge requests found
...@@ -22,6 +22,22 @@ def main(): ...@@ -22,6 +22,22 @@ def main():
except IndexError: except IndexError:
print("usage: python3 -m search path/to/input.json", file=sys.stderr) print("usage: python3 -m search path/to/input.json", file=sys.stderr)
sys.exit(1) 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: # TODO:
# Find and print a solution to the board configuration described # Find and print a solution to the board configuration described
...@@ -38,20 +54,20 @@ def main(): ...@@ -38,20 +54,20 @@ def main():
def piece_collision(piecea, pieceb) -> int: def piece_collision(piecea, pieceb) -> int:
piecea = piecea.lower() piecea = piecea.lower()
pieceb = pieceb.lower() pieceb = pieceb.lower()
if (piecea == "r"): if piecea == "r":
if (pieceb == "s"): if pieceb == "s":
return 1 return 1
elif (pieceb == "p"): elif pieceb == "p":
return 2 return 2
elif (piecea == "s"): elif piecea == "s":
if (pieceb == "p"): if pieceb == "p":
return 1 return 1
elif (pieceb == "r"): elif pieceb == "r":
return 2 return 2
elif (piecea == "p"): elif piecea == "p":
if (pieceb == "r"): if pieceb == "r":
return 1 return 1
elif (pieceb == "s"): elif pieceb == "s":
return 2 return 2
return 0 return 0
# We may have to edit this to strip numbers later # We may have to edit this to strip numbers later
......
...@@ -7,7 +7,7 @@ TYPE = 0 ...@@ -7,7 +7,7 @@ TYPE = 0
ROW = 1 ROW = 1
COLUMN = 2 COLUMN = 2
# This isn't reaaly needed, check main file
def read_position_list(file): def read_position_list(file):
""" """
:argument file - of the JSON file :argument file - of the JSON file
......
...@@ -100,7 +100,7 @@ DOWN_RIGHT = 6 ...@@ -100,7 +100,7 @@ DOWN_RIGHT = 6
Swing action logic: Swing action logic:
x is the another token that current token swing from 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. tile 1, 2 and 3 are those token can swing to.
...@@ -200,7 +200,7 @@ def get_relative_position(token, x): ...@@ -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)} :argument token - the selected game object that is presented by its position on board { (row, column)}
x - the adjacent game object x - the adjacent game object
:return the position of x relative to token :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 e.g left,right, up_left, up_right,..etc
""" """
# check if x is to the left of tile # check if x is to the left of tile
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment