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
09fe6e7e
Commit
09fe6e7e
authored
May 30, 2017
by
Matthew Hausknecht
Committed by
GitHub
May 30, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #25 from DurgeshSamant/master
Python3-port
parents
eb26f8fc
350bdb69
Changes
12
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
168 additions
and
64 deletions
+168
-64
.travis.yml
.travis.yml
+2
-2
bin/Communicator.py
bin/Communicator.py
+5
-5
bin/HFO
bin/HFO
+8
-8
bin/Teams.py
bin/Teams.py
+2
-2
bin/Trainer.py
bin/Trainer.py
+32
-32
example/communication_agent.py
example/communication_agent.py
+2
-2
example/hfo_example_agent.py
example/hfo_example_agent.py
+1
-1
example/high_level_custom_agent.py
example/high_level_custom_agent.py
+93
-0
example/high_level_random_agent.py
example/high_level_random_agent.py
+1
-1
example/python_agents_3v3.sh
example/python_agents_3v3.sh
+13
-0
hfo/hfo.py
hfo/hfo.py
+8
-10
setup.py
setup.py
+1
-1
No files found.
.travis.yml
View file @
09fe6e7e
...
...
@@ -11,7 +11,7 @@ addons:
-
libboost-filesystem-dev
install
:
-
if [ "${TRAVIS_OS_NAME}" = "osx" ]; then
brew install
qt
brew install
cartr/qt4/qt
;
fi
os
:
...
...
bin/Communicator.py
View file @
09fe6e7e
...
...
@@ -9,7 +9,7 @@ Modified: 2010-11-07
'''
import
socket
,
sys
,
time
import
cP
ickle
as
pickle
import
p
ickle
as
pickle
defaultPort
=
5557
...
...
@@ -43,7 +43,7 @@ class Communicator(object):
def
sendMsg
(
self
,
msg
):
#print 'sending',msg
self
.
_sock
.
sendto
(
msg
+
'
\0
'
,
self
.
_addr
)
self
.
_sock
.
sendto
(
(
msg
+
'
\0
'
)
.
encode
(
'utf-8'
)
,
self
.
_addr
)
def
recvMsg
(
self
,
event
=
None
,
retryCount
=
None
):
msg
=
self
.
_storedMsg
...
...
@@ -53,7 +53,7 @@ class Communicator(object):
newMsg
=
''
try
:
newMsg
,
self
.
_addr
=
self
.
_sock
.
recvfrom
(
8192
)
msg
+=
newMsg
msg
+=
newMsg
.
decode
(
'utf-8'
)
except
socket
.
error
:
#time.sleep(0.1)
pass
...
...
@@ -62,7 +62,7 @@ class Communicator(object):
raise
TimeoutError
else
:
retryCount
-=
1
print
'[Trainer] waiting for message, retry ='
,
retryCount
print
(
'[Trainer] waiting for message, retry ='
,
retryCount
)
time
.
sleep
(
0.3
)
#raise ValueError('Error while receiving message')
(
msg
,
sep
,
rest
)
=
msg
.
partition
(
'
\0
'
)
...
...
@@ -88,5 +88,5 @@ class ClientCommunicator(Communicator):
self
.
_sock
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_DGRAM
)
self
.
_sock
.
settimeout
(
5
)
except
:
print
>>
sys
.
stderr
,
'Error creating socket'
sys
.
stderr
.
write
(
'Error creating socket'
)
raise
bin/HFO
View file @
09fe6e7e
...
...
@@ -84,9 +84,9 @@ def main(args):
# Run
trainer
.
run
(
necProcesses
,
args
.
offenseTeam
,
args
.
defenseTeam
)
except
KeyboardInterrupt
:
print
'[start.py] Exiting for CTRL-C'
print
(
'[start.py] Exiting for CTRL-C'
)
finally
:
print
'[start.py] Cleaning up server and other processes'
print
(
'[start.py] Cleaning up server and other processes'
)
for
p
in
reversed
(
processes
):
try
:
p
.
terminate
()
...
...
@@ -160,23 +160,23 @@ def parseArgs():
p
.
add_argument
(
'--verbose'
,
dest
=
'verbose'
,
action
=
'store_true'
,
default
=
False
,
help
=
'Print verbose output.'
)
args
=
p
.
parse_args
()
if
args
.
offenseAgents
not
in
xrange
(
0
,
11
):
if
args
.
offenseAgents
not
in
list
(
range
(
0
,
11
)
):
p
.
error
(
'argument --offense-agents: invalid choice: '
\
+
str
(
args
.
offenseAgents
)
+
' (choose from [0-10])'
)
if
args
.
offenseNPCs
not
in
xrange
(
0
,
11
):
if
args
.
offenseNPCs
not
in
list
(
range
(
0
,
11
)
):
p
.
error
(
'argument --offense-npcs: invalid choice: '
\
+
str
(
args
.
offenseNPCs
)
+
' (choose from [0-10])'
)
if
args
.
defenseAgents
not
in
xrange
(
0
,
12
):
if
args
.
defenseAgents
not
in
list
(
range
(
0
,
12
)
):
p
.
error
(
'argument --defense-agents: invalid choice: '
\
+
str
(
args
.
defenseAgents
)
+
' (choose from [0-11])'
)
if
args
.
defenseNPCs
not
in
xrange
(
0
,
12
):
if
args
.
defenseNPCs
not
in
list
(
range
(
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
):
if
args
.
offenseAgents
+
args
.
offenseNPCs
not
in
list
(
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
xrange
(
0
,
12
):
if
args
.
defenseAgents
+
args
.
defenseNPCs
not
in
list
(
range
(
0
,
12
)
):
p
.
error
(
'Defense players (defense-agents + defense-npcs): '
\
'invalid choice: '
+
str
(
args
.
defenseAgents
+
args
.
defenseNPCs
)
+
\
' (choose from [0,11])'
)
...
...
bin/Teams.py
View file @
09fe6e7e
...
...
@@ -71,7 +71,7 @@ class Agent2d(Team):
launchOpts
=
None
if
player_num
==
1
:
launchOpts
=
'-g'
print
'Launch npc
%
s-
%
d'
%
(
self
.
_name
,
player_num
)
print
(
'Launch npc
%
s-
%
d'
%
(
self
.
_name
,
player_num
)
)
return
self
.
start_npc_proc
(
launchOpts
)
...
...
@@ -99,5 +99,5 @@ class Helios(Team):
launchOpts
=
None
if
player_num
==
1
:
launchOpts
=
'-g'
print
'Launch npc
%
s-
%
d'
%
(
self
.
_name
,
player_num
)
print
(
'Launch npc
%
s-
%
d'
%
(
self
.
_name
,
player_num
)
)
return
self
.
start_npc_proc
(
launchOpts
)
bin/Trainer.py
View file @
09fe6e7e
...
...
@@ -72,11 +72,11 @@ class Trainer(object):
binary_dir
=
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
)),
'teams'
,
'base'
)
config_dir
=
os
.
path
.
join
(
binary_dir
,
'config/formations-dt'
)
print
(
"Waiting for player-controlled agent
%
s-
%
d: config_dir=
%
s, "
\
print
(
(
"Waiting for player-controlled agent
%
s-
%
d: config_dir=
%
s, "
\
"server_port=
%
d, server_addr=
%
s, team_name=
%
s, play_goalie=
%
r"
%
(
self
.
_offenseTeamName
if
play_offense
else
self
.
_defenseTeamName
,
agent_num
,
config_dir
,
self
.
_serverPort
,
"localhost"
,
team_name
,
agent_ext_num
==
1
))
agent_ext_num
==
1
))
)
if
wait_until_join
:
self
.
waitOnPlayer
(
agent_ext_num
,
play_offense
)
return
None
...
...
@@ -85,7 +85,7 @@ class Trainer(object):
""" Given a team name, returns the team object. """
teams_dir
=
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
)),
'teams'
)
if
requested_team_name
==
'helios'
:
print
'Creating team Helios'
print
(
'Creating team Helios'
)
team_name
=
'HELIOS_'
+
(
'left'
if
play_offense
else
'right'
)
team_dir
=
os
.
path
.
join
(
teams_dir
,
'helios'
,
'helios-13Eindhoven'
)
lib_dir
=
os
.
path
.
join
(
teams_dir
,
'helios'
,
'local'
,
'lib'
)
...
...
@@ -93,7 +93,7 @@ class Trainer(object):
binaryName
=
'helios_player'
,
host
=
'localhost'
,
port
=
self
.
_serverPort
)
elif
requested_team_name
==
'base'
:
print
'Creating team Agent2d (base)'
print
(
'Creating team Agent2d (base)'
)
team_name
=
'base_'
+
(
'left'
if
play_offense
else
'right'
)
team_dir
=
os
.
path
.
join
(
teams_dir
,
'base'
)
lib_dir
=
None
...
...
@@ -102,7 +102,7 @@ class Trainer(object):
record
=
self
.
_record
,
host
=
'localhost'
,
port
=
self
.
_serverPort
)
else
:
print
'Unknown team requested: '
+
requested_team_name
print
(
'Unknown team requested: '
+
requested_team_name
)
sys
.
exit
(
1
)
def
getTeams
(
self
,
offense_team_name
,
defense_team_name
):
...
...
@@ -179,8 +179,8 @@ class Trainer(object):
self
.
_done
=
True
if
endOfTrial
:
self
.
_numTrials
+=
1
print
'EndOfTrial:
%
d /
%
d
%
d
%
s'
%
\
(
self
.
_numGoals
,
self
.
_numTrials
,
self
.
_frame
,
event
)
print
(
'EndOfTrial:
%
d /
%
d
%
d
%
s'
%
\
(
self
.
_numGoals
,
self
.
_numTrials
,
self
.
_frame
,
event
)
)
self
.
_numFrames
+=
self
.
_frame
-
self
.
_lastTrialStart
self
.
_lastTrialStart
=
self
.
_frame
self
.
getConnectedPlayers
()
...
...
@@ -199,16 +199,16 @@ class Trainer(object):
msg
=
msg
[
1
:
length
+
1
]
if
msg
==
'START'
:
if
self
.
_isPlaying
:
print
'Already playing, ignoring message'
print
(
'Already playing, ignoring message'
)
else
:
self
.
startGame
()
elif
msg
==
'DONE'
:
raise
DoneError
elif
msg
==
'ready'
:
print
'Agent Connected:'
,
team
,
player
print
(
'Agent Connected:'
,
team
,
player
)
self
.
_agentReady
.
add
((
team
,
player
))
else
:
print
'Unhandled message from agent:
%
s'
%
msg
print
(
'Unhandled message from agent:
%
s'
%
msg
)
def
initMsgHandlers
(
self
):
""" Create handlers for different messages. """
...
...
@@ -235,9 +235,9 @@ class Trainer(object):
""" Check that the next message is same as expected message. """
msg
=
self
.
recv
(
retryCount
)
if
msg
!=
expectedMsg
:
print
>>
sys
.
stderr
,
'Error with message'
print
>>
sys
.
stderr
,
' expected:
%
s'
%
expectedMsg
print
>>
sys
.
stderr
,
' received:
%
s'
%
msg
sys
.
stderr
.
write
(
'Error with message'
)
sys
.
stderr
.
write
(
' expected: '
+
expectedMsg
)
sys
.
stderr
.
write
(
' received: '
+
msg
)
# print >>sys.stderr,len(expectedMsg),len(msg)
raise
ValueError
...
...
@@ -263,7 +263,7 @@ class Trainer(object):
self
.
_msgHandlers
.
append
([
args
,
handler
])
else
:
if
(
'quiet'
not
in
kwargs
)
or
(
not
kwargs
[
'quiet'
]):
print
'Updating handler for
%
s'
%
(
' '
.
join
(
args
))
print
(
'Updating handler for
%
s'
%
(
' '
.
join
(
args
)
))
self
.
_msgHandlers
[
i
]
=
[
args
,
handler
]
def
unregisterMsgHandler
(
self
,
*
args
):
...
...
@@ -285,7 +285,7 @@ class Trainer(object):
""" Handle a message using the registered handlers. """
i
,
prefixLength
,
handler
=
self
.
_findHandlerInd
(
msg
)
if
i
<
0
:
print
'Unhandled message:'
,
msg
[
0
:
2
]
print
(
'Unhandled message:'
,
msg
[
0
:
2
])
else
:
handler
(
msg
[
prefixLength
:])
...
...
@@ -319,7 +319,7 @@ class Trainer(object):
def
f
(
body
):
self
.
_gotLook
=
True
del
self
.
_connectedPlayers
[:]
for
i
in
x
range
(
4
,
len
(
body
)):
for
i
in
range
(
4
,
len
(
body
)):
_
,
team
,
num
=
body
[
i
][
0
][:
3
]
if
(
team
,
num
)
not
in
self
.
_connectedPlayers
:
self
.
_connectedPlayers
.
append
((
team
,
num
))
...
...
@@ -342,9 +342,9 @@ class Trainer(object):
def
sendHFOConfig
(
self
):
""" Broadcast the HFO configuration """
offense_nums
=
' '
.
join
([
str
(
self
.
convertToExtPlayer
(
self
.
_offenseTeamName
,
i
))
for
i
in
x
range
(
1
,
self
.
_numOffense
+
1
)])
for
i
in
range
(
1
,
self
.
_numOffense
+
1
)])
defense_nums
=
' '
.
join
([
str
(
self
.
convertToExtPlayer
(
self
.
_defenseTeamName
,
i
))
for
i
in
x
range
(
self
.
_numDefense
)])
for
i
in
range
(
self
.
_numDefense
)])
self
.
send
(
'(say HFO_SETUP offense_name
%
s defense_name
%
s num_offense
%
d'
\
' num_defense
%
d offense_nums
%
s defense_nums
%
s)'
%
(
self
.
_offenseTeamName
,
self
.
_defenseTeamName
,
...
...
@@ -357,15 +357,15 @@ class Trainer(object):
self
.
_isPlaying
=
True
def
printStats
(
self
):
print
'TotalFrames =
%
i, AvgFramesPerTrial =
%.1
f, AvgFramesPerGoal =
%.1
f'
\
print
(
'TotalFrames =
%
i, AvgFramesPerTrial =
%.1
f, AvgFramesPerGoal =
%.1
f'
\
%
(
self
.
_numFrames
,
self
.
_numFrames
/
float
(
self
.
_numTrials
)
if
self
.
_numTrials
>
0
else
float
(
'nan'
),
self
.
_numGoalFrames
/
float
(
self
.
_numGoals
)
if
self
.
_numGoals
>
0
else
float
(
'nan'
))
print
'Trials :
%
i'
%
self
.
_numTrials
print
'Goals :
%
i'
%
self
.
_numGoals
print
'Defense Captured :
%
i'
%
self
.
_numBallsCaptured
print
'Balls Out of Bounds:
%
i'
%
self
.
_numBallsOOB
print
'Out of Time :
%
i'
%
self
.
_numOutOfTime
self
.
_numGoalFrames
/
float
(
self
.
_numGoals
)
if
self
.
_numGoals
>
0
else
float
(
'nan'
))
)
print
(
'Trials :
%
i'
%
self
.
_numTrials
)
print
(
'Goals :
%
i'
%
self
.
_numGoals
)
print
(
'Defense Captured :
%
i'
%
self
.
_numBallsCaptured
)
print
(
'Balls Out of Bounds:
%
i'
%
self
.
_numBallsOOB
)
print
(
'Out of Time :
%
i'
%
self
.
_numOutOfTime
)
def
checkLive
(
self
,
necProcesses
):
"""Returns true if each of the necessary processes is still alive and
...
...
@@ -374,7 +374,7 @@ class Trainer(object):
"""
for
p
,
name
in
necProcesses
:
if
p
is
not
None
and
p
.
poll
()
is
not
None
:
print
'Something necessary closed (
%
s), exiting'
%
name
print
(
'Something necessary closed (
%
s), exiting'
%
name
)
return
False
return
True
...
...
@@ -391,7 +391,7 @@ class Trainer(object):
# Launch offense
agent_num
=
0
for
player_num
in
x
range
(
1
,
12
):
for
player_num
in
range
(
1
,
12
):
if
agent_num
<
self
.
_offenseAgents
and
player_num
==
sorted_offense_agent_unums
[
agent_num
]:
port
=
self
.
_agentServerPort
+
agent_num
agent
=
self
.
launch_agent
(
agent_num
,
sorted_offense_agent_unums
[
agent_num
],
...
...
@@ -410,7 +410,7 @@ class Trainer(object):
# Launch defense
agent_num
=
0
for
player_num
in
x
range
(
1
,
12
):
for
player_num
in
range
(
1
,
12
):
if
agent_num
<
self
.
_defenseAgents
and
player_num
==
sorted_defense_agent_unums
[
agent_num
]:
port
=
self
.
_agentServerPort
+
agent_num
+
self
.
_offenseAgents
agent
=
self
.
launch_agent
(
agent_num
,
sorted_defense_agent_unums
[
agent_num
],
...
...
@@ -427,23 +427,23 @@ class Trainer(object):
else
:
self
.
disconnectPlayer
(
player
,
player_num
,
on_offense
=
False
)
print
'Checking all players connected'
print
(
'Checking all players connected'
)
while
not
self
.
allPlayersConnected
():
self
.
getConnectedPlayers
()
time
.
sleep
(
0.1
)
self
.
sendHFOConfig
()
print
'Starting game'
print
(
'Starting game'
)
time
.
sleep
(
0.1
)
self
.
startGame
()
while
self
.
allPlayersConnected
()
and
self
.
checkLive
(
necProcesses
)
and
not
self
.
_done
:
prevFrame
=
self
.
_frame
self
.
listenAndProcess
()
except
TimeoutError
:
print
'Haven
\'
t heard from the server for too long, Exiting'
print
(
'Haven
\'
t heard from the server for too long, Exiting'
)
except
(
KeyboardInterrupt
,
DoneError
):
print
'Finished'
print
(
'Finished'
)
finally
:
try
:
self
.
_comm
.
sendMsg
(
'(bye)'
)
...
...
example/communication_agent.py
View file @
09fe6e7e
...
...
@@ -24,7 +24,7 @@ def main():
msg
=
hfo
.
hear
()
# Print the incoming communication
if
msg
:
print
(
'Heard:
%
s'
%
msg
)
print
(
(
'Heard:
%
s'
%
msg
)
)
# Take an action
hfo
.
act
(
DASH
,
20.0
,
0.
)
# Create outgoing communication
...
...
@@ -32,7 +32,7 @@ def main():
# Advance the environment and get the game status
status
=
hfo
.
step
()
# Check the outcome of the episode
print
(
'Episode
%
d ended with
%
s'
%
(
episode
,
hfo
.
statusToString
(
status
)))
print
(
(
'Episode
%
d ended with
%
s'
%
(
episode
,
hfo
.
statusToString
(
status
)
)))
# Quit if the server goes down
if
status
==
SERVER_DOWN
:
hfo
.
act
(
QUIT
)
...
...
example/hfo_example_agent.py
View file @
09fe6e7e
...
...
@@ -25,7 +25,7 @@ def main():
# Advance the environment and get the game status
status
=
hfo
.
step
()
# Check the outcome of the episode
print
(
'Episode
%
d ended with
%
s'
%
(
episode
,
hfo
.
statusToString
(
status
)))
print
(
(
'Episode
%
d ended with
%
s'
%
(
episode
,
hfo
.
statusToString
(
status
)
)))
# Quit if the server goes down
if
status
==
SERVER_DOWN
:
hfo
.
act
(
QUIT
)
...
...
example/high_level_custom_agent.py
0 → 100755
View file @
09fe6e7e
#!/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/high_level_random_agent.py
View file @
09fe6e7e
...
...
@@ -28,7 +28,7 @@ def main():
# Advance the environment and get the game status
status
=
hfo
.
step
()
# Check the outcome of the episode
print
(
'Episode
%
d ended with
%
s'
%
(
episode
,
hfo
.
statusToString
(
status
)))
print
(
(
'Episode
%
d ended with
%
s'
%
(
episode
,
hfo
.
statusToString
(
status
)
)))
# Quit if the server goes down
if
status
==
SERVER_DOWN
:
hfo
.
act
(
QUIT
)
...
...
example/python_agents_3v3.sh
0 → 100755
View file @
09fe6e7e
#!/bin/bash
./bin/HFO
--offense-agents
=
2
--defense-npcs
=
3
--offense-npcs
=
1
--trials
20
--headless
&
sleep
5
/usr/bin/python2.7 ./example/high_level_custom_agent.py
--numTeammates
=
2
--numOpponents
=
3
--port
6000 &> agent1.txt &
sleep
5
/usr/bin/python3 ./example/high_level_custom_agent.py
--numTeammates
=
2
--numOpponents
=
3
--port
6000 &> agent2.txt &
# The magic line
# $$ holds the PID for this script
# Negation means kill by process group id instead of PID
trap
"kill -TERM -
$$
"
SIGINT
wait
hfo/hfo.py
View file @
09fe6e7e
...
...
@@ -7,7 +7,7 @@ hfo_lib = cdll.LoadLibrary(os.path.join(os.path.dirname(__file__),
'libhfo_c.so'
))
''' Possible feature sets '''
LOW_LEVEL_FEATURE_SET
,
HIGH_LEVEL_FEATURE_SET
=
range
(
2
)
LOW_LEVEL_FEATURE_SET
,
HIGH_LEVEL_FEATURE_SET
=
list
(
range
(
2
)
)
''' An enum of the possible HFO actions
[Low-Level] Dash(power, relative_direction)
...
...
@@ -26,7 +26,7 @@ LOW_LEVEL_FEATURE_SET, HIGH_LEVEL_FEATURE_SET = range(2)
NOOP(): Do Nothing
QUIT(): Quit the game '''
DASH
,
TURN
,
TACKLE
,
KICK
,
KICK_TO
,
MOVE_TO
,
DRIBBLE_TO
,
INTERCEPT
,
\
MOVE
,
SHOOT
,
PASS
,
DRIBBLE
,
CATCH
,
NOOP
,
QUIT
,
REDUCE_ANGLE_TO_GOAL
,
MARK_PLAYER
,
DEFEND_GOAL
,
GO_TO_BALL
=
range
(
19
)
MOVE
,
SHOOT
,
PASS
,
DRIBBLE
,
CATCH
,
NOOP
,
QUIT
,
REDUCE_ANGLE_TO_GOAL
,
MARK_PLAYER
,
DEFEND_GOAL
,
GO_TO_BALL
=
list
(
range
(
19
)
)
''' Possible game status
[IN_GAME] Game is currently active
...
...
@@ -36,10 +36,10 @@ DASH, TURN, TACKLE, KICK, KICK_TO, MOVE_TO, DRIBBLE_TO, INTERCEPT, \
[OUT_OF_TIME] Trial has ended due to time limit
[SERVER_DOWN] Server is not alive
'''
IN_GAME
,
GOAL
,
CAPTURED_BY_DEFENSE
,
OUT_OF_BOUNDS
,
OUT_OF_TIME
,
SERVER_DOWN
=
range
(
6
)
IN_GAME
,
GOAL
,
CAPTURED_BY_DEFENSE
,
OUT_OF_BOUNDS
,
OUT_OF_TIME
,
SERVER_DOWN
=
list
(
range
(
6
)
)
''' Possible sides '''
RIGHT
,
NEUTRAL
,
LEFT
=
range
(
-
1
,
2
)
RIGHT
,
NEUTRAL
,
LEFT
=
list
(
range
(
-
1
,
2
)
)
class
Player
(
Structure
):
pass
Player
.
_fields_
=
[
...
...
@@ -104,9 +104,7 @@ class HFOEnvironment(object):
play_goalie: is this player the goalie
record_dir: record agent's states/actions/rewards to this directory
"""
hfo_lib
.
connectToServer
(
self
.
obj
,
feature_set
,
config_dir
,
server_port
,
server_addr
,
team_name
,
play_goalie
,
record_dir
)
hfo_lib
.
connectToServer
(
self
.
obj
,
feature_set
,
config_dir
.
encode
(
'utf-8'
),
server_port
,
server_addr
.
encode
(
'utf-8'
),
team_name
.
encode
(
'utf-8'
),
play_goalie
,
record_dir
.
encode
(
'utf-8'
))
def
getStateSize
(
self
):
""" Returns the number of state features """
return
hfo_lib
.
getStateSize
(
self
.
obj
)
...
...
@@ -130,11 +128,11 @@ class HFOEnvironment(object):
def
say
(
self
,
message
):
""" Transmit a message """
hfo_lib
.
say
(
self
.
obj
,
message
)
hfo_lib
.
say
(
self
.
obj
,
message
.
encode
(
'utf-8'
)
)
def
hear
(
self
):
""" Returns the message heard from another player """
return
hfo_lib
.
hear
(
self
.
obj
)
return
hfo_lib
.
hear
(
self
.
obj
)
.
decode
(
'utf-8'
)
def
playerOnBall
(
self
):
""" Returns a player object who last touched the ball """
...
...
@@ -146,7 +144,7 @@ class HFOEnvironment(object):
def
actionToString
(
self
,
action
):
""" Returns a string representation of an action """
return
hfo_lib
.
actionToString
(
action
)
return
hfo_lib
.
actionToString
(
action
.
decode
(
'utf-8'
)
)
def
statusToString
(
self
,
status
):
""" Returns a string representation of a game status """
...
...
setup.py
View file @
09fe6e7e
...
...
@@ -3,7 +3,7 @@ import os.path, sys
hfo_c_lib
=
'hfo/libhfo_c.so'
if
not
os
.
path
.
isfile
(
hfo_c_lib
):
print
(
'ERROR: Unable to find required library:
%
s.'
%
(
hfo_c_lib
))
print
(
(
'ERROR: Unable to find required library:
%
s.'
%
(
hfo_c_lib
)
))
sys
.
exit
()
module1
=
Extension
(
'hfo.hfo_c_wrapper'
,
...
...
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