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
d369f8c4
Commit
d369f8c4
authored
Mar 22, 2021
by
Scott Wong
Browse files
Options
Downloads
Patches
Plain Diff
Finalised import, global dict and list
parent
2536b015
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
search/main.py
+38
-14
38 additions, 14 deletions
search/main.py
with
38 additions
and
14 deletions
search/main.py
+
38
−
14
View file @
d369f8c4
...
@@ -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
...
...
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