From 19d1d3f22c896ab51b96a1a063791099ef2f8a3d Mon Sep 17 00:00:00 2001
From: Xuan Trinh <xuan.trinh@student.unimelb.edu.au>
Date: Sun, 21 Mar 2021 16:04:32 +1100
Subject: [PATCH] Found a conflict in opinion, add my opinion into the comment
 section.

---
 search/main.py   | 11 +++++++++
 search/method.py | 61 ++++++++++++++++++++++++++----------------------
 2 files changed, 44 insertions(+), 28 deletions(-)

diff --git a/search/main.py b/search/main.py
index 2aeb11e..e0ab98e 100644
--- a/search/main.py
+++ b/search/main.py
@@ -26,6 +26,17 @@ def main():
     # 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
+
+    # 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 = {}
     setblocks = set()
     initialpiecesupper = data["upper"]
diff --git a/search/method.py b/search/method.py
index 8f72f9a..14050d0 100644
--- a/search/method.py
+++ b/search/method.py
@@ -35,51 +35,56 @@ def read_position_list(file):
     r = 0
     p = 0
     s = 0
-    b = 1
 
     if not isinstance(file, str):
         print("Pass invalid argument to to_board()~!!!")
-        exit(-1)
+        exit(1)
     try:
         # open the file handle by json module
         initial = open(file)
         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 = {}
-        # iterate through the entity who is not empty in order to add it type and coordinate to dictionary.
-        for entity in game.keys():
-
-            if game[entity]:
-                for token in game[entity]:
+    dict = {}
+    dict[''] = set()
+    # 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():
 
-                    if entity == 'upper':
-                        if token[TYPE] == ROCK:
-                            dict[token[TYPE].upper() + str(R + 1)] = (int(token[ROW]), int(token[COLUMN]))
+        if game[entity]:
+            for token in game[entity]:
 
-                        if token[TYPE] == PAPER:
-                            dict[token[TYPE].upper() + str(P + 1)] = (int(token[ROW]), int(token[COLUMN]))
+                if entity == 'upper':
+                    if token[TYPE] == ROCK:
+                        dict[token[TYPE].upper() + str(R + 1)] = (int(token[ROW]), int(token[COLUMN]))
 
-                        else:
-                            dict[token[TYPE].upper() + str(S + 1)] = (int(token[ROW]), int(token[COLUMN]))
+                    if token[TYPE] == PAPER:
+                        dict[token[TYPE].upper() + str(P + 1)] = (int(token[ROW]), int(token[COLUMN]))
 
-                    elif entity == 'lower':
-                        if token[TYPE] == ROCK:
-                            dict[token[TYPE] + str(r + 1)] = (int(token[ROW]), int(token[COLUMN]))
+                    else:
+                        dict[token[TYPE].upper() + str(S + 1)] = (int(token[ROW]), int(token[COLUMN]))
 
-                        if token[TYPE] == PAPER:
-                            dict[token[TYPE] + str(p + 1)] = (int(token[ROW]), int(token[COLUMN]))
+                elif entity == 'lower':
+                    if token[TYPE] == ROCK:
+                        dict[token[TYPE] + str(r + 1)] = (int(token[ROW]), int(token[COLUMN]))
 
-                        else:
-                            dict[token[TYPE] + str(s + 1)] = (int(token[ROW]), int(token[COLUMN]))
+                    if token[TYPE] == PAPER:
+                        dict[token[TYPE] + str(p + 1)] = (int(token[ROW]), int(token[COLUMN]))
 
                     else:
-                        dict[token[TYPE] + str(b)] = (int(token[ROW]), int(token[COLUMN]))
+                        dict[token[TYPE] + str(s + 1)] = (int(token[ROW]), int(token[COLUMN]))
 
-        initial.close()
-        return dict
-    except IOError:
-        print("There is an issue when try to open file")
-        exit(-1)
+                else:
+                    dict[''].add((int(token[ROW]), int(token[COLUMN])))
+
+
+    return dict
 
 
 def distance_between(Upper_token, Lower_token):
-- 
GitLab