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
ca27922d
Commit
ca27922d
authored
Jul 17, 2017
by
drallensmith
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'randomization' into add_preprocess_action - bring in fixes, avoid rebase
parents
91a48115
ba8342fc
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
133 additions
and
59 deletions
+133
-59
example/defense_2v2.sh
example/defense_2v2.sh
+6
-1
example/defense_long_2v2.sh
example/defense_long_2v2.sh
+14
-0
example/defense_python_2v2.sh
example/defense_python_2v2.sh
+1
-1
example/defense_python_2v3.sh
example/defense_python_2v3.sh
+1
-1
example/defense_python_3v3.sh
example/defense_python_3v3.sh
+1
-1
example/defense_python_long_2v2.sh
example/defense_python_long_2v2.sh
+12
-0
example/hand_coded_defense_agent.py
example/hand_coded_defense_agent.py
+98
-55
No files found.
example/defense_2v2.sh
View file @
ca27922d
...
@@ -3,7 +3,12 @@
...
@@ -3,7 +3,12 @@
# HAS TO BE RUN FROM EXAMPLE DIR DUE TO hand_coded_defense_agent CONFIG!
# HAS TO BE RUN FROM EXAMPLE DIR DUE TO hand_coded_defense_agent CONFIG!
../bin/HFO
--offense-npcs
=
2
--defense-agents
=
1
--defense-npcs
=
1
--trials
20
--headless
--port
=
7000 &
../bin/HFO
--offense-npcs
=
2
--defense-agents
=
1
--defense-npcs
=
1
--trials
20
--headless
--port
=
7000 &
sleep
5
# The below sleep period is needed to avoid the agent connecting in before the
# Trainer.py script gets the base/Helios goalie connected in; if that happens,
# the agent gets assigned unum 1 and there is a mixup in which agent is
# supposed to be the goalie (some portions of the various programs go by unum,
# others go by a goalie flag).
sleep
15
./hand_coded_defense_agent &> agent1.txt &
./hand_coded_defense_agent &> agent1.txt &
sleep
5
sleep
5
...
...
example/defense_long_2v2.sh
0 → 100755
View file @
ca27922d
#!/bin/bash
# HAS TO BE RUN FROM EXAMPLE DIR DUE TO hand_coded_defense_agent CONFIG!
../bin/HFO
--offense-npcs
=
2
--defense-agents
=
1
--defense-npcs
=
1
--trials
5000
--headless
--port
=
7000
--seed
1500310928
--no-logging
&
sleep
15
./hand_coded_defense_agent &> agent1.txt &
sleep
5
# The magic line
# $$ holds the PID for this script
# Negation means kill by process group id instead of PID
trap
"kill -TERM -
$$
"
SIGINT
wait
\ No newline at end of file
example/defense_python_2v2.sh
View file @
ca27922d
#!/bin/bash
#!/bin/bash
./bin/HFO
--offense-npcs
=
2
--defense-agents
=
1
--defense-npcs
=
1
--trials
20
--headless
&
./bin/HFO
--offense-npcs
=
2
--defense-agents
=
1
--defense-npcs
=
1
--trials
20
--headless
&
sleep
5
sleep
1
5
./example/hand_coded_defense_agent.py &> agent1.txt &
./example/hand_coded_defense_agent.py &> agent1.txt &
sleep
5
sleep
5
...
...
example/defense_python_2v3.sh
View file @
ca27922d
#!/bin/bash
#!/bin/bash
./bin/HFO
--offense-npcs
=
2
--defense-agents
=
1
--defense-npcs
=
2
--trials
20
--headless
&
./bin/HFO
--offense-npcs
=
2
--defense-agents
=
1
--defense-npcs
=
2
--trials
20
--headless
&
sleep
5
sleep
1
5
./example/hand_coded_defense_agent.py &> agent1.txt &
./example/hand_coded_defense_agent.py &> agent1.txt &
sleep
5
sleep
5
...
...
example/defense_python_3v3.sh
View file @
ca27922d
#!/bin/bash
#!/bin/bash
./bin/HFO
--offense-npcs
=
3
--defense-agents
=
1
--defense-npcs
=
2
--trials
20
--headless
&
./bin/HFO
--offense-npcs
=
3
--defense-agents
=
1
--defense-npcs
=
2
--trials
20
--headless
&
sleep
5
sleep
1
5
./example/hand_coded_defense_agent.py &> agent1.txt &
./example/hand_coded_defense_agent.py &> agent1.txt &
sleep
5
sleep
5
...
...
example/defense_python_long_2v2.sh
0 → 100755
View file @
ca27922d
#!/bin/bash
./bin/HFO
--offense-npcs
=
2
--defense-agents
=
1
--defense-npcs
=
1
--trials
5000
--headless
--seed
1500310928
--no-logging
&
sleep
15
./example/hand_coded_defense_agent.py &> agent1.txt &
sleep
5
# The magic line
# $$ holds the PID for this script
# Negation means kill by process group id instead of PID
trap
"kill -TERM -
$$
"
SIGINT
wait
\ No newline at end of file
example/hand_coded_defense_agent.py
View file @
ca27922d
...
@@ -27,8 +27,8 @@ GOAL_POS_Y = 0.0
...
@@ -27,8 +27,8 @@ GOAL_POS_Y = 0.0
# below - from hand_coded_defense_agent.cpp except LOW_KICK_DIST
# below - from hand_coded_defense_agent.cpp except LOW_KICK_DIST
HALF_FIELD_WIDTH
=
68
# y coordinate -34 to 34 (-34 = bottom 34 = top)
HALF_FIELD_WIDTH
=
68
# y coordinate -34 to 34 (-34 = bottom 34 = top)
HALF_FIELD_LENGTH
=
52.5
# x coordinate 0 to 52.5 (0 = goalline 52.5 = center)
HALF_FIELD_LENGTH
=
52.5
# x coordinate 0 to 52.5 (0 = goalline 52.5 = center)
params
=
{
'KICK_DIST'
:
1.504052352
,
'OPEN_AREA_HIGH_LIMIT_X'
:
0.747311440447
,
params
=
{
'KICK_DIST'
:
(
1.504052352
*
1
)
,
'OPEN_AREA_HIGH_LIMIT_X'
:
0.747311440447
,
'TACKLE_DIST'
:
1.613456553
,
'LOW_KICK_DIST'
:(
5
/
HALF_FIELD_LENGTH
)}
'TACKLE_DIST'
:
(
1.613456553
*
1
),
'LOW_KICK_DIST'
:((
5
*
5
)
/
HALF_FIELD_LENGTH
)}
def
get_dist_normalized
(
ref_x
,
ref_y
,
src_x
,
src_y
):
def
get_dist_normalized
(
ref_x
,
ref_y
,
src_x
,
src_y
):
...
@@ -39,16 +39,28 @@ def get_dist_normalized(ref_x, ref_y, src_x, src_y):
...
@@ -39,16 +39,28 @@ def get_dist_normalized(ref_x, ref_y, src_x, src_y):
## return get_dist_normalized(ball_pos_x, ball_pos_y,
## return get_dist_normalized(ball_pos_x, ball_pos_y,
## kicker_pos_x, kicker_pos_y) < params['KICK_DIST']
## kicker_pos_x, kicker_pos_y) < params['KICK_DIST']
def
is_tackleable
(
agent_pos_x
,
agent_pos_y
,
opp_pos_x
,
opp_pos_y
):
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
,
return
(
get_dist_normalized
(
agent_pos_x
,
opp_pos_x
,
opp_pos_y
)
<
params
[
'TACKLE_DIST'
]
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
):
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
,
return
(
get_dist_normalized
(
ball_pos_x
,
ball_pos_y
,
GOAL_POS_X
,
GOAL_POS_Y
)
<
get_dist_normalized
(
old_ball_pos_x
,
GOAL_POS_X
,
GOAL_POS_Y
)
<
min
(
params
[
'KICK_DIST'
],
get_dist_normalized
(
old_ball_pos_x
,
old_ball_pos_y
,
old_ball_pos_y
,
GOAL_POS_X
,
GOAL_POS_X
,
GOAL_POS_Y
)
GOAL_POS_Y
)))
def
ball_nearer_to_goal
(
ball_pos_x
,
ball_pos_y
,
agent_pos_x
,
agent_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
(
agent_pos_x
,
agent_pos_y
,
GOAL_POS_X
,
GOAL_POS_Y
))
def
get_sorted_opponents
(
state_vec
,
num_opponents
,
num_teammates
,
pos_x
,
pos_y
):
def
get_sorted_opponents
(
state_vec
,
num_opponents
,
num_teammates
,
pos_x
,
pos_y
):
"""
"""
...
@@ -92,6 +104,9 @@ def do_defense_action(state_vec, hfo_env, episode,
...
@@ -92,6 +104,9 @@ def do_defense_action(state_vec, hfo_env, episode,
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
)
ball_nearer_goal
=
ball_nearer_to_goal
(
ball_pos_x
,
ball_pos_y
,
agent_pos_x
,
agent_pos_y
)
ball_sorted_list
=
get_sorted_opponents
(
state_vec
,
num_opponents
,
num_teammates
,
ball_sorted_list
=
get_sorted_opponents
(
state_vec
,
num_opponents
,
num_teammates
,
pos_x
=
ball_pos_x
,
pos_y
=
ball_pos_y
)
pos_x
=
ball_pos_x
,
pos_y
=
ball_pos_y
)
if
not
ball_sorted_list
:
# unknown opponent positions/unums
if
not
ball_sorted_list
:
# unknown opponent positions/unums
...
@@ -102,75 +117,103 @@ def do_defense_action(state_vec, hfo_env, episode,
...
@@ -102,75 +117,103 @@ def do_defense_action(state_vec, hfo_env, episode,
old_ball_pos_x
,
old_ball_pos_x
,
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
:
hfo_env
.
act
(
hfo
.
REDUCE_ANGLE_TO_GOAL
)
else
:
hfo_env
.
act
(
hfo
.
INTERCEPT
)
hfo_env
.
act
(
hfo
.
INTERCEPT
)
else
:
else
:
hfo_env
.
act
(
hfo
.
MOVE
)
hfo_env
.
act
(
hfo
.
MOVE
)
return
return
goal_sorted_list
=
get_sorted_opponents
(
state_vec
,
num_opponents
,
num_teammates
,
pos_x
=
GOAL_POS_X
,
pos_y
=
GOAL_POS_Y
)
if
ball_toward_goal
:
if
ball_sorted_list
[
0
][
1
]
<
params
[
'LOW_KICK_DIST'
]:
ball_toward_goal
=
False
elif
goal_sorted_list
[
0
][
1
]
<
get_dist_normalized
(
ball_pos_x
,
ball_pos_y
,
GOAL_POS_X
,
GOAL_POS_Y
):
ball_toward_goal
=
False
is_tackleable_opp
=
is_tackleable
(
agent_pos_x
,
agent_pos_y
,
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
])
ball_sorted_list
[
0
][
2
],
ball_sorted_list
[
0
][
3
])
if
state_vec
[
5
]
>
0
:
# kickable distance of player
if
state_vec
[
5
]
>
0
:
# kickable distance of player
if
ball_sorted_list
[
0
][
1
]
<
params
[
'LOW_KICK_DIST'
]
:
if
is_tackleable_opp
:
hfo_env
.
act
(
hfo
.
MOVE
)
# will do tackle
hfo_env
.
act
(
hfo
.
MOVE
)
# will do tackle
elif
ball_nearer_goal
:
hfo_env
.
act
(
hfo
.
REDUCE_ANGLE_TO_GOAL
)
elif
ball_toward_goal
:
elif
ball_toward_goal
:
hfo_env
.
act
(
hfo
.
INTERCEPT
)
hfo_env
.
act
(
hfo
.
INTERCEPT
)
elif
is_tackleable_opp
:
if
ball_sorted_list
[
0
][
1
]
<
get_dist_normalized
(
agent_pos_x
,
agent_pos_y
,
ball_pos_x
,
ball_pos_y
):
hfo_env
.
act
(
hfo
.
MOVE
)
# will do tackle
else
:
hfo_env
.
act
(
hfo
.
INTERCEPT
)
else
:
else
:
hfo_env
.
act
(
hfo
.
GO_TO_BALL
)
hfo_env
.
act
(
hfo
.
GO_TO_BALL
)
return
return
if
ball_sorted_list
[
0
][
1
]
<
params
[
'KICK_DIST'
]:
agent_to_ball_dist
=
get_dist_normalized
(
agent_pos_x
,
agent_pos_y
,
goal_sorted_list
=
get_sorted_opponents
(
state_vec
,
num_opponents
,
num_teammates
,
ball_pos_x
,
ball_pos_y
)
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
goal_sorted_list
[
0
][
0
]
!=
ball_sorted_list
[
0
][
0
]:
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
is_in_open_area
(
goal_sorted_list
[
0
][
2
],
goal_sorted_list
[
0
][
3
]):
if
ball_sorted_list
[
0
][
1
]
<
params
[
'LOW_KICK_DIST'
]:
hfo_env
.
act
(
hfo
.
MARK_PLAYER
,
goal_sorted_list
[
0
][
0
])
hfo_env
.
act
(
hfo
.
MARK_PLAYER
,
goal_sorted_list
[
0
][
0
])
elif
get_dist_normalized
(
agent_pos_x
,
agent_pos_y
,
elif
agent_to_ball_dist
<
ball_sorted_list
[
0
][
1
]:
ball_pos_x
,
ball_pos_y
)
<
ball_sorted_list
[
0
][
1
]:
if
ball_nearer_goal
:
## # odd; why not kickable above?
hfo_env
.
act
(
hfo
.
REDUCE_ANGLE_TO_GOAL
)
## print("Ball dist below {0:n}".format(ball_sorted_list[0][1]) +
elif
ball_toward_goal
:
## " 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
)
hfo_env
.
act
(
hfo
.
INTERCEPT
)
elif
is_in_open_area
(
ball_pos_x
,
ball_pos_y
)
or
(
is_tackleable_opp
and
(
ball_sorted_list
[
0
][
1
]
<
params
[
'LOW_KICK_DIST'
])):
hfo_env
.
act
(
hfo
.
MOVE
)
# will do tackle or appropriate
else
:
else
:
hfo_env
.
act
(
hfo
.
GO_TO_BALL
)
hfo_env
.
act
(
hfo
.
GO_TO_BALL
)
elif
is_tackleable_opp
and
(
ball_sorted_list
[
0
][
1
]
<
params
[
'LOW_KICK_DIST'
]):
hfo_env
.
act
(
hfo
.
MOVE
)
# will do tackle
else
:
else
:
hfo_env
.
act
(
hfo
.
REDUCE_ANGLE_TO_GOAL
)
hfo_env
.
act
(
hfo
.
REDUCE_ANGLE_TO_GOAL
)
elif
is_tackleable_opp
and
(
ball_sorted_list
[
0
][
1
]
<
params
[
'LOW_KICK_DIST'
])
:
elif
ball_sorted_list
[
0
][
1
]
>=
params
[
'KICK_DIST'
]
:
hfo_env
.
act
(
hfo
.
MOVE
)
# will do tackle
if
agent_to_ball_dist
<
ball_sorted_list
[
0
][
1
]:
else
:
if
ball_nearer_goal
:
hfo_env
.
act
(
hfo
.
REDUCE_ANGLE_TO_GOAL
)
hfo_env
.
act
(
hfo
.
REDUCE_ANGLE_TO_GOAL
)
return
elif
ball_toward_goal
:
if
(
not
is_in_open_area
(
ball_pos_x
,
ball_pos_y
))
and
ball_toward_goal
:
hfo_env
.
act
(
hfo
.
INTERCEPT
)
hfo_env
.
act
(
hfo
.
INTERCEPT
)
else
:
hfo_env
.
act
(
hfo
.
GO_TO_BALL
)
else
:
hfo_env
.
act
(
hfo
.
REDUCE_ANGLE_TO_GOAL
)
elif
is_tackleable_opp
and
(
not
is_in_open_area
(
ball_sorted_list
[
0
][
2
],
ball_sorted_list
[
0
][
3
])):
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'
]):
hfo_env
.
act
(
hfo
.
MARK_PLAYER
,
goal_sorted_list
[
0
][
0
])
else
:
hfo_env
.
act
(
hfo
.
REDUCE_ANGLE_TO_GOAL
)
return
return
if
get_dist_normalized
(
agent_pos_x
,
agent_pos_y
,
ball_pos_x
,
ball_pos_y
)
<
ball_sorted_list
[
0
][
1
]:
if
is_in_open_area
(
ball_sorted_list
[
0
][
2
],
ball_sorted_list
[
0
][
3
]):
if
ball_toward_goal
:
if
ball_sorted_list
[
0
][
1
]
<
params
[
'KICK_DIST'
]:
hfo_env
.
act
(
hfo
.
REDUCE_ANGLE_TO_GOAL
)
elif
agent_to_ball_dist
<
params
[
'KICK_DIST'
]:
if
ball_nearer_goal
:
hfo_env
.
act
(
hfo
.
REDUCE_ANGLE_TO_GOAL
)
elif
ball_toward_goal
:
hfo_env
.
act
(
hfo
.
INTERCEPT
)
hfo_env
.
act
(
hfo
.
INTERCEPT
)
elif
is_in_open_area
(
ball_pos_x
,
ball_pos_y
):
else
:
hfo_env
.
act
(
hfo
.
GO_TO_BALL
)
elif
is_tackleable_opp
:
hfo_env
.
act
(
hfo
.
MOVE
)
hfo_env
.
act
(
hfo
.
MOVE
)
else
:
hfo_env
.
act
(
hfo
.
REDUCE_ANGLE_TO_GOAL
)
else
:
if
ball_sorted_list
[
0
][
1
]
>=
max
(
params
[
'KICK_DIST'
],
agent_to_ball_dist
):
if
ball_nearer_goal
:
hfo_env
.
act
(
hfo
.
REDUCE_ANGLE_TO_GOAL
)
elif
ball_toward_goal
:
hfo_env
.
act
(
hfo
.
INTERCEPT
)
else
:
else
:
hfo_env
.
act
(
hfo
.
GO_TO_BALL
)
hfo_env
.
act
(
hfo
.
GO_TO_BALL
)
return
elif
ball_sorted_list
[
0
][
1
]
>=
params
[
'KICK_DIST'
]:
hfo_env
.
act
(
hfo
.
REDUCE_ANGLE_TO_GOAL
)
goal_sorted_list
=
get_sorted_opponents
(
state_vec
,
num_opponents
,
num_teammates
,
elif
is_tackleable_opp
:
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
)
hfo_env
.
act
(
hfo
.
MOVE
)
else
:
else
:
hfo_env
.
act
(
hfo
.
REDUCE_ANGLE_TO_GOAL
)
hfo_env
.
act
(
hfo
.
REDUCE_ANGLE_TO_GOAL
)
...
@@ -183,7 +226,7 @@ def do_random_defense_action(state, hfo_env):
...
@@ -183,7 +226,7 @@ def do_random_defense_action(state, hfo_env):
else
:
else
:
hfo_env
.
act
(
hfo
.
MOVE
)
hfo_env
.
act
(
hfo
.
MOVE
)
else
:
else
:
hfo_env
.
act
(
random
.
choose
(
hfo
.
MOVE
,
hfo
.
MOVE
,
hfo_env
.
act
(
random
.
choose
(
hfo
.
MOVE
,
hfo
.
DEFEND_GOAL
,
hfo
.
REDUCE_ANGLE_TO_GOAL
,
hfo
.
REDUCE_ANGLE_TO_GOAL
,
hfo
.
REDUCE_ANGLE_TO_GOAL
,
hfo
.
REDUCE_ANGLE_TO_GOAL
,
hfo
.
GO_TO_BALL
,
hfo
.
INTERCEPT
))
hfo
.
GO_TO_BALL
,
hfo
.
INTERCEPT
))
return
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