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

Finalised import, global dict and list

parent 2536b015
Branches
No related tags found
No related merge requests found
...@@ -14,6 +14,10 @@ import json ...@@ -14,6 +14,10 @@ import json
# then import from them like this: # then import from them like this:
from search.util import print_board, print_slide, print_swing from search.util import print_board, print_slide, print_swing
# Why don't we just make the pieces and blocks global then?
# No need to ever pass them around
dictpieces = {}
setblocks = set()
def main(): def main():
try: try:
...@@ -37,16 +41,34 @@ def main(): ...@@ -37,16 +41,34 @@ def main():
# in case we need it # in case we need it
# #
# e.g: object_dict = read_position_list(sys.argv[1]) ? # e.g: object_dict = read_position_list(sys.argv[1]) ?
dictpieces = {}
setblocks = set()
initialpiecesupper = data["upper"] initialpiecesupper = data["upper"]
initialpieceslower = data["lower"] initialpieceslower = data["lower"]
initialblocks = data["block"] initialblocks = data["block"]
# Will edit to handle duplicate pieces soon nump, numr, nums = 0,0,0
keywrite = ""
for piece in initialpiecesupper: for piece in initialpiecesupper:
dictpieces[piece[0].upper] = (piece[1],piece[2]) if piece[0] == "p":
nump = nump + 1
keywrite = "P" + str(nump)
elif piece[0] == "r":
numr = numr + 1
keywrite = "R" + str(numr)
else:
nums = nums + 1
keywrite = "S" + str(nums)
dictpieces[keywrite] = (piece[1],piece[2])
nump, numr, nums = 0,0,0
for piece in initialpieceslower: for piece in initialpieceslower:
dictpieces[piece[0]] = (piece[1],piece[2]) if piece[0] == "p":
nump = nump + 1
keywrite = "p" + str(nump)
elif piece[0] == "r":
numr = numr + 1
keywrite = "r" + str(numr)
else:
nums = nums + 1
keywrite = "s" + str(nums)
dictpieces[keywrite] = (piece[1],piece[2])
for block in initialblocks: for block in initialblocks:
setblocks.add((block[1],block[2])) setblocks.add((block[1],block[2]))
...@@ -62,23 +84,25 @@ def main(): ...@@ -62,23 +84,25 @@ def main():
# We will convert both to lower case letters and check each case # We will convert both to lower case letters and check each case
# Would be nice to use comparator but can't have r>s>p>r using it # Would be nice to use comparator but can't have r>s>p>r using it
# Return 1 if piecea wins, 2 if pieceb wins and 0 if neither win # Return 1 if piecea wins, 2 if pieceb wins and 0 if neither win
# Only look at first character of string
# so we don't have to worry about stripping numbers off
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[0] == "r":
if pieceb == "s": if pieceb[0] == "s":
return 1 return 1
elif pieceb == "p": elif pieceb[0] == "p":
return 2 return 2
elif piecea == "s": elif piecea[0] == "s":
if pieceb == "p": if pieceb[0] == "p":
return 1 return 1
elif pieceb == "r": elif pieceb[0] == "r":
return 2 return 2
elif piecea == "p": elif piecea[0] == "p":
if pieceb == "r": if pieceb[0] == "r":
return 1 return 1
elif pieceb == "s": elif pieceb[0] == "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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment