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
1ca482f1
Commit
1ca482f1
authored
Jun 11, 2015
by
Matthew Hausknecht
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #6 from UNiQ10/test
parents
99adc4a2
01b5dfe7
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
99 additions
and
17 deletions
+99
-17
.gitignore
.gitignore
+17
-0
bin/Trainer.py
bin/Trainer.py
+16
-12
bin/start.py
bin/start.py
+17
-5
example/example_high_level_random_agent.py
example/example_high_level_random_agent.py
+49
-0
No files found.
.gitignore
View file @
1ca482f1
...
...
@@ -52,3 +52,20 @@ docs/_build/
# PyBuilder
target/
# Make files
CMakeCache.txt
Makefile
cmake_install.cmake
CMakeFiles/
# Executeables
bin/agent
bin/sample_coach
bin/sample_player
bin/sample_trainer
example/hfo_example_agent
# Logs
log/
bin/log/
bin/Trainer.py
View file @
1ca482f1
...
...
@@ -78,26 +78,24 @@ class Trainer(object):
self
.
_teams
=
[]
# Team indexes for offensive and defensive teams
self
.
_SP
=
{}
# Sever Parameters. Recieved when connecting to the server.
self
.
_isPlaying
=
False
# Is a game being played?
self
.
_agentPopen
=
None
# Agent's proces
s
self
.
_agentPopen
=
[]
# Agent's processe
s
self
.
initMsgHandlers
()
def
launch_agent
(
self
):
def
launch_agent
(
self
,
player_num
):
"""Launch the learning agent using the start.sh script and return a
DummyPopen for the process.
"""
print
'[Trainer] Launching Agent'
print
'[Trainer] Launching Agent'
+
str
(
player_num
)
if
self
.
_agent_play_offense
:
assert
self
.
_numOffense
>
0
self
.
_agentTeam
=
self
.
_offenseTeam
self
.
_agentNumInt
=
1
if
self
.
_numOffense
==
1
\
else
self
.
_rng
.
randint
(
1
,
self
.
_numOffense
)
self
.
_agentNumInt
=
player_num
+
1
numTeammates
=
self
.
_numOffense
-
1
numOpponents
=
self
.
_numDefense
else
:
assert
self
.
_numDefense
>
0
self
.
_agentTeam
=
self
.
_defenseTeam
self
.
_agentNumInt
=
0
if
self
.
_numDefense
==
1
\
else
self
.
_rng
.
randint
(
0
,
self
.
_numDefense
)
self
.
_agentNumInt
=
player_num
numTeammates
=
self
.
_numOffense
numOpponents
=
self
.
_numDefense
-
1
self
.
_agentNumExt
=
self
.
convertToExtPlayer
(
self
.
_agentTeam
,
...
...
@@ -108,7 +106,7 @@ class Trainer(object):
' --playingOffense
%
i --serverPort
%
i'
\
%
(
self
.
_agentTeam
,
self
.
_agentNumExt
,
self
.
_serverPort
,
self
.
_coachPort
,
self
.
_logDir
,
numTeammates
,
numOpponents
,
self
.
_agent_play_offense
,
self
.
_agentServerPort
)
self
.
_agent_play_offense
,
(
self
.
_agentServerPort
-
player_num
)
)
if
self
.
_record
:
agentCmd
+=
' --record'
agentCmd
=
os
.
path
.
join
(
binary_dir
,
agentCmd
)
...
...
@@ -640,8 +638,14 @@ class Trainer(object):
"""
try
:
if
self
.
_agent
:
self
.
_agentPopen
=
self
.
launch_agent
()
necProcesses
.
append
([
self
.
_agentPopen
,
'agent'
])
if
self
.
_agent_play_offense
:
for
i
in
xrange
(
self
.
_numOffense
):
self
.
_agentPopen
.
append
(
self
.
launch_agent
(
i
))
necProcesses
.
append
([
self
.
_agentPopen
[
i
],
'agent'
+
str
(
i
)])
else
:
for
i
in
xrange
(
self
.
_numDefense
):
self
.
_agentPopen
.
append
(
self
.
launch_agent
(
i
))
necProcesses
.
append
([
self
.
_agentPopen
[
i
],
'agent'
+
str
(
i
)])
self
.
startGame
()
while
self
.
checkLive
(
necProcesses
):
prevFrame
=
self
.
_frame
...
...
@@ -653,8 +657,8 @@ class Trainer(object):
except
(
KeyboardInterrupt
,
DoneError
):
print
'[Trainer] Exiting'
finally
:
if
self
.
_agentPopen
is
not
None
:
self
.
_agentPopen
.
send_signal
(
SIGINT
)
for
p
in
self
.
_agentPopen
:
p
.
send_signal
(
SIGINT
)
try
:
self
.
_comm
.
sendMsg
(
'(bye)'
)
except
:
...
...
bin/start.py
View file @
1ca482f1
...
...
@@ -9,7 +9,7 @@ processes, necProcesses = [], []
# Command to run the rcssserver. Edit as needed.
SERVER_CMD
=
'rcssserver'
# Command to run the monitor. Edit as needed.
MONITOR_CMD
=
'
rcssmonitor
'
MONITOR_CMD
=
'
soccerwindow2
'
def
getAgentDirCmd
(
binary_dir
,
teamname
,
server_port
=
6000
,
coach_port
=
6002
,
logDir
=
'log'
,
record
=
False
):
...
...
@@ -100,7 +100,7 @@ def main(args, team1='left', team2='right', rng=numpy.random.RandomState()):
pass
time
.
sleep
(
0.1
)
def
parseArgs
(
args
=
None
):
def
parseArgs
():
import
argparse
p
=
argparse
.
ArgumentParser
(
description
=
'Start Half Field Offense.'
)
p
.
add_argument
(
'--headless'
,
dest
=
'headless'
,
action
=
'store_true'
,
...
...
@@ -110,9 +110,9 @@ def parseArgs(args=None):
p
.
add_argument
(
'--frames'
,
dest
=
'numFrames'
,
type
=
int
,
default
=-
1
,
help
=
'Number of frames to run for'
)
p
.
add_argument
(
'--offense'
,
dest
=
'numOffense'
,
type
=
int
,
default
=
4
,
choices
=
xrange
(
1
,
11
),
help
=
'Number of offensive players'
)
help
=
'Number of offensive players'
)
p
.
add_argument
(
'--defense'
,
dest
=
'numDefense'
,
type
=
int
,
default
=
4
,
choices
=
xrange
(
0
,
12
),
help
=
'Number of defensive players'
)
help
=
'Number of defensive players'
)
p
.
add_argument
(
'--play-defense'
,
dest
=
'play_offense'
,
action
=
'store_false'
,
default
=
True
,
help
=
'Put the learning agent on defensive team'
)
...
...
@@ -133,7 +133,19 @@ def parseArgs(args=None):
help
=
'Agent starts with the ball.'
)
p
.
add_argument
(
'--fullstate'
,
dest
=
'fullstate'
,
action
=
'store_true'
,
help
=
'Server provides full-state information to agents.'
)
return
p
.
parse_args
(
args
=
args
)
args
=
p
.
parse_args
()
if
args
.
numOffense
not
in
xrange
(
1
,
11
):
p
.
error
(
'argument --offense: invalid choice: '
+
str
(
args
.
numOffense
)
+
' (choose from [1-10])'
)
if
args
.
play_offense
:
if
args
.
numDefense
not
in
xrange
(
0
,
12
):
p
.
error
(
'argument --defense: invalid choice: '
+
str
(
args
.
numDefense
)
+
' (choose from [0-11])'
)
else
:
if
args
.
numDefense
not
in
xrange
(
1
,
12
):
p
.
error
(
'argument --defense: invalid choice: '
+
str
(
args
.
numDefense
)
+
' (choose from [1-11])'
)
return
args
if
__name__
==
'__main__'
:
main
(
parseArgs
())
example/example_high_level_random_agent.py
0 → 100644
View file @
1ca482f1
#!/usr/bin/env python
# encoding: utf-8
# First Start the server: $> bin/start.py
import
random
if
__name__
==
'__main__'
:
try
:
from
hfo
import
*
except
:
print
'Failed to import hfo. To install hfo, in the HFO directory'
\
' run:
\"
pip install .
\"
'
exit
()
# Connect 4 agents
agents
=
[]
for
i
in
xrange
(
4
):
agents
.
append
(
hfo
.
HFOEnvironment
())
agents
[
i
]
.
connectToAgentServer
(
6000
-
i
,
HFO_Features
.
HIGH_LEVEL_FEATURE_SET
)
for
episode
in
xrange
(
5
):
status
=
HFO_Status
.
IN_GAME
while
status
==
HFO_Status
.
IN_GAME
:
# Grab the state features from the environment from the first agent
features
=
agents
[
0
]
.
getState
()
# Take an action and get the current game status
for
agent
in
agents
:
rand_int
=
random
.
randint
(
0
,
3
)
if
rand_int
==
0
:
status
=
agent
.
act
((
HFO_Actions
.
MOVE
,
0
,
0
))
elif
rand_int
==
1
:
status
=
agent
.
act
((
HFO_Actions
.
SHOOT
,
0
,
0
))
elif
rand_int
==
2
:
status
=
agent
.
act
((
HFO_Actions
.
PASS
,
0
,
0
))
elif
rand_int
==
3
:
status
=
agent
.
act
((
HFO_Actions
.
DRIBBLE
,
0
,
0
))
print
'Episode'
,
episode
,
'ended with'
,
# Check what the outcome of the episode was
if
status
==
HFO_Status
.
GOAL
:
print
'goal'
elif
status
==
HFO_Status
.
CAPTURED_BY_DEFENSE
:
print
'captured by defense'
elif
status
==
HFO_Status
.
OUT_OF_BOUNDS
:
print
'out of bounds'
elif
status
==
HFO_Status
.
OUT_OF_TIME
:
print
'out of time'
else
:
print
'Unknown status'
,
status
exit
()
# Cleanup when finished
for
agent
in
agents
:
agent
.
cleanup
()
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