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
3275a136
Commit
3275a136
authored
May 30, 2017
by
DurgeshSamant
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
python3-port-cleanup
parent
4a9eea2e
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
2 additions
and
381 deletions
+2
-381
bin/HFO.bak
bin/HFO.bak
+0
-192
example/high_level_custom_agent_py2.py
example/high_level_custom_agent_py2.py
+0
-94
example/high_level_custom_agent_py3.py
example/high_level_custom_agent_py3.py
+0
-93
example/python_agents_3v3.sh
example/python_agents_3v3.sh
+2
-2
No files found.
bin/HFO.bak
deleted
100755 → 0
View file @
4a9eea2e
#!/usr/bin/env python
# encoding: utf-8
import
subprocess
,
os
,
time
,
numpy
,
sys
# Global list of all/essential running processes
processes
,
necProcesses
=
[],
[]
# Command to run the rcssserver. Edit as needed.
SERVER_BIN
=
'rcssserver'
# Command to run the monitor. Edit as needed.
MONITOR_BIN
=
'soccerwindow2'
def
launch
(
cmd
,
name
=
'Unknown'
,
necessary
=
True
,
supressOutput
=
True
):
"""Launch a process.
Appends to list of processes and (optionally) necProcesses if
necessary flag is True.
Returns: The launched process.
"""
kwargs
=
{}
if
supressOutput
:
kwargs
=
{
'stdout'
:
open
(
'/dev/null'
,
'w'
),
'stderr'
:
open
(
'/dev/null'
,
'w'
)}
p
=
subprocess
.
Popen
(
cmd
.
split
(
' '
),
shell
=
False
,
**
kwargs
)
processes
.
append
(
p
)
if
necessary
:
necProcesses
.
append
([
p
,
name
])
return
p
def
main
(
args
):
"""Sets up the teams, launches the server and monitor, starts the trainer.
"""
if
args
.
logging
and
not
os
.
path
.
exists
(
args
.
logDir
):
os
.
makedirs
(
args
.
logDir
)
num_agents
=
args
.
offenseAgents
+
args
.
defenseAgents
binary_dir
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
server_port
=
args
.
port
coach_port
=
args
.
port
+
1
olcoach_port
=
args
.
port
+
2
serverCommand
=
os
.
path
.
join
(
binary_dir
,
SERVER_BIN
)
serverOptions
=
' server::port=
%
i server::coach_port=
%
i '
\
'server::olcoach_port=
%
i server::coach=1 '
\
'server::game_logging=
%
i server::text_logging=
%
i '
\
'server::hfo_logging=
%
i server::hfo_log_dir=
%
s '
\
'server::game_log_dir=
%
s server::text_log_dir=
%
s '
\
'server::synch_mode=
%
i server::hfo=1 '
\
'server::fullstate_l=
%
i server::fullstate_r=
%
i '
\
'server::coach_w_referee=1 server::hfo_max_trial_time=
%
i '
\
'server::hfo_max_trials=
%
i server::hfo_max_frames=
%
i '
\
'server::hfo_offense_on_ball=
%
i server::random_seed=
%
i '
\
'server::hfo_max_untouched_time=
%
i '
\
'server::hfo_min_ball_pos_x=
%
f '
\
'server::hfo_max_ball_pos_x=
%
f '
\
'server::say_msg_size=
%
i '
\
'server::record_messages=
%
i'
\
%
(
server_port
,
coach_port
,
olcoach_port
,
args
.
logging
,
args
.
logging
,
args
.
logging
,
args
.
logDir
,
args
.
logDir
,
args
.
logDir
,
args
.
sync
,
args
.
fullstate
,
args
.
fullstate
,
args
.
maxFramesPerTrial
,
args
.
numTrials
,
args
.
numFrames
,
args
.
offenseOnBall
,
args
.
seed
,
args
.
maxUntouchedTime
,
args
.
min_ball_x
,
args
.
max_ball_x
,
args
.
messageSize
,
args
.
verbose
)
try
:
# Launch the Server
server
=
launch
(
serverCommand
+
serverOptions
,
name
=
'server'
,
supressOutput
=
not
args
.
verbose
)
time
.
sleep
(
0.2
)
assert
server
.
poll
()
is
None
,
\
'[start.py] Failed to launch Server with command:
\"
%
s
\"
'
\
'
\n\n
Another rcssserver may be running on the same port?'
\
'
\n
Try:
\"
killall -9 rcssserver
\"
'
\
%
(
serverCommand
+
serverOptions
)
if
not
args
.
headless
:
monitorCommand
=
os
.
path
.
join
(
binary_dir
,
MONITOR_BIN
)
monitorOptions
=
' --connect --port=
%
i'
%
(
server_port
)
launch
(
monitorCommand
+
monitorOptions
,
name
=
'monitor'
)
# Launch the Trainer
from
Trainer
import
Trainer
trainer
=
Trainer
(
args
=
args
,
server_port
=
server_port
,
coach_port
=
coach_port
)
trainer
.
initComm
()
# Run
trainer
.
run
(
necProcesses
,
args
.
offenseTeam
,
args
.
defenseTeam
)
except
KeyboardInterrupt
:
print
(
'[start.py] Exiting for CTRL-C'
)
finally
:
print
(
'[start.py] Cleaning up server and other processes'
)
for
p
in
reversed
(
processes
):
try
:
p
.
terminate
()
time
.
sleep
(
0.1
)
p
.
kill
()
except
:
pass
def
parseArgs
():
import
argparse
team_dir
=
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
)),
'teams'
)
installed_teams
=
os
.
listdir
(
team_dir
)
p
=
argparse
.
ArgumentParser
(
description
=
'Start Half Field Offense.'
,
formatter_class
=
argparse
.
RawTextHelpFormatter
)
p
.
add_argument
(
'--headless'
,
dest
=
'headless'
,
action
=
'store_true'
,
help
=
'Run without a monitor.'
)
p
.
add_argument
(
'--trials'
,
dest
=
'numTrials'
,
type
=
int
,
default
=-
1
,
help
=
'Number of trials to run.
\n
'
\
'Negative values mean unlimited. Default: -1.'
)
p
.
add_argument
(
'--frames'
,
dest
=
'numFrames'
,
type
=
int
,
default
=-
1
,
help
=
'Number of frames to run for.
\n
'
\
'Negative values mean unlimited. Default: -1.'
)
p
.
add_argument
(
'--frames-per-trial'
,
dest
=
'maxFramesPerTrial'
,
type
=
int
,
default
=
1000
,
help
=
'Max number of frames per trial.
\n
'
\
'Negative values mean unlimited. Default: 1000.'
)
p
.
add_argument
(
'--untouched-time'
,
dest
=
'maxUntouchedTime'
,
type
=
int
,
default
=
100
,
help
=
'Ends trial if ball is untouched for this long.
\n
'
\
'Negative values mean unlimited. Default: 100.'
)
p
.
add_argument
(
'--offense-agents'
,
dest
=
'offenseAgents'
,
type
=
int
,
default
=
0
,
help
=
'Number of offensive agents. Default: 0.'
)
p
.
add_argument
(
'--defense-agents'
,
dest
=
'defenseAgents'
,
type
=
int
,
default
=
0
,
help
=
'Number of defensive agents. Default: 0.'
)
p
.
add_argument
(
'--offense-npcs'
,
dest
=
'offenseNPCs'
,
type
=
int
,
default
=
0
,
help
=
'Number of offensive uncontrolled players. Default: 0.'
)
p
.
add_argument
(
'--defense-npcs'
,
dest
=
'defenseNPCs'
,
type
=
int
,
default
=
0
,
help
=
'Number of defensive uncontrolled players. Default: 0.'
)
p
.
add_argument
(
'--agent-play-goalie'
,
dest
=
'agentPlayGoalie'
,
action
=
'store_true'
,
default
=
False
,
help
=
'Defense-agent plays goalie, rather than defender.'
)
p
.
add_argument
(
'--offense-team'
,
dest
=
'offenseTeam'
,
type
=
str
,
default
=
'base'
,
help
=
'Offense team binary. Options: '
+
str
(
installed_teams
)
+
'. Default: base.'
)
p
.
add_argument
(
'--defense-team'
,
dest
=
'defenseTeam'
,
type
=
str
,
default
=
'base'
,
help
=
'Defense team binary. Options: '
+
str
(
installed_teams
)
+
'. Default: base.'
)
p
.
add_argument
(
'--no-sync'
,
dest
=
'sync'
,
action
=
'store_false'
,
default
=
True
,
help
=
'Run server in non-sync mode.'
)
p
.
add_argument
(
'--port'
,
dest
=
'port'
,
type
=
int
,
default
=
6000
,
help
=
'Agent server
\'
s port. Default: 6000.
\n
'
\
'rcssserver, coach, and ol_coach will be '
\
'incrementally allocated the following ports.'
)
p
.
add_argument
(
'--no-logging'
,
dest
=
'logging'
,
action
=
'store_false'
,
default
=
True
,
help
=
'Disable rcssserver logging.'
)
p
.
add_argument
(
'--log-dir'
,
dest
=
'logDir'
,
default
=
'log/'
,
help
=
'Directory to store logs. Default: log/'
)
p
.
add_argument
(
'--record'
,
dest
=
'record'
,
action
=
'store_true'
,
help
=
'Record logs of states and actions.'
)
p
.
add_argument
(
'--offense-on-ball'
,
dest
=
'offenseOnBall'
,
type
=
int
,
default
=
0
,
help
=
'Ball given to the player represented by the value.
\n
'
\
'If value greater than the number of offense players, '
\
'ball given to a random offense player.
\n
'
\
'If value non-positive, ball is not given to any player.
\n
'
\
'Default: 0.'
)
p
.
add_argument
(
'--fullstate'
,
dest
=
'fullstate'
,
action
=
'store_true'
,
help
=
'Server provides full-state information to agents.'
)
p
.
add_argument
(
'--seed'
,
dest
=
'seed'
,
type
=
int
,
default
=-
1
,
help
=
'Seed the server
\'
s RNG. Default: time.'
)
p
.
add_argument
(
'--message-size'
,
dest
=
'messageSize'
,
type
=
int
,
default
=
1000
,
help
=
'Message size limit for communication'
)
p
.
add_argument
(
'--ball-x-min'
,
dest
=
'min_ball_x'
,
type
=
float
,
default
=
0.0
,
help
=
'Ball initialization min x position: [0,1]. Default: 0'
)
p
.
add_argument
(
'--ball-x-max'
,
dest
=
'max_ball_x'
,
type
=
float
,
default
=
0.2
,
help
=
'Ball initialization max x position: [0,1]. Default: .2'
)
p
.
add_argument
(
'--verbose'
,
dest
=
'verbose'
,
action
=
'store_true'
,
default
=
False
,
help
=
'Print verbose output.'
)
args
=
p
.
parse_args
()
if
args
.
offenseAgents
not
in
range
(
0
,
11
):
p
.
error
(
'argument --offense-agents: invalid choice: '
\
+
str
(
args
.
offenseAgents
)
+
' (choose from [0-10])'
)
if
args
.
offenseNPCs
not
in
range
(
0
,
11
):
p
.
error
(
'argument --offense-npcs: invalid choice: '
\
+
str
(
args
.
offenseNPCs
)
+
' (choose from [0-10])'
)
if
args
.
defenseAgents
not
in
range
(
0
,
12
):
p
.
error
(
'argument --defense-agents: invalid choice: '
\
+
str
(
args
.
defenseAgents
)
+
' (choose from [0-11])'
)
if
args
.
defenseNPCs
not
in
range
(
0
,
12
):
p
.
error
(
'argument --offense-npcs: invalid choice: '
\
+
str
(
args
.
defenseNPCs
)
+
' (choose from [0-11])'
)
if
args
.
offenseAgents
+
args
.
offenseNPCs
not
in
range
(
1
,
11
):
p
.
error
(
'Offense players (offense-agents + offense-npcs): '
\
'invalid choice: '
+
str
(
args
.
offenseAgents
+
args
.
offenseNPCs
)
+
\
' (choose from [1,10])'
)
if
args
.
defenseAgents
+
args
.
defenseNPCs
not
in
range
(
0
,
12
):
p
.
error
(
'Defense players (defense-agents + defense-npcs): '
\
'invalid choice: '
+
str
(
args
.
defenseAgents
+
args
.
defenseNPCs
)
+
\
' (choose from [0,11])'
)
if
args
.
offenseTeam
not
in
installed_teams
:
p
.
error
(
'Unrecognized offense team: '
+
str
(
args
.
offenseTeam
))
if
args
.
defenseTeam
not
in
installed_teams
:
p
.
error
(
'Unrecognized defense team: '
+
str
(
args
.
defenseTeam
))
if
args
.
agentPlayGoalie
and
args
.
defenseAgents
<=
0
:
p
.
error
(
'You must add a --defense-agent before it can play goalie.'
)
return
args
if
__name__
==
'__main__'
:
main
(
parseArgs
())
example/high_level_custom_agent_py2.py
deleted
100755 → 0
View file @
4a9eea2e
#!/usr/bin/env python
# encoding: utf-8
#MODIFIED#
# First Start the server: $> bin/start.py
import
random
,
threading
,
argparse
import
itertools
try
:
from
hfo
import
*
except
:
print
'Failed to import hfo. To install hfo, in the HFO directory'
\
' run:
\"
pip install .
\"
'
exit
()
params
=
{
'SHT_DST'
:
0.136664020547
,
'SHT_ANG'
:
-
0.747394386098
,
'PASS_ANG'
:
0.464086704478
,
'DRIB_DST'
:
-
0.999052871962
}
def
can_shoot
(
goal_dist
,
goal_angle
):
"""Returns True if if player can have a good shot at goal"""
if
goal_dist
<
params
[
'SHT_DST'
]
and
goal_angle
>
params
[
'SHT_ANG'
]:
return
True
else
:
return
False
def
has_better_pos
(
dist_to_op
,
goal_angle
,
pass_angle
,
curr_goal_angle
):
"""Returns True if teammate is in a better attacking position"""
if
curr_goal_angle
>
goal_angle
or
dist_to_op
<
params
[
'DRIB_DST'
]:
return
False
if
pass_angle
<
params
[
'PASS_ANG'
]:
return
False
return
True
def
can_dribble
(
dist_to_op
):
if
dist_to_op
>
params
[
'DRIB_DST'
]:
return
True
else
:
return
False
def
get_action
(
state
,
hfo_env
,
num_teammates
):
"""Returns the action to be taken by the agent"""
goal_dist
=
float
(
state
[
6
])
goal_op_angle
=
float
(
state
[
8
])
if
can_shoot
(
goal_dist
,
goal_op_angle
):
hfo_env
.
act
(
SHOOT
)
return
for
i
in
range
(
num_teammates
):
teammate_uniform_number
=
state
[
10
+
3
*
num_teammates
+
3
*
i
+
2
]
if
has_better_pos
(
dist_to_op
=
float
(
state
[
10
+
num_teammates
+
i
]),
goal_angle
=
float
(
state
[
10
+
i
]),
pass_angle
=
float
(
state
[
10
+
2
*
num_teammates
+
i
]),
curr_goal_angle
=
goal_op_angle
):
hfo_env
.
act
(
PASS
,
teammate_uniform_number
)
return
if
can_dribble
(
dist_to_op
=
state
[
9
]):
hfo_env
.
act
(
DRIBBLE
)
return
# If nothing can be done pass
hfo_env
.
act
(
PASS
)
def
main
():
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'--port'
,
type
=
int
,
default
=
6000
)
parser
.
add_argument
(
'--numTeammates'
,
type
=
int
,
default
=
0
)
parser
.
add_argument
(
'--numOpponents'
,
type
=
int
,
default
=
1
)
args
=
parser
.
parse_args
()
hfo_env
=
HFOEnvironment
()
hfo_env
.
connectToServer
(
HIGH_LEVEL_FEATURE_SET
,
'bin/teams/base/config/formations-dt'
,
args
.
port
,
'localhost'
,
'base_left'
,
False
)
#itertools.count() counts forever
for
episode
in
itertools
.
count
():
status
=
IN_GAME
count
=
0
while
status
==
IN_GAME
:
state
=
hfo_env
.
getState
()
#print(state)
if
int
(
state
[
5
])
==
1
:
# state[5] is 1 when player has the ball
tmp
=
get_action
(
state
,
hfo_env
,
args
.
numTeammates
)
#print(tmp)
#hfo_env.act(tmp)
else
:
hfo_env
.
act
(
MOVE
)
status
=
hfo_env
.
step
()
#print(status)
if
status
==
SERVER_DOWN
:
hfo_env
.
act
(
QUIT
)
break
if
__name__
==
'__main__'
:
main
()
print
"END"
example/high_level_custom_agent_py3.py
deleted
100755 → 0
View file @
4a9eea2e
#!/usr/bin/env python
# encoding: utf-8
#MODIFIED#
# First Start the server: $> bin/start.py
import
random
,
threading
,
argparse
import
itertools
try
:
from
hfo
import
*
except
:
print
(
'Failed to import hfo. To install hfo, in the HFO directory'
\
' run:
\"
pip install .
\"
'
)
exit
()
params
=
{
'SHT_DST'
:
0.136664020547
,
'SHT_ANG'
:
-
0.747394386098
,
'PASS_ANG'
:
0.464086704478
,
'DRIB_DST'
:
-
0.999052871962
}
def
can_shoot
(
goal_dist
,
goal_angle
):
"""Returns True if if player can have a good shot at goal"""
if
goal_dist
<
params
[
'SHT_DST'
]
and
goal_angle
>
params
[
'SHT_ANG'
]:
return
True
else
:
return
False
def
has_better_pos
(
dist_to_op
,
goal_angle
,
pass_angle
,
curr_goal_angle
):
"""Returns True if teammate is in a better attacking position"""
if
curr_goal_angle
>
goal_angle
or
dist_to_op
<
params
[
'DRIB_DST'
]:
return
False
if
pass_angle
<
params
[
'PASS_ANG'
]:
return
False
return
True
def
can_dribble
(
dist_to_op
):
if
dist_to_op
>
params
[
'DRIB_DST'
]:
return
True
else
:
return
False
def
get_action
(
state
,
hfo_env
,
num_teammates
):
"""Returns the action to be taken by the agent"""
goal_dist
=
float
(
state
[
6
])
goal_op_angle
=
float
(
state
[
8
])
if
can_shoot
(
goal_dist
,
goal_op_angle
):
hfo_env
.
act
(
SHOOT
)
return
for
i
in
range
(
num_teammates
):
teammate_uniform_number
=
state
[
10
+
3
*
num_teammates
+
3
*
i
+
2
]
if
has_better_pos
(
dist_to_op
=
float
(
state
[
10
+
num_teammates
+
i
]),
goal_angle
=
float
(
state
[
10
+
i
]),
pass_angle
=
float
(
state
[
10
+
2
*
num_teammates
+
i
]),
curr_goal_angle
=
goal_op_angle
):
hfo_env
.
act
(
PASS
,
teammate_uniform_number
)
return
if
can_dribble
(
dist_to_op
=
state
[
9
]):
hfo_env
.
act
(
DRIBBLE
)
return
# If nothing can be done pass
hfo_env
.
act
(
PASS
)
def
main
():
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'--port'
,
type
=
int
,
default
=
6000
)
parser
.
add_argument
(
'--numTeammates'
,
type
=
int
,
default
=
0
)
parser
.
add_argument
(
'--numOpponents'
,
type
=
int
,
default
=
1
)
args
=
parser
.
parse_args
()
hfo_env
=
HFOEnvironment
()
hfo_env
.
connectToServer
(
HIGH_LEVEL_FEATURE_SET
,
'bin/teams/base/config/formations-dt'
,
args
.
port
,
'localhost'
,
'base_left'
,
False
)
#itertools.count() counts forever
for
episode
in
itertools
.
count
():
status
=
IN_GAME
count
=
0
while
status
==
IN_GAME
:
state
=
hfo_env
.
getState
()
#print(state)
if
int
(
state
[
5
])
==
1
:
# state[5] is 1 when player has the ball
tmp
=
get_action
(
state
,
hfo_env
,
args
.
numTeammates
)
#print(tmp)
#hfo_env.act(tmp)
else
:
hfo_env
.
act
(
MOVE
)
status
=
hfo_env
.
step
()
#print(status)
if
status
==
SERVER_DOWN
:
hfo_env
.
act
(
QUIT
)
break
if
__name__
==
'__main__'
:
main
()
example/python_agents_3v3.sh
View file @
3275a136
...
@@ -2,9 +2,9 @@
...
@@ -2,9 +2,9 @@
./bin/HFO
--offense-agents
=
2
--defense-npcs
=
3
--offense-npcs
=
1
--trials
20
--headless
&
./bin/HFO
--offense-agents
=
2
--defense-npcs
=
3
--offense-npcs
=
1
--trials
20
--headless
&
sleep
5
sleep
5
/usr/bin/python2.7 ./example/high_level_custom_agent
_py2
.py
--numTeammates
=
2
--numOpponents
=
3
--port
6000 &> agent1.txt &
/usr/bin/python2.7 ./example/high_level_custom_agent.py
--numTeammates
=
2
--numOpponents
=
3
--port
6000 &> agent1.txt &
sleep
5
sleep
5
/usr/bin/python3 ./example/high_level_custom_agent
_py3
.py
--numTeammates
=
2
--numOpponents
=
3
--port
6000 &> agent2.txt &
/usr/bin/python3 ./example/high_level_custom_agent.py
--numTeammates
=
2
--numOpponents
=
3
--port
6000 &> agent2.txt &
# The magic line
# The magic line
# $$ holds the PID for this script
# $$ holds the PID for this script
...
...
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