Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
comp30024-project-1
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Scott Wong
comp30024-project-1
Commits
19d1d3f2
Commit
19d1d3f2
authored
4 years ago
by
Xuan Trinh
Browse files
Options
Downloads
Patches
Plain Diff
Found a conflict in opinion, add my opinion into the comment section.
parent
d2e95132
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
search/main.py
+11
-0
11 additions, 0 deletions
search/main.py
search/method.py
+33
-28
33 additions, 28 deletions
search/method.py
with
44 additions
and
28 deletions
search/main.py
+
11
−
0
View file @
19d1d3f2
...
@@ -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
"
]
...
...
This diff is collapsed.
Click to expand it.
search/method.py
+
33
−
28
View file @
19d1d3f2
...
@@ -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
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment