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
45572095
Commit
45572095
authored
Feb 02, 2016
by
Matthew Hausknecht
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored HFO interface.
parent
b7ecb2d5
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
28 deletions
+18
-28
example/hfo_example_agent.cpp
example/hfo_example_agent.cpp
+1
-1
src/HFO.cpp
src/HFO.cpp
+17
-27
No files found.
example/hfo_example_agent.cpp
View file @
45572095
...
...
@@ -22,7 +22,7 @@ int main() {
// Get the vector of state features for the current state
const
std
::
vector
<
float
>&
feature_vec
=
hfo
.
getState
();
// Perform the dash
hfo
.
act
(
DASH
,
20.0
);
hfo
.
act
(
DASH
,
20.0
,
0.0
);
// Advance the environment and recieve current game status
status
=
hfo
.
step
();
}
...
...
src/HFO.cpp
View file @
45572095
...
...
@@ -188,15 +188,14 @@ void HFOEnvironment::connectToAgentServer(int server_port,
close
(
sockfd
);
exit
(
1
);
}
// Get first hear message
// Message length
// First get the length of the hear message
uint32_t
msgLength
;
if
(
recv
(
sockfd
,
&
msgLength
,
sizeof
(
uint32_t
),
0
)
<
0
){
perror
(
"[Agent Client] ERROR recieving hear message length from socket"
);
close
(
sockfd
);
exit
(
1
);
}
//
M
essage
//
Next, receive the m
essage
if
(
msgLength
>
0
){
std
::
vector
<
char
>
hearMsgBuffer
;
hearMsgBuffer
.
resize
(
msgLength
);
...
...
@@ -283,7 +282,6 @@ void HFOEnvironment::act(action_t action, ...) {
}
void
HFOEnvironment
::
say
(
const
std
::
string
&
message
)
{
// TODO: [Sanmit] Bounds check message?
say_msg
=
message
;
}
...
...
@@ -291,13 +289,12 @@ std::string HFOEnvironment::hear() {
return
hear_msg
;
}
Player
HFOEnvironment
::
playerOnBall
(){
Player
HFOEnvironment
::
playerOnBall
()
{
return
player_on_ball
;
}
status_t
HFOEnvironment
::
step
()
{
status_t
game_status
;
// Send the action_type
if
(
send
(
sockfd
,
&
requested_action
,
sizeof
(
action_t
),
0
)
<
0
)
{
perror
(
"[Agent Client] ERROR sending from socket"
);
...
...
@@ -313,26 +310,23 @@ status_t HFOEnvironment::step() {
exit
(
1
);
}
}
// [Sanmit] Send say_msg
// Send message length
// Send the message length
uint32_t
sendMsgLength
=
say_msg
.
size
();
if
(
send
(
sockfd
,
&
sendMsgLength
,
sizeof
(
uint32_t
),
0
)
<
0
){
if
(
send
(
sockfd
,
&
sendMsgLength
,
sizeof
(
uint32_t
),
0
)
<
0
)
{
perror
(
"[Agent Client] ERROR sending from socket"
);
close
(
sockfd
);
exit
(
1
);
}
// Send message
if
(
sendMsgLength
>
0
)
{
if
(
send
(
sockfd
,
say_msg
.
c_str
(),
say_msg
.
size
(),
0
)
<
0
)
{
// Send
the say
message
if
(
sendMsgLength
>
0
)
{
if
(
send
(
sockfd
,
say_msg
.
c_str
(),
say_msg
.
size
(),
0
)
<
0
)
{
perror
(
"[Agent Client] ERROR sending from socket"
);
close
(
sockfd
);
exit
(
1
);
}
}
// Clear say message buffer
say_msg
.
clear
();
// Get the game status
int
full_status
[
3
];
if
(
recv
(
sockfd
,
&
(
full_status
[
0
]),
3
*
sizeof
(
int
),
0
)
<
0
)
{
...
...
@@ -343,28 +337,26 @@ status_t HFOEnvironment::step() {
game_status
=
(
status_t
)
full_status
[
0
];
player_on_ball
.
side
=
(
SideID
)
full_status
[
1
];
player_on_ball
.
unum
=
full_status
[
2
];
// Get the next game state
if
(
recv
(
sockfd
,
&
(
feature_vec
.
front
()),
numFeatures
*
sizeof
(
float
),
0
)
<
0
)
{
perror
(
"[Agent Client] ERROR receiving state features from socket"
);
close
(
sockfd
);
exit
(
1
);
}
// [Sanmit] Receive comm_msg
// Clear last message
hear_msg
.
clear
();
//
M
essage length
//
Receive m
essage length
uint32_t
msgLength
;
if
(
recv
(
sockfd
,
&
msgLength
,
sizeof
(
uint32_t
),
0
)
<
0
){
if
(
recv
(
sockfd
,
&
msgLength
,
sizeof
(
uint32_t
),
0
)
<
0
)
{
perror
(
"[Agent Client] ERROR receiving hear message length from socket"
);
close
(
sockfd
);
exit
(
1
);
}
//
M
essage
if
(
msgLength
>
0
){
//
Receive the m
essage
if
(
msgLength
>
0
)
{
std
::
vector
<
char
>
hearMsgBuffer
;
hearMsgBuffer
.
resize
(
msgLength
);
if
(
recv
(
sockfd
,
&
hearMsgBuffer
[
0
],
msgLength
,
0
)
<
0
){
if
(
recv
(
sockfd
,
&
hearMsgBuffer
[
0
],
msgLength
,
0
)
<
0
)
{
perror
(
"[Agent Client] ERROR receiving hear message from socket"
);
close
(
sockfd
);
exit
(
1
);
...
...
@@ -373,5 +365,3 @@ status_t HFOEnvironment::step() {
}
return
game_status
;
}
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