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
e9af5a81
You need to sign in or sign up before continuing.
Commit
e9af5a81
authored
Jul 12, 2017
by
drallensmith
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Got rand-pass working (need to backport to randomization); other bugfixes
parent
f461c24a
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
97 additions
and
34 deletions
+97
-34
example/high_action_random_agent.py
example/high_action_random_agent.py
+14
-1
example/high_level_custom_agent.py
example/high_level_custom_agent.py
+51
-31
example/high_level_random_agent.py
example/high_level_random_agent.py
+5
-2
example/python_agents_rpass_3v3.sh
example/python_agents_rpass_3v3.sh
+14
-0
example/random_high_action_2v1.sh
example/random_high_action_2v1.sh
+13
-0
No files found.
example/high_action_random_agent.py
View file @
e9af5a81
#!/usr/bin/env python
#!/usr/bin/env python
from
__future__
import
print_function
# encoding: utf-8
# encoding: utf-8
# Before running this program, first Start HFO server:
# Before running this program, first Start HFO server:
...
@@ -30,7 +31,12 @@ def main():
...
@@ -30,7 +31,12 @@ def main():
hfo_env
.
connectToServer
(
hfo
.
LOW_LEVEL_FEATURE_SET
,
hfo_env
.
connectToServer
(
hfo
.
LOW_LEVEL_FEATURE_SET
,
'bin/teams/base/config/formations-dt'
,
args
.
port
,
'bin/teams/base/config/formations-dt'
,
args
.
port
,
'localhost'
,
'base_left'
,
False
)
'localhost'
,
'base_left'
,
False
)
if
args
.
seed
:
print
(
"Python randomization seed: {0:d}"
.
format
(
args
.
seed
))
for
episode
in
itertools
.
count
():
for
episode
in
itertools
.
count
():
num_reorient
=
0
num_move
=
0
num_had_ball
=
0
status
=
hfo
.
IN_GAME
status
=
hfo
.
IN_GAME
while
status
==
hfo
.
IN_GAME
:
while
status
==
hfo
.
IN_GAME
:
# Get the vector of state features for the current state
# Get the vector of state features for the current state
...
@@ -41,16 +47,23 @@ def main():
...
@@ -41,16 +47,23 @@ def main():
hfo_env
.
act
(
hfo
.
SHOOT
)
hfo_env
.
act
(
hfo
.
SHOOT
)
else
:
else
:
hfo_env
.
act
(
hfo
.
DRIBBLE
)
hfo_env
.
act
(
hfo
.
DRIBBLE
)
num_had_ball
+=
1
# 8 is frozen; rest are self or ball position/velocity valid
# 8 is frozen; rest are self or ball position/velocity valid
elif
(
state
[
8
]
>
0
)
or
(
min
(
state
[
0
],
state
[
1
],
state
[
50
],
state
[
54
])
<
0
):
elif
(
state
[
8
]
>
0
)
or
(
min
(
state
[
0
],
state
[
1
],
state
[
50
],
state
[
54
])
<
0
):
hfo_env
.
act
(
hfo
.
REORIENT
)
hfo_env
.
act
(
hfo
.
REORIENT
)
num_reorient
+=
1
else
:
else
:
hfo_env
.
act
(
hfo
.
MOVE
)
hfo_env
.
act
(
hfo
.
MOVE
)
num_move
+=
1
# Advance the environment and get the game status
# Advance the environment and get the game status
status
=
hfo_env
.
step
()
status
=
hfo_env
.
step
()
# Check the outcome of the episode
# Check the outcome of the episode
print
((
'Episode
%
d ended with
%
s'
%
(
episode
,
hfo
.
statusToString
(
status
))))
print
(
"Episode {0:d} ended with status {1}"
.
format
(
episode
,
hfo_env
.
statusToString
(
status
)))
print
(
"
\t
Had ball: {0:d}; Reorient: {1:d}; Move: {2:d}"
.
format
(
num_had_ball
,
num_reorient
,
num_move
))
# Quit if the server goes down
# Quit if the server goes down
if
status
==
hfo
.
SERVER_DOWN
:
if
status
==
hfo
.
SERVER_DOWN
:
hfo_env
.
act
(
hfo
.
QUIT
)
hfo_env
.
act
(
hfo
.
QUIT
)
...
...
example/high_level_custom_agent.py
View file @
e9af5a81
#!/usr/bin/env python
#!/usr/bin/env python
from
__future__
import
print_function
# encoding: utf-8
# encoding: utf-8
#MODIFIED#
#MODIFIED#
# First Start the server: $> bin/start.py
# First Start the server: $> bin/start.py
import
argparse
import
argparse
import
itertools
import
random
import
random
try
:
try
:
import
hfo
import
hfo
...
@@ -27,9 +29,6 @@ def has_better_pos(dist_to_op, goal_angle, pass_angle, curr_goal_angle):
...
@@ -27,9 +29,6 @@ def has_better_pos(dist_to_op, goal_angle, pass_angle, curr_goal_angle):
return
False
return
False
return
True
return
True
def
can_dribble
(
dist_to_op
):
return
bool
(
dist_to_op
>
params
[
'DRIB_DST'
])
def
get_action
(
state
,
hfo_env
,
num_teammates
,
rand_pass
):
def
get_action
(
state
,
hfo_env
,
num_teammates
,
rand_pass
):
"""Decides and performs the action to be taken by the agent."""
"""Decides and performs the action to be taken by the agent."""
...
@@ -38,10 +37,9 @@ def get_action(state,hfo_env,num_teammates,rand_pass):
...
@@ -38,10 +37,9 @@ def get_action(state,hfo_env,num_teammates,rand_pass):
if
can_shoot
(
goal_dist
,
goal_op_angle
):
if
can_shoot
(
goal_dist
,
goal_op_angle
):
hfo_env
.
act
(
hfo
.
SHOOT
)
hfo_env
.
act
(
hfo
.
SHOOT
)
return
return
team_list
=
list
(
range
(
num_teammates
))
if
rand_pass
and
(
num_teammates
>
1
):
if
rand_pass
and
(
num_teammates
>
1
):
team_list
=
random
.
shuffle
(
range
(
num_teammates
))
random
.
shuffle
(
team_list
)
else
:
team_list
=
range
(
num_teammates
)
for
i
in
team_list
:
for
i
in
team_list
:
teammate_uniform_number
=
state
[
10
+
3
*
num_teammates
+
3
*
i
+
2
]
teammate_uniform_number
=
state
[
10
+
3
*
num_teammates
+
3
*
i
+
2
]
if
has_better_pos
(
dist_to_op
=
float
(
state
[
10
+
num_teammates
+
i
]),
if
has_better_pos
(
dist_to_op
=
float
(
state
[
10
+
num_teammates
+
i
]),
...
@@ -50,14 +48,10 @@ def get_action(state,hfo_env,num_teammates,rand_pass):
...
@@ -50,14 +48,10 @@ def get_action(state,hfo_env,num_teammates,rand_pass):
curr_goal_angle
=
goal_op_angle
):
curr_goal_angle
=
goal_op_angle
):
hfo_env
.
act
(
hfo
.
PASS
,
teammate_uniform_number
)
hfo_env
.
act
(
hfo
.
PASS
,
teammate_uniform_number
)
return
return
# not sure if below check is needed - doDribble in agent.cpp includes
# no check for can_dribble is needed; doDribble in agent.cpp includes
# (via doPreprocess) doForceKick, which may cover this situation depending
# (via doPreprocess) doForceKick, which will cover this situation since
# on what existKickableOpponent returns.
# existKickableOpponent is based on distance.
if
can_dribble
(
dist_to_op
=
state
[
9
]):
hfo_env
.
act
(
hfo
.
DRIBBLE
)
hfo_env
.
act
(
hfo
.
DRIBBLE
)
else
:
# If nothing can be done, do not do anything
hfo_env
.
act
(
hfo
.
NOOP
)
return
return
...
@@ -79,26 +73,52 @@ def main():
...
@@ -79,26 +73,52 @@ def main():
hfo_env
.
connectToServer
(
hfo
.
HIGH_LEVEL_FEATURE_SET
,
hfo_env
.
connectToServer
(
hfo
.
HIGH_LEVEL_FEATURE_SET
,
'bin/teams/base/config/formations-dt'
,
args
.
port
,
'bin/teams/base/config/formations-dt'
,
args
.
port
,
'localhost'
,
'base_left'
,
False
)
'localhost'
,
'base_left'
,
False
)
status
=
hfo
.
IN_GAME
if
args
.
seed
:
while
status
!=
hfo
.
SERVER_DOWN
:
if
args
.
rand_pass
or
(
args
.
eps
>
0
):
state
=
hfo_env
.
getState
()
print
(
"Python randomization seed: {0:d}"
.
format
(
args
.
seed
))
#print(state)
else
:
if
int
(
state
[
5
])
==
1
:
# state[5] is 1 when player has the ball
print
(
"Python randomization seed setting is useless without --rand-pass or --eps >0"
)
if
(
args
.
eps
>
0
)
and
(
random
.
random
()
<
args
.
eps
):
if
args
.
rand_pass
and
(
args
.
numTeammates
>
0
):
if
random
.
random
()
<
0.5
:
print
(
"Randomizing order of checking for a pass"
)
hfo_env
.
act
(
hfo
.
SHOOT
)
if
args
.
eps
>
0
:
print
(
"Using eps(ilon) {0:n}"
.
format
(
args
.
eps
))
for
episode
in
itertools
.
count
():
num_eps
=
0
num_had_ball
=
0
num_move
=
0
status
=
hfo
.
IN_GAME
while
status
==
hfo
.
IN_GAME
:
state
=
hfo_env
.
getState
()
#print(state)
if
int
(
state
[
5
])
==
1
:
# state[5] is 1 when player has the ball
if
(
args
.
eps
>
0
)
and
(
random
.
random
()
<
args
.
eps
):
if
random
.
random
()
<
0.5
:
hfo_env
.
act
(
hfo
.
SHOOT
)
else
:
hfo_env
.
act
(
hfo
.
DRIBBLE
)
num_eps
+=
1
else
:
else
:
hfo_env
.
act
(
hfo
.
DRIBBLE
)
get_action
(
state
,
hfo_env
,
args
.
numTeammates
,
args
.
rand_pass
)
num_had_ball
+=
1
else
:
else
:
get_action
(
state
,
hfo_env
,
args
.
numTeammates
,
args
.
rand_pass
)
hfo_env
.
act
(
hfo
.
MOVE
)
else
:
num_move
+=
1
hfo_env
.
act
(
hfo
.
MOVE
)
status
=
hfo_env
.
step
()
status
=
hfo_env
.
step
()
#print(status)
#print(status)
hfo_env
.
act
(
hfo
.
QUIT
)
# Quit if the server goes down
exit
()
if
status
==
hfo
.
SERVER_DOWN
:
hfo_env
.
act
(
hfo
.
QUIT
)
exit
()
# Check the outcome of the episode
print
(
"Episode {0:d} ended with {1:s}"
.
format
(
episode
,
hfo_env
.
statusToString
(
status
)))
if
args
.
eps
>
0
:
print
(
"
\t
Num move: {0:d}; Random action: {1:d}; Nonrandom: {2:d}"
.
format
(
num_move
,
num_eps
,
(
num_had_ball
-
num_eps
)))
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
main
()
main
()
example/high_level_random_agent.py
View file @
e9af5a81
#!/usr/bin/env python
#!/usr/bin/env python
from
__future__
import
print_function
# encoding: utf-8
# encoding: utf-8
# Before running this program, first Start HFO server:
# Before running this program, first Start HFO server:
...
@@ -30,6 +31,8 @@ def main():
...
@@ -30,6 +31,8 @@ def main():
hfo_env
.
connectToServer
(
hfo
.
HIGH_LEVEL_FEATURE_SET
,
hfo_env
.
connectToServer
(
hfo
.
HIGH_LEVEL_FEATURE_SET
,
'bin/teams/base/config/formations-dt'
,
args
.
port
,
'bin/teams/base/config/formations-dt'
,
args
.
port
,
'localhost'
,
'base_left'
,
False
)
'localhost'
,
'base_left'
,
False
)
if
args
.
seed
:
print
(
"Python randomization seed: {0:d}"
.
format
(
args
.
seed
))
for
episode
in
itertools
.
count
():
for
episode
in
itertools
.
count
():
status
=
hfo
.
IN_GAME
status
=
hfo
.
IN_GAME
while
status
==
hfo
.
IN_GAME
:
while
status
==
hfo
.
IN_GAME
:
...
@@ -47,8 +50,8 @@ def main():
...
@@ -47,8 +50,8 @@ def main():
status
=
hfo_env
.
step
()
status
=
hfo_env
.
step
()
# Check the outcome of the episode
# Check the outcome of the episode
print
(
(
'Episode
%
d ended with
%
s'
%
(
episode
,
print
(
"Episode {0:d} ended with {1:s}"
.
format
(
episode
,
hfo_env
.
statusToString
(
status
)
)))
hfo_env
.
statusToString
(
status
)))
# Quit if the server goes down
# Quit if the server goes down
if
status
==
hfo
.
SERVER_DOWN
:
if
status
==
hfo
.
SERVER_DOWN
:
hfo_env
.
act
(
hfo
.
QUIT
)
hfo_env
.
act
(
hfo
.
QUIT
)
...
...
example/python_agents_rpass_3v3.sh
0 → 100755
View file @
e9af5a81
#!/bin/bash
./bin/HFO
--offense-agents
=
2
--defense-npcs
=
3
--offense-npcs
=
1
--trials
20
--headless
&
sleep
5
# -x is needed to skip first line - otherwise whatever default python version is will run
python2.7
-x
./example/high_level_custom_agent.py
--numTeammates
=
2
--numOpponents
=
3
--rand-pass
--port
6000 &> agent1.txt &
sleep
5
python3
-x
./example/high_level_custom_agent.py
--numTeammates
=
2
--numOpponents
=
3
--rand-pass
--port
6000 &> agent2.txt &
# The magic line
# $$ holds the PID for this script
# Negation means kill by process group id instead of PID
trap
"kill -TERM -
$$
"
SIGINT
wait
example/random_high_action_2v1.sh
0 → 100755
View file @
e9af5a81
#!/bin/bash
./bin/HFO
--offense-agents
=
2
--defense-npcs
=
1
--trials
20
--headless
&
sleep
5
python2.7
-x
example/high_action_random_agent.py
--port
6000 &> agent1.txt &
sleep
5
python3
-x
example/high_action_random_agent.py
--port
6000 &> agent2.txt &
# The magic line
# $$ holds the PID for this script
# Negation means kill by process group id instead of PID
trap
"kill -TERM -
$$
"
SIGINT
wait
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