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
073ab0e3
Commit
073ab0e3
authored
Mar 25, 2021
by
Scott Wong
Browse files
Options
Downloads
Patches
Plain Diff
Added target selection function
parent
1d89c277
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
+52
-23
52 additions, 23 deletions
search/main.py
with
52 additions
and
23 deletions
search/main.py
+
52
−
23
View file @
073ab0e3
...
...
@@ -12,6 +12,7 @@ import json
# If you want to separate your code into separate files, put them
# inside the `search` directory (like this one and `util.py`) and
# then import from them like this:
from
search.movement_logic
import
*
from
search.util
import
print_board
,
print_slide
,
print_swing
# Why don't we just make the pieces and blocks global then?
...
...
@@ -19,6 +20,8 @@ from search.util import print_board, print_slide, print_swing
dictpieces
=
{}
setblocks
=
set
()
dicttargets
=
{}
def
main
():
try
:
with
open
(
sys
.
argv
[
1
])
as
file
:
...
...
@@ -38,8 +41,12 @@ def main():
# This is greedy, but it's a lot faster than trying to path optimally.
# And for search algorithm choice let's try starting with depth-first search, depth limit 1, 2 or 3
# Not sure which is best at the moment, looking ahead is good but looking too far ahead costs too much time
# We'll use a dictionary to track current targets
# ALGORITHM GOES HERE
# Add starting targets
# Algorithm start
...
...
@@ -94,38 +101,60 @@ def parse_input(data):
# 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
# Only look at first character of string
# so we don't have to worry about stripping numbers off
def
piece_collision
(
piecea
,
pieceb
)
->
int
:
piecea
=
piecea
.
lower
()
pieceb
=
pieceb
.
lower
()
if
piecea
[
0
]
==
"
r
"
:
if
pieceb
[
0
]
==
"
s
"
:
piecea
=
piecea
[
0
]
.
lower
()
pieceb
=
pieceb
[
0
]
.
lower
()
if
piecea
==
"
r
"
:
if
pieceb
==
"
s
"
:
return
1
elif
pieceb
[
0
]
==
"
p
"
:
elif
pieceb
==
"
p
"
:
return
2
elif
piecea
[
0
]
==
"
s
"
:
if
pieceb
[
0
]
==
"
p
"
:
elif
piecea
==
"
s
"
:
if
pieceb
==
"
p
"
:
return
1
elif
pieceb
[
0
]
==
"
r
"
:
elif
pieceb
==
"
r
"
:
return
2
elif
piecea
[
0
]
==
"
p
"
:
if
pieceb
[
0
]
==
"
r
"
:
elif
piecea
==
"
p
"
:
if
pieceb
==
"
r
"
:
return
1
elif
pieceb
[
0
]
==
"
s
"
:
elif
pieceb
==
"
s
"
:
return
2
return
0
# We may have to edit this to strip numbers later
# Input is the key of the piece to find a target for
# This function changes the value of the key given in the
# target dictionary to the closest enemy piece it can beat
def
find_target
(
piece_key
):
currentpos
=
dictpieces
[
piece_key
]
# Set the target
target
=
""
if
piece_key
[
0
]
==
"
R
"
:
target
=
"
s
"
elif
piece_key
[
0
]
==
"
S
"
:
target
=
"
p
"
elif
piece_key
[
0
]
==
"
P
"
:
target
=
"
r
"
# If we haven't set a target by now, we're dealing with the wrong kind of piece
else
:
return
#Now we check which target is closest
#Start with dummy information
targetpiece
=
""
targetdist
=
99
for
key
in
dictpieces
:
if
key
[
0
]
==
target
:
distance
=
distance_between
(
dictpieces
[
piece_key
],
dictpieces
[
key
])
if
distance
<
targetdist
:
targetpiece
=
key
targetdist
=
distance
# Now add target to dictionary
if
targetdist
==
99
:
dicttargets
[
piece_key
]
=
()
else
:
dicttargets
[
piece_key
]
=
dictpieces
[
key
]
return
# We will have dictionary containing pieces
# This is so we don't have to search the entire board every time
# we need to find pieces
# Blocks can be stored in a separate list
# Other option is to have dictionary of entire board
#Sample dictionary
sample_dict
=
{
"
R
"
:
(
0
,
-
2
),
"
s
"
:
(
-
1
,
1
)
}
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