Commit 45572095 authored by Matthew Hausknecht's avatar Matthew Hausknecht

Refactored HFO interface.

parent b7ecb2d5
......@@ -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();
}
......
......@@ -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);
}
// Message
// Next, receive the message
if (msgLength > 0){
std::vector<char> hearMsgBuffer;
hearMsgBuffer.resize(msgLength);
......@@ -204,7 +203,7 @@ void HFOEnvironment::connectToAgentServer(int server_port,
perror("[Agent Client] ERROR recieving hear message from socket");
close(sockfd);
exit(1);
}
}
hear_msg.assign(&(hearMsgBuffer[0]), hearMsgBuffer.size());
}
}
......@@ -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
}
// 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,35 +337,31 @@ 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();
// Message length
// Receive message 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);
}
// Message
if (msgLength > 0){
// Receive the message
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);
}
}
hear_msg.assign(&(hearMsgBuffer[0]), hearMsgBuffer.size());
}
return game_status;
}
......@@ -70,7 +70,7 @@ struct Config {
};
struct Player {
SideID side;
SideID side;
int unum;
};
......@@ -103,7 +103,7 @@ class HFOEnvironment {
virtual void say(const std::string& message);
virtual std::string hear();
// Get the current player holding the ball
// Get the current player holding the ball
virtual Player playerOnBall();
// Indicates the agent is done and the environment should
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment