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
fdef3ceb
You need to sign in or sign up before continuing.
Commit
fdef3ceb
authored
Mar 06, 2015
by
Matthew Hausknecht
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added example python agent.
parent
2598397e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
29 deletions
+23
-29
HFO.py
HFO.py
+2
-29
README.md
README.md
+1
-0
example/agent.py
example/agent.py
+20
-0
No files found.
HFO.py
View file @
fdef3ceb
import
socket
,
struct
,
thread
,
time
class
HFOEnvironment
(
object
):
'''The HFOEnvironment is designed to be the
single
point of contact
'''The HFOEnvironment is designed to be the
main
point of contact
between a learning agent and the Half-Field-Offense domain.
'''
...
...
@@ -9,24 +9,8 @@ class HFOEnvironment(object):
def
__init__
(
self
):
self
.
socket
=
None
# Socket connection to server
self
.
numFeatures
=
None
# Given by the server in handshake
self
.
trainerThreadID
=
None
# Thread of the trainer process
self
.
actions
=
[
'DASH'
,
'TURN'
,
'TACKLE'
,
'KICK'
]
def
startDomain
(
self
,
args
=
[]):
'''Covenience method to start the HFO domain by calling the
/bin/start.py script and providing it kwargs. Call this method
before connectToAgentServer.
args: a list of argument strings passed to the start script.
(e.g. ['--offense','3']). See ./bin/start.py -h for all args.
'''
# This method calls the trainer in bin directory
def
runTrainer
():
from
bin
import
start
start
.
main
(
start
.
parseArgs
(
args
))
self
.
trainerThreadID
=
thread
.
start_new_thread
(
runTrainer
,())
time
.
sleep
(
2
)
def
connectToAgentServer
(
self
,
server_port
=
6008
):
'''Connect to the server that controls the agent on the specified port. '''
self
.
socket
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
...
...
@@ -72,20 +56,9 @@ class HFOEnvironment(object):
def
act
(
self
,
action_number
):
''' Send an action and recieve the resulting reward from the environment.'''
self
.
socket
.
send
(
struct
.
pack
(
"i"
,
action_number
))
# TODO: Get the rewards from the domain
return
0
def
cleanup
(
self
):
''' Close the connection to the agent's server. '''
self
.
socket
.
close
()
if
self
.
trainerThreadID
is
not
None
:
thread
.
interrupt_main
()
if
__name__
==
'__main__'
:
hfo
=
HFOEnvironment
()
trainer_args
=
'--offense 1 --defense 0 --headless'
.
split
(
' '
)
hfo
.
startDomain
(
trainer_args
)
hfo
.
connectToAgentServer
()
while
True
:
features
=
hfo
.
getState
()
reward
=
hfo
.
act
(
0
)
hfo
.
cleanup
()
README.md
View file @
fdef3ceb
...
...
@@ -10,6 +10,7 @@ HFO
-
Only run single-threaded make. Multi-threaded make (eg
`make -j4`
) fails.
-
[
librcsc-4.1.0
](
http://en.sourceforge.jp/projects/rctools/downloads/51941/librcsc-4.1.0.tar.gz/
)
-
[
soccerwindow2-5.1.0
](
http://en.sourceforge.jp/projects/rctools/downloads/51942/soccerwindow2-5.1.0.tar.gz/
)
(
Optional
)
-
If -laudio is not found during make, it can be safely removed from the link command.
## Install
1.
Edit the
`LIBRCSC_INCLUDE`
/
`LIBRCSC_LINK`
variables in
`CMakeLists.txt`
to point to your librcsc include/lib directories.
...
...
example/agent.py
0 → 100755
View file @
fdef3ceb
#!/usr/bin/env python
# encoding: utf-8
import
imp
if
__name__
==
'__main__'
:
# First Start the server by calling start.py in bin
# Load the HFO library
hfo_module
=
imp
.
load_source
(
'HFO'
,
'../HFO.py'
)
# Create the HFO Environment
hfo
=
hfo_module
.
HFOEnvironment
()
hfo
.
connectToAgentServer
()
# Continue until finished
while
True
:
# Grab the state features from the environment
features
=
hfo
.
getState
()
# Take an action and get the reward
reward
=
hfo
.
act
(
0
)
# Cleanup when finished
hfo
.
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