Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
Seminar-HFO
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Shashank Suhas
Seminar-HFO
Commits
475ccb90
Commit
475ccb90
authored
Jul 16, 2017
by
drallensmith
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Was being too far away from goal, now too close... rethinking.
parent
435af1ad
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
13 deletions
+46
-13
example/hand_coded_defense_agent.py
example/hand_coded_defense_agent.py
+46
-13
No files found.
example/hand_coded_defense_agent.py
View file @
475ccb90
...
...
@@ -39,16 +39,20 @@ def get_dist_normalized(ref_x, ref_y, src_x, src_y):
## return get_dist_normalized(ball_pos_x, ball_pos_y,
## kicker_pos_x, kicker_pos_y) < params['KICK_DIST']
def
is_tackleable
(
agent_pos_x
,
agent_pos_y
,
opp_pos_x
,
opp_pos_y
):
return
get_dist_normalized
(
agent_pos_x
,
agent_pos_y
,
opp_pos_x
,
opp_pos_y
)
<
params
[
'TACKLE_DIST'
]
def
is_tackleable
(
agent_pos_x
,
agent_pos_y
,
ball_dist
,
opp_pos_x
,
opp_pos_y
):
return
(
get_dist_normalized
(
agent_pos_x
,
agent_pos_y
,
opp_pos_x
,
opp_pos_y
)
<
params
[
'TACKLE_DIST'
])
and
(
ball_dist
<
params
[
'LOW_KICK_DIST'
])
def
ball_moving_toward_goal
(
ball_pos_x
,
ball_pos_y
,
old_ball_pos_x
,
old_ball_pos_y
):
return
get_dist_normalized
(
ball_pos_x
,
ball_pos_y
,
GOAL_POS_X
,
GOAL_POS_Y
)
<
get_dist_normalized
(
old_ball_pos_x
,
old_ball_pos_y
,
GOAL_POS_X
,
GOAL_POS_Y
)
return
(
get_dist_normalized
(
ball_pos_x
,
ball_pos_y
,
GOAL_POS_X
,
GOAL_POS_Y
)
<
min
(
params
[
'KICK_DIST'
],
get_dist_normalized
(
old_ball_pos_x
,
old_ball_pos_y
,
GOAL_POS_X
,
GOAL_POS_Y
)))
def
get_sorted_opponents
(
state_vec
,
num_opponents
,
num_teammates
,
pos_x
,
pos_y
):
"""
...
...
@@ -107,7 +111,11 @@ def do_defense_action(state_vec, hfo_env, episode,
hfo_env
.
act
(
hfo
.
MOVE
)
return
if
ball_toward_goal
and
(
ball_sorted_list
[
0
][
1
]
<
params
[
'LOW_KICK_DIST'
]):
ball_toward_goal
=
False
is_tackleable_opp
=
is_tackleable
(
agent_pos_x
,
agent_pos_y
,
ball_sorted_list
[
0
][
1
],
ball_sorted_list
[
0
][
2
],
ball_sorted_list
[
0
][
3
])
if
state_vec
[
5
]
>
0
:
# kickable distance of player
...
...
@@ -125,18 +133,37 @@ def do_defense_action(state_vec, hfo_env, episode,
hfo_env
.
act
(
hfo
.
GO_TO_BALL
)
return
if
get_dist_normalized
(
ball_sorted_list
[
0
][
2
],
ball_sorted_list
[
0
][
3
],
GOAL_POS_X
,
GOAL_POS_Y
)
<
get_dist_normalized
(
agent_pos_x
,
agent_pos_y
,
GOAL_POS_X
,
GOAL_POS_Y
):
if
max
(
ball_sorted_list
[
0
][
1
],
get_dist_normalized
(
ball_sorted_list
[
0
][
2
],
ball_sorted_list
[
0
][
3
],
GOAL_POS_X
,
GOAL_POS_Y
))
<
params
[
'KICK_DIST'
]:
if
is_tackleable_opp
:
hfo_env
.
act
(
hfo
.
MOVE
)
else
:
hfo_env
.
act
(
hfo
.
DEFEND_GOAL
)
elif
is_tackleable_opp
and
get_dist_normalized
(
ball_sorted_list
[
0
][
2
],
ball_sorted_list
[
0
][
3
],
GOAL_POS_X
,
GOAL_POS_Y
)
<
params
[
'KICK_DIST'
]:
hfo_env
.
act
(
hfo
.
MOVE
)
elif
ball_toward_goal
and
(
not
is_in_open_area
(
ball_pos_x
,
ball_pos_y
)):
hfo_env
.
act
(
hfo
.
INTERCEPT
)
else
:
hfo_env
.
act
(
hfo
.
REDUCE_ANGLE_TO_GOAL
)
return
if
ball_sorted_list
[
0
][
1
]
<
params
[
'KICK_DIST'
]:
goal_sorted_list
=
get_sorted_opponents
(
state_vec
,
num_opponents
,
num_teammates
,
pos_x
=
GOAL_POS_X
,
pos_y
=
GOAL_POS_Y
)
if
goal_sorted_list
[
0
][
0
]
!=
ball_sorted_list
[
0
][
0
]:
# top in each are opponents to worry about
if
is_in_open_area
(
ball_sorted_list
[
0
][
2
],
ball_sorted_list
[
0
][
3
]):
if
is_in_open_area
(
ball_sorted_list
[
0
][
2
],
ball_sorted_list
[
0
][
3
])
and
(
goal_sorted_list
[
0
][
1
]
<
params
[
'KICK_DIST'
]):
hfo_env
.
act
(
hfo
.
MARK_PLAYER
,
goal_sorted_list
[
0
][
0
])
elif
get_dist_normalized
(
agent_pos_x
,
agent_pos_y
,
ball_pos_x
,
ball_pos_y
)
<
ball_sorted_list
[
0
][
1
]:
## # odd; why not kickable above?
## print("Ball dist below {0:n}".format(ball_sorted_list[0][1]) +
## " but not kickable (btg {0!r} ito {1!r})".format(ball_toward_goal,
## is_tackleable_opp))
if
ball_toward_goal
:
hfo_env
.
act
(
hfo
.
INTERCEPT
)
elif
is_in_open_area
(
ball_pos_x
,
ball_pos_y
)
or
(
is_tackleable_opp
and
...
...
@@ -172,6 +199,12 @@ def do_defense_action(state_vec, hfo_env, episode,
pos_x
=
GOAL_POS_X
,
pos_y
=
GOAL_POS_Y
)
if
is_in_open_area
(
goal_sorted_list
[
0
][
2
],
goal_sorted_list
[
0
][
3
]):
hfo_env
.
act
(
hfo
.
MOVE
)
elif
goal_sorted_list
[
0
][
1
]
<
min
(
params
[
'KICK_DIST'
],
get_dist_normalized
(
agent_pos_x
,
agent_pos_y
,
GOAL_POS_X
,
GOAL_POS_Y
)):
hfo_env
.
act
(
hfo
.
DEFEND_GOAL
)
else
:
hfo_env
.
act
(
hfo
.
REDUCE_ANGLE_TO_GOAL
)
return
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment