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
231a5252
Commit
231a5252
authored
9 years ago
by
Matthew Hausknecht
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated HFO to be more permissive about calls to get state and act.
parent
c9eb5ab2
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
14 deletions
+26
-14
example/hfo_example_agent.py
example/hfo_example_agent.py
+1
-1
hfo/hfo.py
hfo/hfo.py
+16
-7
src/HFO.cpp
src/HFO.cpp
+9
-6
No files found.
example/hfo_example_agent.py
View file @
231a5252
...
...
@@ -21,7 +21,7 @@ if __name__ == '__main__':
# Grab the state features from the environment
features
=
hfo
.
getState
()
# Take an action and get the current game status
status
=
hfo
.
act
((
HFO_Actions
.
KICK
,
100
,
12.3
))
status
=
hfo
.
act
((
HFO_Actions
.
DASH
,
100
,
0
))
print
'Episode'
,
episode
,
'ended with'
,
# Check what the outcome of the episode was
if
status
==
HFO_Status
.
GOAL
:
...
...
This diff is collapsed.
Click to expand it.
hfo/hfo.py
View file @
231a5252
...
...
@@ -25,6 +25,7 @@ class HFOEnvironment(object):
def
__init__
(
self
):
self
.
socket
=
None
# Socket connection to server
self
.
numFeatures
=
None
# Given by the server in handshake
self
.
features
=
None
# The state features
def
connectToAgentServer
(
self
,
server_port
=
6008
):
'''Connect to the server that controls the agent on the specified port. '''
...
...
@@ -40,6 +41,13 @@ class HFOEnvironment(object):
break
print
'[Agent Client] Connected'
self
.
handshakeAgentServer
()
# Get the initial state
state_data
=
self
.
socket
.
recv
(
struct
.
calcsize
(
'f'
)
*
self
.
numFeatures
)
if
not
state_data
:
print
'[Agent Client] ERROR Recieved bad data from Server. Perhaps server closed?'
self
.
cleanup
()
exit
(
1
)
self
.
features
=
struct
.
unpack
(
'f'
*
self
.
numFeatures
,
state_data
)
def
handshakeAgentServer
(
self
):
'''Handshake with the agent's server. '''
...
...
@@ -63,13 +71,7 @@ class HFOEnvironment(object):
def
getState
(
self
):
'''Get the current state of the world. Returns a list of floats with
size numFeatures. '''
data
=
self
.
socket
.
recv
(
struct
.
calcsize
(
'f'
)
*
self
.
numFeatures
)
if
not
data
:
print
'[Agent Client] ERROR Recieved bad data from Server. Perhaps server closed?'
self
.
cleanup
()
exit
(
1
)
features
=
struct
.
unpack
(
'f'
*
self
.
numFeatures
,
data
)
return
features
return
self
.
features
def
act
(
self
,
action
):
''' Send an action and recieve the game status.'''
...
...
@@ -77,6 +79,13 @@ class HFOEnvironment(object):
# Get the current game status
data
=
self
.
socket
.
recv
(
struct
.
calcsize
(
"i"
))
status
=
struct
.
unpack
(
"i"
,
data
)[
0
]
# Get the next state features
state_data
=
self
.
socket
.
recv
(
struct
.
calcsize
(
'f'
)
*
self
.
numFeatures
)
if
not
state_data
:
print
'[Agent Client] ERROR Recieved bad data from Server. Perhaps server closed?'
self
.
cleanup
()
exit
(
1
)
self
.
features
=
struct
.
unpack
(
'f'
*
self
.
numFeatures
,
state_data
)
return
status
def
cleanup
(
self
):
...
...
This diff is collapsed.
Click to expand it.
src/HFO.cpp
View file @
231a5252
...
...
@@ -50,6 +50,11 @@ void HFOEnvironment::connectToAgentServer(int server_port) {
}
std
::
cout
<<
"[Agent Client] Connected"
<<
std
::
endl
;
handshakeAgentServer
();
// Get the initial game state
feature_vec
.
resize
(
numFeatures
);
if
(
recv
(
sockfd
,
&
(
feature_vec
.
front
()),
numFeatures
*
sizeof
(
float
),
0
)
<
0
)
{
error
(
"[Agent Client] ERROR recieving state features from socket"
);
}
}
void
HFOEnvironment
::
handshakeAgentServer
()
{
...
...
@@ -87,12 +92,6 @@ void HFOEnvironment::handshakeAgentServer() {
}
const
std
::
vector
<
float
>&
HFOEnvironment
::
getState
()
{
if
(
feature_vec
.
size
()
!=
numFeatures
)
{
feature_vec
.
resize
(
numFeatures
);
}
if
(
recv
(
sockfd
,
&
(
feature_vec
.
front
()),
numFeatures
*
sizeof
(
float
),
0
)
<
0
)
{
error
(
"[Agent Client] ERROR recieving state features from socket"
);
}
return
feature_vec
;
}
...
...
@@ -106,5 +105,9 @@ hfo_status_t HFOEnvironment::act(Action action) {
if
(
recv
(
sockfd
,
&
game_status
,
sizeof
(
hfo_status_t
),
0
)
<
0
)
{
error
(
"[Agent Client] ERROR recieving from socket"
);
}
// Get the next game state
if
(
recv
(
sockfd
,
&
(
feature_vec
.
front
()),
numFeatures
*
sizeof
(
float
),
0
)
<
0
)
{
error
(
"[Agent Client] ERROR recieving state features from socket"
);
}
return
game_status
;
}
This diff is collapsed.
Click to expand it.
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