Skip to content
Snippets Groups Projects
Commit 19d1d3f2 authored by Xuan Trinh's avatar Xuan Trinh
Browse files

Found a conflict in opinion, add my opinion into the comment section.

parent d2e95132
Branches
No related tags found
No related merge requests found
...@@ -26,6 +26,17 @@ def main(): ...@@ -26,6 +26,17 @@ def main():
# if the file couldn't be read the process would end anyway # if the file couldn't be read the process would end anyway
# data is a dictionary with keys "upper", "lower" and "block" # data is a dictionary with keys "upper", "lower" and "block"
# pieces in dictionary, blocks in set, we can use if position in setblocks # pieces in dictionary, blocks in set, we can use if position in setblocks
# XUAN: please have a look at the read_position_list() in method module. This should be on another abstraction
# level? for readability: else the main method will be too long? I like how u place Block in a set.
# Can we just add the set of block into the dictionary ?since we know for sure that any time we want to do
# anything with the object{take action}.We sure need to know where the block is.like:
# { '' : {(pos1, pos2), ..}
# ....}
# => this way later on we will only need to pass the dictionary around knowing that all the block is there
# in case we need it
#
# e.g: object_dict = read_position_list(sys.argv[1]) ?
dictpieces = {} dictpieces = {}
setblocks = set() setblocks = set()
initialpiecesupper = data["upper"] initialpiecesupper = data["upper"]
......
...@@ -35,18 +35,26 @@ def read_position_list(file): ...@@ -35,18 +35,26 @@ def read_position_list(file):
r = 0 r = 0
p = 0 p = 0
s = 0 s = 0
b = 1
if not isinstance(file, str): if not isinstance(file, str):
print("Pass invalid argument to to_board()~!!!") print("Pass invalid argument to to_board()~!!!")
exit(-1) exit(1)
try: try:
# open the file handle by json module # open the file handle by json module
initial = open(file) initial = open(file)
game = json.load(initial) game = json.load(initial)
initial.close()
except IOError:
#this is line of code from SCOTT's simmiliar way to handle this exception
print("usage: python3 -m search path/to/input.json")
exit(1)
dict = {} dict = {}
dict[''] = set()
# iterate through the entity who is not empty in order to add it type and coordinate to dictionary. # iterate through the entity who is not empty in order to add it type and coordinate to dictionary.
# taken Scott's approach of splitting the read file into 3 subsection: base on which object it is{upper, lower
# block.}
#also: Scott's approach of bringing the except to the load data only and using set instead of list
for entity in game.keys(): for entity in game.keys():
if game[entity]: if game[entity]:
...@@ -73,13 +81,10 @@ def read_position_list(file): ...@@ -73,13 +81,10 @@ def read_position_list(file):
dict[token[TYPE] + str(s + 1)] = (int(token[ROW]), int(token[COLUMN])) dict[token[TYPE] + str(s + 1)] = (int(token[ROW]), int(token[COLUMN]))
else: else:
dict[token[TYPE] + str(b)] = (int(token[ROW]), int(token[COLUMN])) dict[''].add((int(token[ROW]), int(token[COLUMN])))
initial.close()
return dict return dict
except IOError:
print("There is an issue when try to open file")
exit(-1)
def distance_between(Upper_token, Lower_token): def distance_between(Upper_token, Lower_token):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment