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
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
Hide 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):
...
@@ -78,26 +78,24 @@ class Trainer(object):
self
.
_teams
=
[]
# Team indexes for offensive and defensive teams
self
.
_teams
=
[]
# Team indexes for offensive and defensive teams
self
.
_SP
=
{}
# Sever Parameters. Recieved when connecting to the server.
self
.
_SP
=
{}
# Sever Parameters. Recieved when connecting to the server.
self
.
_isPlaying
=
False
# Is a game being played?
self
.
_isPlaying
=
False
# Is a game being played?
self
.
_agentPopen
=
None
# Agent's proces
s
self
.
_agentPopen
=
[]
# Agent's processe
s
self
.
initMsgHandlers
()
self
.
initMsgHandlers
()
def
launch_agent
(
self
):
def
launch_agent
(
self
,
player_num
):
"""Launch the learning agent using the start.sh script and return a
"""Launch the learning agent using the start.sh script and return a
DummyPopen for the process.
DummyPopen for the process.
"""
"""
print
'[Trainer] Launching Agent'
print
'[Trainer] Launching Agent'
+
str
(
player_num
)
if
self
.
_agent_play_offense
:
if
self
.
_agent_play_offense
:
assert
self
.
_numOffense
>
0
assert
self
.
_numOffense
>
0
self
.
_agentTeam
=
self
.
_offenseTeam
self
.
_agentTeam
=
self
.
_offenseTeam
self
.
_agentNumInt
=
1
if
self
.
_numOffense
==
1
\
self
.
_agentNumInt
=
player_num
+
1
else
self
.
_rng
.
randint
(
1
,
self
.
_numOffense
)
numTeammates
=
self
.
_numOffense
-
1
numTeammates
=
self
.
_numOffense
-
1
numOpponents
=
self
.
_numDefense
numOpponents
=
self
.
_numDefense
else
:
else
:
assert
self
.
_numDefense
>
0
assert
self
.
_numDefense
>
0
self
.
_agentTeam
=
self
.
_defenseTeam
self
.
_agentTeam
=
self
.
_defenseTeam
self
.
_agentNumInt
=
0
if
self
.
_numDefense
==
1
\
self
.
_agentNumInt
=
player_num
else
self
.
_rng
.
randint
(
0
,
self
.
_numDefense
)
numTeammates
=
self
.
_numOffense
numTeammates
=
self
.
_numOffense
numOpponents
=
self
.
_numDefense
-
1
numOpponents
=
self
.
_numDefense
-
1
self
.
_agentNumExt
=
self
.
convertToExtPlayer
(
self
.
_agentTeam
,
self
.
_agentNumExt
=
self
.
convertToExtPlayer
(
self
.
_agentTeam
,
...
@@ -108,7 +106,7 @@ class Trainer(object):
...
@@ -108,7 +106,7 @@ class Trainer(object):
' --playingOffense
%
i --serverPort
%
i'
\
' --playingOffense
%
i --serverPort
%
i'
\
%
(
self
.
_agentTeam
,
self
.
_agentNumExt
,
self
.
_serverPort
,
%
(
self
.
_agentTeam
,
self
.
_agentNumExt
,
self
.
_serverPort
,
self
.
_coachPort
,
self
.
_logDir
,
numTeammates
,
numOpponents
,
self
.
_coachPort
,
self
.
_logDir
,
numTeammates
,
numOpponents
,
self
.
_agent_play_offense
,
self
.
_agentServerPort
)
self
.
_agent_play_offense
,
(
self
.
_agentServerPort
-
player_num
)
)
if
self
.
_record
:
if
self
.
_record
:
agentCmd
+=
' --record'
agentCmd
+=
' --record'
agentCmd
=
os
.
path
.
join
(
binary_dir
,
agentCmd
)
agentCmd
=
os
.
path
.
join
(
binary_dir
,
agentCmd
)
...
@@ -640,8 +638,14 @@ class Trainer(object):
...
@@ -640,8 +638,14 @@ class Trainer(object):
"""
"""
try
:
try
:
if
self
.
_agent
:
if
self
.
_agent
:
self
.
_agentPopen
=
self
.
launch_agent
()
if
self
.
_agent_play_offense
:
necProcesses
.
append
([
self
.
_agentPopen
,
'agent'
])
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
()
self
.
startGame
()
while
self
.
checkLive
(
necProcesses
):
while
self
.
checkLive
(
necProcesses
):
prevFrame
=
self
.
_frame
prevFrame
=
self
.
_frame
...
@@ -653,8 +657,8 @@ class Trainer(object):
...
@@ -653,8 +657,8 @@ class Trainer(object):
except
(
KeyboardInterrupt
,
DoneError
):
except
(
KeyboardInterrupt
,
DoneError
):
print
'[Trainer] Exiting'
print
'[Trainer] Exiting'
finally
:
finally
:
if
self
.
_agentPopen
is
not
None
:
for
p
in
self
.
_agentPopen
:
self
.
_agentPopen
.
send_signal
(
SIGINT
)
p
.
send_signal
(
SIGINT
)
try
:
try
:
self
.
_comm
.
sendMsg
(
'(bye)'
)
self
.
_comm
.
sendMsg
(
'(bye)'
)
except
:
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