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
e415c173
Commit
e415c173
authored
Oct 13, 2015
by
Matthew Hausknecht
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
took HFO from pr9
parent
63820e45
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
38 deletions
+34
-38
bin/HFO
bin/HFO
+34
-38
No files found.
bin/HFO
View file @
e415c173
...
...
@@ -2,7 +2,6 @@
# encoding: utf-8
import
subprocess
,
os
,
time
,
numpy
,
sys
from
signal
import
SIGKILL
# Global list of all/essential running processes
processes
,
necProcesses
=
[],
[]
...
...
@@ -11,37 +10,26 @@ SERVER_BIN = 'rcssserver'
# Command to run the monitor. Edit as needed.
MONITOR_BIN
=
'soccerwindow2'
def
getAgentDirCmd
(
binary_dir
,
teamname
,
server_port
=
6000
,
coach_port
=
6002
,
logDir
=
'log'
,
record
=
False
):
""" Returns the team name, command, and directory to run a team. """
cmd
=
'start.sh -t
%
s -p
%
i -P
%
i --log-dir
%
s'
%
(
teamname
,
server_port
,
coach_port
,
logDir
)
if
record
:
cmd
+=
' --record'
cmd
=
os
.
path
.
join
(
binary_dir
,
cmd
)
return
teamname
,
cmd
def
launch
(
cmd
,
necessary
=
True
,
supressOutput
=
True
,
name
=
'Unknown'
):
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
)
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
,
team1
=
'left'
,
team2
=
'right'
,
rng
=
numpy
.
random
.
RandomState
()):
"""Sets up the teams, launches the server and monitor, starts the
trainer.
"""Sets up the teams, launches the server and monitor, starts the trainer.
"""
if
args
.
seed
:
print
'[start.py] Seeding RNG with seed: '
,
args
.
seed
...
...
@@ -65,10 +53,6 @@ def main(args, team1='left', team2='right', rng=numpy.random.RandomState()):
args
.
logDir
,
args
.
logDir
,
args
.
sync
,
args
.
fullstate
,
args
.
fullstate
)
team1
,
team1Cmd
=
getAgentDirCmd
(
binary_dir
,
team1
,
server_port
,
coach_port
,
args
.
logDir
,
args
.
record
)
team2
,
team2Cmd
=
getAgentDirCmd
(
binary_dir
,
team2
,
server_port
,
coach_port
,
args
.
logDir
,
args
.
record
)
try
:
# Launch the Server
server
=
launch
(
serverCommand
+
serverOptions
,
name
=
'server'
)
...
...
@@ -85,27 +69,23 @@ def main(args, team1='left', team2='right', rng=numpy.random.RandomState()):
trainer
=
Trainer
(
args
=
args
,
rng
=
rng
,
server_port
=
server_port
,
coach_port
=
coach_port
)
trainer
.
initComm
()
# Start Team1
launch
(
team1Cmd
,
False
)
trainer
.
waitOnTeam
(
True
)
# wait to make sure of team order
# Start Team2
launch
(
team2Cmd
,
False
)
trainer
.
waitOnTeam
(
False
)
# Make sure all players are connected
trainer
.
checkIfAllPlayersConnected
()
trainer
.
setTeams
()
# Run HFO
# Add Team1
trainer
.
addTeam
(
team1
)
# Add Team2
trainer
.
addTeam
(
team2
)
# Run
trainer
.
run
(
necProcesses
)
except
KeyboardInterrupt
:
print
'[start.py] Exiting for CTRL-C'
finally
:
print
'[start.py] Cleaning up server and other processes'
for
p
in
processes
:
for
p
in
reversed
(
processes
)
:
try
:
p
.
send_signal
(
SIGKILL
)
p
.
terminate
()
time
.
sleep
(
0.1
)
p
.
kill
()
except
:
pass
time
.
sleep
(
0.1
)
def
parseArgs
():
import
argparse
...
...
@@ -145,10 +125,26 @@ def parseArgs():
p
.
add_argument
(
'--seed'
,
dest
=
'seed'
,
type
=
int
,
help
=
'Seed the trainer
\'
s RNG. Default: time.'
)
args
=
p
.
parse_args
()
assert
args
.
offenseAgents
+
args
.
offenseNPCs
in
xrange
(
0
,
11
),
\
'Invalid number of offensive players: (choose from [0,10])'
assert
args
.
defenseAgents
+
args
.
defenseNPCs
in
xrange
(
0
,
12
),
\
'Invalid number of defensive players: (choose from [0,11])'
if
args
.
offenseAgents
not
in
xrange
(
0
,
11
):
p
.
error
(
'argument --offense-agents: invalid choice: '
\
+
str
(
args
.
offenseAgents
)
+
' (choose from [0-10])'
)
if
args
.
offenseNPCs
not
in
xrange
(
0
,
11
):
p
.
error
(
'argument --offense-npcs: invalid choice: '
\
+
str
(
args
.
offenseNPCs
)
+
' (choose from [0-10])'
)
if
args
.
defenseAgents
not
in
xrange
(
0
,
12
):
p
.
error
(
'argument --defense-agents: invalid choice: '
\
+
str
(
args
.
defenseAgents
)
+
' (choose from [0-11])'
)
if
args
.
defenseNPCs
not
in
xrange
(
0
,
12
):
p
.
error
(
'argument --offense-npcs: invalid choice: '
\
+
str
(
args
.
defenseNPCs
)
+
' (choose from [0-11])'
)
if
args
.
offenseAgents
+
args
.
offenseNPCs
not
in
xrange
(
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
xrange
(
0
,
12
):
p
.
error
(
'Defense players (defense-agents + defense-npcs): '
\
'invalid choice: '
+
str
(
args
.
defenseAgents
+
args
.
defenseNPCs
)
+
\
' (choose from [0,11])'
)
return
args
if
__name__
==
'__main__'
:
...
...
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