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
2e10799f
You need to sign in or sign up before continuing.
Commit
2e10799f
authored
Jul 17, 2017
by
drallensmith
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Instrument hand_coded_defense_agent.py
parent
ba8342fc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
2 deletions
+45
-2
example/hand_coded_defense_agent.py
example/hand_coded_defense_agent.py
+45
-2
No files found.
example/hand_coded_defense_agent.py
View file @
2e10799f
...
@@ -83,6 +83,12 @@ def get_sorted_opponents(state_vec, num_opponents, num_teammates, pos_x, pos_y):
...
@@ -83,6 +83,12 @@ def get_sorted_opponents(state_vec, num_opponents, num_teammates, pos_x, pos_y):
def
is_in_open_area
(
pos_x
,
ignored_pos_y
):
def
is_in_open_area
(
pos_x
,
ignored_pos_y
):
return
pos_x
>=
params
[
'OPEN_AREA_HIGH_LIMIT_X'
]
return
pos_x
>=
params
[
'OPEN_AREA_HIGH_LIMIT_X'
]
num_times_intercept
=
0
num_times_move
=
0
num_times_RATG
=
0
num_times_GTB
=
0
num_times_MP
=
0
def
do_defense_action
(
state_vec
,
hfo_env
,
episode
,
def
do_defense_action
(
state_vec
,
hfo_env
,
episode
,
num_opponents
,
num_teammates
,
num_opponents
,
num_teammates
,
old_ball_pos_x
,
old_ball_pos_y
):
old_ball_pos_x
,
old_ball_pos_y
):
...
@@ -101,6 +107,8 @@ def do_defense_action(state_vec, hfo_env, episode,
...
@@ -101,6 +107,8 @@ def do_defense_action(state_vec, hfo_env, episode,
hfo_env
.
act
(
hfo
.
MOVE
)
# will be Reorient in that version
hfo_env
.
act
(
hfo
.
MOVE
)
# will be Reorient in that version
return
return
global
num_times_intercept
,
num_times_move
,
num_times_RATG
,
num_times_GTB
,
num_times_MP
ball_toward_goal
=
ball_moving_toward_goal
(
ball_pos_x
,
ball_pos_y
,
ball_toward_goal
=
ball_moving_toward_goal
(
ball_pos_x
,
ball_pos_y
,
old_ball_pos_x
,
old_ball_pos_y
)
old_ball_pos_x
,
old_ball_pos_y
)
...
@@ -118,10 +126,13 @@ def do_defense_action(state_vec, hfo_env, episode,
...
@@ -118,10 +126,13 @@ def do_defense_action(state_vec, hfo_env, episode,
old_ball_pos_y
))
old_ball_pos_y
))
if
ball_toward_goal
and
(
not
is_in_open_area
(
ball_pos_x
,
ball_pos_y
)):
if
ball_toward_goal
and
(
not
is_in_open_area
(
ball_pos_x
,
ball_pos_y
)):
if
ball_nearer_goal
:
if
ball_nearer_goal
:
num_times_RATG
+=
1
hfo_env
.
act
(
hfo
.
REDUCE_ANGLE_TO_GOAL
)
hfo_env
.
act
(
hfo
.
REDUCE_ANGLE_TO_GOAL
)
else
:
else
:
num_times_intercept
+=
1
hfo_env
.
act
(
hfo
.
INTERCEPT
)
hfo_env
.
act
(
hfo
.
INTERCEPT
)
else
:
else
:
num_times_move
+=
1
hfo_env
.
act
(
hfo
.
MOVE
)
hfo_env
.
act
(
hfo
.
MOVE
)
return
return
...
@@ -141,12 +152,16 @@ def do_defense_action(state_vec, hfo_env, episode,
...
@@ -141,12 +152,16 @@ def do_defense_action(state_vec, hfo_env, episode,
if
state_vec
[
5
]
>
0
:
# kickable distance of player
if
state_vec
[
5
]
>
0
:
# kickable distance of player
if
is_tackleable_opp
:
if
is_tackleable_opp
:
num_times_move
+=
1
hfo_env
.
act
(
hfo
.
MOVE
)
# will do tackle
hfo_env
.
act
(
hfo
.
MOVE
)
# will do tackle
elif
ball_nearer_goal
:
elif
ball_nearer_goal
:
num_times_RATG
+=
1
hfo_env
.
act
(
hfo
.
REDUCE_ANGLE_TO_GOAL
)
hfo_env
.
act
(
hfo
.
REDUCE_ANGLE_TO_GOAL
)
elif
ball_toward_goal
:
elif
ball_toward_goal
:
num_times_intercept
+=
1
hfo_env
.
act
(
hfo
.
INTERCEPT
)
hfo_env
.
act
(
hfo
.
INTERCEPT
)
else
:
else
:
num_times_GTB
+=
1
hfo_env
.
act
(
hfo
.
GO_TO_BALL
)
hfo_env
.
act
(
hfo
.
GO_TO_BALL
)
return
return
...
@@ -158,64 +173,86 @@ def do_defense_action(state_vec, hfo_env, episode,
...
@@ -158,64 +173,86 @@ def do_defense_action(state_vec, hfo_env, episode,
ball_sorted_list
[
0
][
3
])
and
is_in_open_area
(
goal_sorted_list
[
0
][
2
],
ball_sorted_list
[
0
][
3
])
and
is_in_open_area
(
goal_sorted_list
[
0
][
2
],
goal_sorted_list
[
0
][
3
]):
goal_sorted_list
[
0
][
3
]):
if
ball_sorted_list
[
0
][
1
]
<
params
[
'LOW_KICK_DIST'
]:
if
ball_sorted_list
[
0
][
1
]
<
params
[
'LOW_KICK_DIST'
]:
num_times_MP
+=
1
hfo_env
.
act
(
hfo
.
MARK_PLAYER
,
goal_sorted_list
[
0
][
0
])
hfo_env
.
act
(
hfo
.
MARK_PLAYER
,
goal_sorted_list
[
0
][
0
])
elif
agent_to_ball_dist
<
ball_sorted_list
[
0
][
1
]:
elif
agent_to_ball_dist
<
ball_sorted_list
[
0
][
1
]:
if
ball_nearer_goal
:
if
ball_nearer_goal
:
num_times_RATG
+=
1
hfo_env
.
act
(
hfo
.
REDUCE_ANGLE_TO_GOAL
)
hfo_env
.
act
(
hfo
.
REDUCE_ANGLE_TO_GOAL
)
elif
ball_toward_goal
:
elif
ball_toward_goal
:
num_times_intercept
+=
1
hfo_env
.
act
(
hfo
.
INTERCEPT
)
hfo_env
.
act
(
hfo
.
INTERCEPT
)
else
:
else
:
num_times_GTB
+=
1
hfo_env
.
act
(
hfo
.
GO_TO_BALL
)
hfo_env
.
act
(
hfo
.
GO_TO_BALL
)
else
:
else
:
num_times_RATG
+=
1
hfo_env
.
act
(
hfo
.
REDUCE_ANGLE_TO_GOAL
)
hfo_env
.
act
(
hfo
.
REDUCE_ANGLE_TO_GOAL
)
elif
ball_sorted_list
[
0
][
1
]
>=
params
[
'KICK_DIST'
]:
elif
ball_sorted_list
[
0
][
1
]
>=
params
[
'KICK_DIST'
]:
if
agent_to_ball_dist
<
ball_sorted_list
[
0
][
1
]:
if
agent_to_ball_dist
<
ball_sorted_list
[
0
][
1
]:
if
ball_nearer_goal
:
if
ball_nearer_goal
:
num_times_RATG
+=
1
hfo_env
.
act
(
hfo
.
REDUCE_ANGLE_TO_GOAL
)
hfo_env
.
act
(
hfo
.
REDUCE_ANGLE_TO_GOAL
)
elif
ball_toward_goal
:
elif
ball_toward_goal
:
num_times_intercept
+=
1
hfo_env
.
act
(
hfo
.
INTERCEPT
)
hfo_env
.
act
(
hfo
.
INTERCEPT
)
else
:
else
:
num_times_GTB
+=
1
hfo_env
.
act
(
hfo
.
GO_TO_BALL
)
hfo_env
.
act
(
hfo
.
GO_TO_BALL
)
else
:
else
:
num_times_RATG
+=
1
hfo_env
.
act
(
hfo
.
REDUCE_ANGLE_TO_GOAL
)
hfo_env
.
act
(
hfo
.
REDUCE_ANGLE_TO_GOAL
)
elif
is_tackleable_opp
and
(
not
is_in_open_area
(
ball_sorted_list
[
0
][
2
],
elif
is_tackleable_opp
and
(
not
is_in_open_area
(
ball_sorted_list
[
0
][
2
],
ball_sorted_list
[
0
][
3
])):
ball_sorted_list
[
0
][
3
])):
num_times_move
+=
1
hfo_env
.
act
(
hfo
.
MOVE
)
hfo_env
.
act
(
hfo
.
MOVE
)
## elif is_in_open_area(ball_sorted_list[0][2],ball_sorted_list[0][3]):
## hfo_env.act(hfo.REDUCE_ANGLE_TO_GOAL) # why not MARK_PLAYER for the one that is not in the open area?
elif
ball_sorted_list
[
0
][
1
]
<
(
1
*
params
[
'LOW_KICK_DIST'
]):
elif
ball_sorted_list
[
0
][
1
]
<
(
1
*
params
[
'LOW_KICK_DIST'
]):
num_times_MP
+=
1
hfo_env
.
act
(
hfo
.
MARK_PLAYER
,
goal_sorted_list
[
0
][
0
])
hfo_env
.
act
(
hfo
.
MARK_PLAYER
,
goal_sorted_list
[
0
][
0
])
else
:
else
:
num_times_RATG
+=
1
hfo_env
.
act
(
hfo
.
REDUCE_ANGLE_TO_GOAL
)
hfo_env
.
act
(
hfo
.
REDUCE_ANGLE_TO_GOAL
)
return
return
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
]):
if
ball_sorted_list
[
0
][
1
]
<
params
[
'KICK_DIST'
]:
if
ball_sorted_list
[
0
][
1
]
<
params
[
'KICK_DIST'
]:
num_times_RATG
+=
1
hfo_env
.
act
(
hfo
.
REDUCE_ANGLE_TO_GOAL
)
hfo_env
.
act
(
hfo
.
REDUCE_ANGLE_TO_GOAL
)
elif
agent_to_ball_dist
<
params
[
'KICK_DIST'
]:
elif
agent_to_ball_dist
<
params
[
'KICK_DIST'
]:
if
ball_nearer_goal
:
if
ball_nearer_goal
:
num_times_RATG
+=
1
hfo_env
.
act
(
hfo
.
REDUCE_ANGLE_TO_GOAL
)
hfo_env
.
act
(
hfo
.
REDUCE_ANGLE_TO_GOAL
)
elif
ball_toward_goal
:
elif
ball_toward_goal
:
num_times_intercept
+=
1
hfo_env
.
act
(
hfo
.
INTERCEPT
)
hfo_env
.
act
(
hfo
.
INTERCEPT
)
else
:
else
:
num_times_GTB
+=
1
hfo_env
.
act
(
hfo
.
GO_TO_BALL
)
hfo_env
.
act
(
hfo
.
GO_TO_BALL
)
elif
is_tackleable_opp
:
elif
is_tackleable_opp
:
num_times_move
+=
1
hfo_env
.
act
(
hfo
.
MOVE
)
hfo_env
.
act
(
hfo
.
MOVE
)
else
:
else
:
num_times_RATG
+=
1
hfo_env
.
act
(
hfo
.
REDUCE_ANGLE_TO_GOAL
)
hfo_env
.
act
(
hfo
.
REDUCE_ANGLE_TO_GOAL
)
else
:
else
:
if
ball_sorted_list
[
0
][
1
]
>=
max
(
params
[
'KICK_DIST'
],
agent_to_ball_dist
):
if
ball_sorted_list
[
0
][
1
]
>=
max
(
params
[
'KICK_DIST'
],
agent_to_ball_dist
):
if
ball_nearer_goal
:
if
ball_nearer_goal
:
num_times_RATG
+=
1
hfo_env
.
act
(
hfo
.
REDUCE_ANGLE_TO_GOAL
)
hfo_env
.
act
(
hfo
.
REDUCE_ANGLE_TO_GOAL
)
elif
ball_toward_goal
:
elif
ball_toward_goal
:
num_times_intercept
+=
1
hfo_env
.
act
(
hfo
.
INTERCEPT
)
hfo_env
.
act
(
hfo
.
INTERCEPT
)
else
:
else
:
num_times_GTB
+=
1
hfo_env
.
act
(
hfo
.
GO_TO_BALL
)
hfo_env
.
act
(
hfo
.
GO_TO_BALL
)
elif
ball_sorted_list
[
0
][
1
]
>=
params
[
'KICK_DIST'
]:
elif
ball_sorted_list
[
0
][
1
]
>=
params
[
'KICK_DIST'
]:
num_times_RATG
+=
1
hfo_env
.
act
(
hfo
.
REDUCE_ANGLE_TO_GOAL
)
hfo_env
.
act
(
hfo
.
REDUCE_ANGLE_TO_GOAL
)
elif
is_tackleable_opp
:
elif
is_tackleable_opp
:
num_times_move
+=
1
hfo_env
.
act
(
hfo
.
MOVE
)
hfo_env
.
act
(
hfo
.
MOVE
)
else
:
else
:
num_times_RATG
+=
1
hfo_env
.
act
(
hfo
.
REDUCE_ANGLE_TO_GOAL
)
hfo_env
.
act
(
hfo
.
REDUCE_ANGLE_TO_GOAL
)
return
return
...
@@ -267,6 +304,7 @@ def main():
...
@@ -267,6 +304,7 @@ def main():
my_unum
=
hfo_env
.
getUnum
()
my_unum
=
hfo_env
.
getUnum
()
assert
((
my_unum
>
1
)
and
(
my_unum
<=
11
)),
"Bad unum {!r}"
.
format
(
my_unum
)
assert
((
my_unum
>
1
)
and
(
my_unum
<=
11
)),
"Bad unum {!r}"
.
format
(
my_unum
)
print
(
"My unum is {0:d}"
.
format
(
my_unum
))
print
(
"My unum is {0:d}"
.
format
(
my_unum
))
global
num_times_intercept
,
num_times_move
,
num_times_RATG
,
num_times_GTB
,
num_times_MP
for
episode
in
itertools
.
count
():
for
episode
in
itertools
.
count
():
old_ball_pos_x
=
-
1
old_ball_pos_x
=
-
1
old_ball_pos_y
=
0
old_ball_pos_y
=
0
...
@@ -293,6 +331,11 @@ def main():
...
@@ -293,6 +331,11 @@ def main():
# Quit if the server goes down
# Quit if the server goes down
if
status
==
hfo
.
SERVER_DOWN
:
if
status
==
hfo
.
SERVER_DOWN
:
print
(
"Intercept: {0:d}; Move: {1:d}"
.
format
(
num_times_intercept
,
num_times_move
))
print
(
"RATG: {0:d}; GTB: {1:d}; MP: {2:d}"
.
format
(
num_times_RATG
,
num_times_GTB
,
num_times_MP
))
hfo_env
.
act
(
hfo
.
QUIT
)
hfo_env
.
act
(
hfo
.
QUIT
)
exit
()
exit
()
...
...
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