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
01b5dfe7
You need to sign in or sign up before continuing.
Commit
01b5dfe7
authored
Jun 11, 2015
by
UNiQ10
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added multi-agent support and created example agent for it
parent
ec05756c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
65 additions
and
12 deletions
+65
-12
bin/Trainer.py
bin/Trainer.py
+16
-12
example/example_high_level_random_agent.py
example/example_high_level_random_agent.py
+49
-0
No files found.
bin/Trainer.py
View file @
01b5dfe7
...
...
@@ -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
:
...
...
example/example_high_level_random_agent.py
0 → 100644
View file @
01b5dfe7
#!/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