Commit baa4413c authored by sanmit's avatar sanmit

Updated ref to broadcast last player to touch the ball

parent 731070be
...@@ -215,9 +215,10 @@ class Trainer(object): ...@@ -215,9 +215,10 @@ class Trainer(object):
assert body[0] == 'referee', 'Expected referee message.' assert body[0] == 'referee', 'Expected referee message.'
_,ts,event = body _,ts,event = body
self._frame = int(ts) self._frame = int(ts)
if event == 'GOAL': if 'GOAL' in event:
self._numGoals += 1 self._numGoals += 1
self._numGoalFrames += self._frame - self._lastTrialStart self._numGoalFrames += self._frame - self._lastTrialStart
event = 'GOAL'
elif event == 'OUT_OF_BOUNDS': elif event == 'OUT_OF_BOUNDS':
self._numBallsOOB += 1 self._numBallsOOB += 1
elif 'CAPTURED_BY_DEFENSE' in event: elif 'CAPTURED_BY_DEFENSE' in event:
......
...@@ -25,7 +25,6 @@ int main(int argc, char** argv) { ...@@ -25,7 +25,6 @@ int main(int argc, char** argv) {
// Play 5 episodes // Play 5 episodes
for (int episode=0; ; episode++) { for (int episode=0; ; episode++) {
int step = 0; int step = 0;
vector<int> game_status;
status_t status = IN_GAME; status_t status = IN_GAME;
while (status == IN_GAME) { while (status == IN_GAME) {
// Get the vector of state features for the current state // Get the vector of state features for the current state
...@@ -41,8 +40,7 @@ int main(int argc, char** argv) { ...@@ -41,8 +40,7 @@ int main(int argc, char** argv) {
// Do something with outgoing communication // Do something with outgoing communication
hfo.say("Message"); hfo.say("Message");
// Advance the environment and get the game status // Advance the environment and get the game status
game_status = hfo.step(); status = hfo.step();
status = (status_t)game_status[0];
step+=2; step+=2;
} }
} }
......
...@@ -37,14 +37,14 @@ if __name__ == '__main__': ...@@ -37,14 +37,14 @@ if __name__ == '__main__':
hfo_env.act(HFO_Actions.DASH, 20.0, 0) hfo_env.act(HFO_Actions.DASH, 20.0, 0)
# Do something with outgoing communication # Do something with outgoing communication
hfo_env.say('Message') hfo_env.say('Message')
(status, playerIndex) = hfo_env.step() status = hfo_env.step()
print 'Episode', episode, 'ended with', print 'Episode', episode, 'ended with',
# Check what the outcome of the episode was # Check what the outcome of the episode was
if status == HFO_Status.GOAL: if status == HFO_Status.GOAL:
print 'goal' print 'goal'
elif status == HFO_Status.CAPTURED_BY_DEFENSE: elif status == HFO_Status.CAPTURED_BY_DEFENSE:
print 'captured by defense', playerIndex print 'captured by defense'
elif status == HFO_Status.OUT_OF_BOUNDS: elif status == HFO_Status.OUT_OF_BOUNDS:
print 'out of bounds' print 'out of bounds'
elif status == HFO_Status.OUT_OF_TIME: elif status == HFO_Status.OUT_OF_TIME:
......
...@@ -28,7 +28,7 @@ def play_hfo(num): ...@@ -28,7 +28,7 @@ def play_hfo(num):
hfo_env.act(get_random_action()) hfo_env.act(get_random_action())
else: else:
hfo_env.act(HFO_Actions.MOVE) hfo_env.act(HFO_Actions.MOVE)
(status, playerIndex) = hfo_env.step() status = hfo_env.step()
except: except:
pass pass
finally: finally:
......
...@@ -17,7 +17,6 @@ int main() { ...@@ -17,7 +17,6 @@ int main() {
hfo.connectToAgentServer(6000, LOW_LEVEL_FEATURE_SET); hfo.connectToAgentServer(6000, LOW_LEVEL_FEATURE_SET);
// Play 5 episodes // Play 5 episodes
for (int episode=0; episode<5; episode++) { for (int episode=0; episode<5; episode++) {
vector<int> game_status;
status_t status = IN_GAME; status_t status = IN_GAME;
while (status == IN_GAME) { while (status == IN_GAME) {
// Get the vector of state features for the current state // Get the vector of state features for the current state
...@@ -25,8 +24,7 @@ int main() { ...@@ -25,8 +24,7 @@ int main() {
// Perform the dash // Perform the dash
hfo.act(DASH, 20.0); hfo.act(DASH, 20.0);
// Advance the environment and recieve current game status // Advance the environment and recieve current game status
game_status = hfo.step(); status = hfo.step();
status = (status_t)game_status[0];
} }
// Check what the outcome of the episode was // Check what the outcome of the episode was
cout << "Episode " << episode << " ended with status: "; cout << "Episode " << episode << " ended with status: ";
......
...@@ -20,20 +20,20 @@ if __name__ == '__main__': ...@@ -20,20 +20,20 @@ if __name__ == '__main__':
# feature set. See feature sets in hfo.py/hfo.hpp. # feature set. See feature sets in hfo.py/hfo.hpp.
hfo.connectToAgentServer(port, HFO_Features.HIGH_LEVEL_FEATURE_SET) hfo.connectToAgentServer(port, HFO_Features.HIGH_LEVEL_FEATURE_SET)
# Play 5 episodes # Play 5 episodes
for episode in xrange(5): for episode in xrange(100):
status = HFO_Status.IN_GAME status = HFO_Status.IN_GAME
while status == HFO_Status.IN_GAME: while status == HFO_Status.IN_GAME:
# Grab the state features from the environment # Grab the state features from the environment
features = hfo.getState() features = hfo.getState()
# Take an action and get the current game status # Take an action and get the current game status
hfo.act(HFO_Actions.DASH, 20.0, 0) hfo.act(HFO_Actions.DASH, 20.0, 0)
(status, playerIndex) = hfo.step() status = hfo.step()
print 'Episode', episode, 'ended with', print 'Episode', episode, 'ended with',
# Check what the outcome of the episode was # Check what the outcome of the episode was
if status == HFO_Status.GOAL: if status == HFO_Status.GOAL:
print 'goal' print 'goal', hfo.playerOnBall().unum
elif status == HFO_Status.CAPTURED_BY_DEFENSE: elif status == HFO_Status.CAPTURED_BY_DEFENSE:
print 'captured by defense', playerIndex print 'captured by defense', hfo.playerOnBall().unum
elif status == HFO_Status.OUT_OF_BOUNDS: elif status == HFO_Status.OUT_OF_BOUNDS:
print 'out of bounds' print 'out of bounds'
elif status == HFO_Status.OUT_OF_TIME: elif status == HFO_Status.OUT_OF_TIME:
......
...@@ -27,7 +27,6 @@ int main(int argc, char** argv) { ...@@ -27,7 +27,6 @@ int main(int argc, char** argv) {
hfo.connectToAgentServer(port, HIGH_LEVEL_FEATURE_SET); hfo.connectToAgentServer(port, HIGH_LEVEL_FEATURE_SET);
// Play 5 episodes // Play 5 episodes
for (int episode=0; ; episode++) { for (int episode=0; ; episode++) {
vector<int> game_status;
status_t status = IN_GAME; status_t status = IN_GAME;
while (status == IN_GAME) { while (status == IN_GAME) {
// Get the vector of state features for the current state // Get the vector of state features for the current state
...@@ -35,8 +34,7 @@ int main(int argc, char** argv) { ...@@ -35,8 +34,7 @@ int main(int argc, char** argv) {
// Perform the action // Perform the action
hfo.act(get_random_high_lv_action()); hfo.act(get_random_high_lv_action());
// Advance the environment and get the game status // Advance the environment and get the game status
game_status = hfo.step(); status = hfo.step();
status = (status_t)game_status[0];
} }
// Check what the outcome of the episode was // Check what the outcome of the episode was
...@@ -46,7 +44,7 @@ int main(int argc, char** argv) { ...@@ -46,7 +44,7 @@ int main(int argc, char** argv) {
cout << "goal" << endl; cout << "goal" << endl;
break; break;
case CAPTURED_BY_DEFENSE: case CAPTURED_BY_DEFENSE:
cout << "captured by defense " << game_status[1] << endl; cout << "captured by defense " << endl;
break; break;
case OUT_OF_BOUNDS: case OUT_OF_BOUNDS:
cout << "out of bounds" << endl; cout << "out of bounds" << endl;
......
...@@ -51,7 +51,6 @@ int main(int argc, char** argv) { ...@@ -51,7 +51,6 @@ int main(int argc, char** argv) {
hfo.connectToAgentServer(port, LOW_LEVEL_FEATURE_SET); hfo.connectToAgentServer(port, LOW_LEVEL_FEATURE_SET);
// Play 5 episodes // Play 5 episodes
for (int episode=0; ; episode++) { for (int episode=0; ; episode++) {
vector<int> game_status;
status_t status = IN_GAME; status_t status = IN_GAME;
while (status == IN_GAME) { while (status == IN_GAME) {
// Get the vector of state features for the current state // Get the vector of state features for the current state
...@@ -59,8 +58,7 @@ int main(int argc, char** argv) { ...@@ -59,8 +58,7 @@ int main(int argc, char** argv) {
// Perform the action and recieve the current game status // Perform the action and recieve the current game status
hfo.act(get_random_low_lv_action(), arg1, arg2); hfo.act(get_random_low_lv_action(), arg1, arg2);
game_status = hfo.step(); status = hfo.step();
status = (status_t)game_status[0];
} }
} }
}; };
...@@ -24,7 +24,6 @@ int main(int argc, char** argv) { ...@@ -24,7 +24,6 @@ int main(int argc, char** argv) {
// feature set. See manual for more information on feature sets. // feature set. See manual for more information on feature sets.
hfo.connectToAgentServer(port, HIGH_LEVEL_FEATURE_SET); hfo.connectToAgentServer(port, HIGH_LEVEL_FEATURE_SET);
for (int episode=0; ; episode++) { for (int episode=0; ; episode++) {
vector<int> game_status;
status_t status = IN_GAME; status_t status = IN_GAME;
int step = 0; int step = 0;
while (status == IN_GAME) { while (status == IN_GAME) {
...@@ -35,8 +34,7 @@ int main(int argc, char** argv) { ...@@ -35,8 +34,7 @@ int main(int argc, char** argv) {
float target_y = cos((step % 360) * PI/180); float target_y = cos((step % 360) * PI/180);
hfo.act(DRIBBLE_TO, target_x, target_y); hfo.act(DRIBBLE_TO, target_x, target_y);
// Advance the environment and get the game status // Advance the environment and get the game status
game_status = hfo.step(); status = hfo.step();
status = (status_t)game_status[0];
step += 2; step += 2;
} }
} }
......
...@@ -22,7 +22,6 @@ int main(int argc, char** argv) { ...@@ -22,7 +22,6 @@ int main(int argc, char** argv) {
// feature set. See manual for more information on feature sets. // feature set. See manual for more information on feature sets.
hfo.connectToAgentServer(port, HIGH_LEVEL_FEATURE_SET); hfo.connectToAgentServer(port, HIGH_LEVEL_FEATURE_SET);
for (int episode=0; ; episode++) { for (int episode=0; ; episode++) {
vector<int> game_status;
status_t status = IN_GAME; status_t status = IN_GAME;
while (status == IN_GAME) { while (status == IN_GAME) {
// Get the vector of state features for the current state // Get the vector of state features for the current state
...@@ -45,18 +44,17 @@ int main(int argc, char** argv) { ...@@ -45,18 +44,17 @@ int main(int argc, char** argv) {
hfo.act(INTERCEPT); hfo.act(INTERCEPT);
} }
// Advance the environment and get the game status // Advance the environment and get the game status
game_status = hfo.step(); status = hfo.step();
status = (status_t)game_status[0];
} }
// Check what the outcome of the episode was // Check what the outcome of the episode was
cout << "Episode " << episode << " ended with status: "; cout << "Episode " << episode << " ended with status: ";
switch (status) { switch (status) {
case GOAL: case GOAL:
cout << "goal" << endl; cout << "goal " << hfo.playerOnBall().unum << endl;
break; break;
case CAPTURED_BY_DEFENSE: case CAPTURED_BY_DEFENSE:
cout << "captured by defense " << game_status[1] << endl; cout << "captured by defense " << hfo.playerOnBall().unum << endl;
break; break;
case OUT_OF_BOUNDS: case OUT_OF_BOUNDS:
cout << "out of bounds" << endl; cout << "out of bounds" << endl;
......
...@@ -22,7 +22,6 @@ int main(int argc, char** argv) { ...@@ -22,7 +22,6 @@ int main(int argc, char** argv) {
float target_x = 1.0; float target_x = 1.0;
float target_y = 1.0; float target_y = 1.0;
for (int episode=0; ; episode++) { for (int episode=0; ; episode++) {
vector<int> game_status;
status_t status = IN_GAME; status_t status = IN_GAME;
if (episode % 2 != 0) { if (episode % 2 != 0) {
target_x *= -1; target_x *= -1;
...@@ -36,8 +35,7 @@ int main(int argc, char** argv) { ...@@ -36,8 +35,7 @@ int main(int argc, char** argv) {
// Perform the action // Perform the action
hfo.act(MOVE_TO, target_x, target_y); hfo.act(MOVE_TO, target_x, target_y);
// Advance the environment and get the game status // Advance the environment and get the game status
game_status = hfo.step(); status = hfo.step();
status = (status_t)game_status[0];
} }
} }
hfo.act(QUIT); hfo.act(QUIT);
......
import socket, struct, thread, time import socket, struct, thread, time, collections
class HFO_Features: class HFO_Features:
''' An enum of the possible HFO feature sets. For descriptions see ''' An enum of the possible HFO feature sets. For descriptions see
...@@ -30,10 +30,17 @@ class HFO_Actions: ...@@ -30,10 +30,17 @@ class HFO_Actions:
DASH, TURN, TACKLE, KICK, KICK_TO, MOVE_TO, DRIBBLE_TO, INTERCEPT, \ DASH, TURN, TACKLE, KICK, KICK_TO, MOVE_TO, DRIBBLE_TO, INTERCEPT, \
MOVE, SHOOT, PASS, DRIBBLE, CATCH, NOOP, QUIT = range(15) MOVE, SHOOT, PASS, DRIBBLE, CATCH, NOOP, QUIT = range(15)
HFO_Player = collections.namedtuple("HFO_Player", "side unum")
class HFO_Status: class HFO_Status:
''' Current status of the HFO game. ''' ''' Current status of the HFO game. '''
IN_GAME, GOAL, CAPTURED_BY_DEFENSE, OUT_OF_BOUNDS, OUT_OF_TIME = range(5) IN_GAME, GOAL, CAPTURED_BY_DEFENSE, OUT_OF_BOUNDS, OUT_OF_TIME = range(5)
class HFO_SideID:
''' Team side for a player or object'''
RIGHT, NEUTRAL, LEFT = range(-1, 2)
class HFOEnvironment(object): class HFOEnvironment(object):
''' The HFOEnvironment is designed to be the main point of contact ''' The HFOEnvironment is designed to be the main point of contact
...@@ -47,6 +54,7 @@ class HFOEnvironment(object): ...@@ -47,6 +54,7 @@ class HFOEnvironment(object):
self.requested_action = None # Action to execute and parameters self.requested_action = None # Action to execute and parameters
self.say_msg = '' # Outgoing message to say self.say_msg = '' # Outgoing message to say
self.hear_msg = '' # Incoming heard message self.hear_msg = '' # Incoming heard message
self.player_on_ball = None # Current player holding the ball
def NumParams(self, action_type): def NumParams(self, action_type):
''' Returns the number of required parameters for each action type. ''' ''' Returns the number of required parameters for each action type. '''
...@@ -117,8 +125,8 @@ class HFOEnvironment(object): ...@@ -117,8 +125,8 @@ class HFOEnvironment(object):
# Send what we recieved # Send what we recieved
self.socket.send(struct.pack("i", self.numFeatures)) self.socket.send(struct.pack("i", self.numFeatures))
# Get the current game status # Get the current game status
data = self.socket.recv(struct.calcsize("i")*2) data = self.socket.recv(struct.calcsize("iii"))
status = struct.unpack("ii", data)[0] status = struct.unpack("iii", data)[0]
assert status == HFO_Status.IN_GAME, "Status check failed" assert status == HFO_Status.IN_GAME, "Status check failed"
print '[Agent Client] Handshake complete' print '[Agent Client] Handshake complete'
...@@ -144,6 +152,10 @@ class HFOEnvironment(object): ...@@ -144,6 +152,10 @@ class HFOEnvironment(object):
''' Receive incoming communications from other players. ''' ''' Receive incoming communications from other players. '''
return self.hear_msg return self.hear_msg
def playerOnBall(self):
''' Get the current player holding the ball'''
return self.player_on_ball
def step(self): def step(self):
''' Indicates the agent is done and the environment should ''' Indicates the agent is done and the environment should
progress. Returns the game status after the step''' progress. Returns the game status after the step'''
...@@ -157,9 +169,9 @@ class HFOEnvironment(object): ...@@ -157,9 +169,9 @@ class HFOEnvironment(object):
self.say_msg = '' self.say_msg = ''
# Get the current game status # Get the current game status
data = self.socket.recv(struct.calcsize("i") * 2) data = self.socket.recv(struct.calcsize("iii"))
status = struct.unpack("ii", data)[0] status = struct.unpack("iii", data)[0]
playerIndex = struct.unpack("ii", data)[1] self.player_on_ball = HFO_Player(struct.unpack("iii", data)[1], struct.unpack("iii",data)[2])
# Get the next state features # Get the next state features
state_data = self.socket.recv(struct.calcsize('f')*self.numFeatures) state_data = self.socket.recv(struct.calcsize('f')*self.numFeatures)
...@@ -176,7 +188,7 @@ class HFOEnvironment(object): ...@@ -176,7 +188,7 @@ class HFOEnvironment(object):
hearMsgData = self.socket.recv(struct.calcsize('c')*hearMsgLength) hearMsgData = self.socket.recv(struct.calcsize('c')*hearMsgLength)
self.hear_msg = struct.unpack(str(hearMsgLength)+'s', hearMsgData)[0] self.hear_msg = struct.unpack(str(hearMsgLength)+'s', hearMsgData)[0]
return (status, playerIndex) return status
def cleanup(self): def cleanup(self):
''' Send a quit and close the connection to the agent's server. ''' ''' Send a quit and close the connection to the agent's server. '''
......
...@@ -248,13 +248,13 @@ void HFOEnvironment::handshakeAgentServer(feature_set_t feature_set) { ...@@ -248,13 +248,13 @@ void HFOEnvironment::handshakeAgentServer(feature_set_t feature_set) {
exit(1); exit(1);
} }
// Recieve the game status // Recieve the game status
std::vector<int> game_status(2, -1); std::vector<int> game_status(3, -1);
if (recv(sockfd, &(game_status.front()), 2 * sizeof(int), 0) < 0) { if (recv(sockfd, &(game_status.front()), 3 * sizeof(int), 0) < 0) {
perror("[Agent Client] ERROR receiving game status from socket"); perror("[Agent Client] ERROR receiving game status from socket");
close(sockfd); close(sockfd);
exit(1); exit(1);
} }
if ((status_t)game_status[0] != IN_GAME) { if (game_status[0] != IN_GAME) {
std::cout << "[Agent Client] Handshake failed: status check." << std::endl; std::cout << "[Agent Client] Handshake failed: status check." << std::endl;
close(sockfd); close(sockfd);
exit(1); exit(1);
...@@ -289,8 +289,12 @@ std::string HFOEnvironment::hear() { ...@@ -289,8 +289,12 @@ std::string HFOEnvironment::hear() {
return hear_msg; return hear_msg;
} }
std::vector<int> HFOEnvironment::step() { Player HFOEnvironment::playerOnBall(){
std::vector<int> game_status(2, -1); return player_on_ball;
}
status_t HFOEnvironment::step() {
status_t game_status;
// Send the action_type // Send the action_type
if (send(sockfd, &requested_action, sizeof(action_t), 0) < 0) { if (send(sockfd, &requested_action, sizeof(action_t), 0) < 0) {
...@@ -328,11 +332,16 @@ std::vector<int> HFOEnvironment::step() { ...@@ -328,11 +332,16 @@ std::vector<int> HFOEnvironment::step() {
say_msg.clear(); say_msg.clear();
// Get the game status // Get the game status
if (recv(sockfd, &(game_status.front()), 2 * sizeof(int), 0) < 0) { std::vector<int> full_status(3,-1);
if (recv(sockfd, &(full_status.front()), 3 * sizeof(int), 0) < 0) {
perror("[Agent Client] ERROR receiving game status from socket"); perror("[Agent Client] ERROR receiving game status from socket");
close(sockfd); close(sockfd);
exit(1); exit(1);
} }
game_status = (status_t)full_status[0];
player_on_ball.side = (rcsc::SideID)full_status[1];
player_on_ball.unum = full_status[2];
// Get the next game state // Get the next game state
if (recv(sockfd, &(feature_vec.front()), numFeatures * sizeof(float), 0) < 0) { if (recv(sockfd, &(feature_vec.front()), numFeatures * sizeof(float), 0) < 0) {
perror("[Agent Client] ERROR receiving state features from socket"); perror("[Agent Client] ERROR receiving state features from socket");
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <rcsc/types.h>
namespace hfo { namespace hfo {
...@@ -63,6 +64,11 @@ struct Config { ...@@ -63,6 +64,11 @@ struct Config {
std::vector<int> defense_nums; // Defensive player numbers std::vector<int> defense_nums; // Defensive player numbers
}; };
struct Player {
rcsc::SideID side; // SideID is an enum: 1 = LEFT, 0 = NEUTRAL, -1 = RIGHT
int unum;
};
class HFOEnvironment { class HFOEnvironment {
public: public:
HFOEnvironment(); HFOEnvironment();
...@@ -92,9 +98,12 @@ class HFOEnvironment { ...@@ -92,9 +98,12 @@ class HFOEnvironment {
virtual void say(const std::string& message); virtual void say(const std::string& message);
virtual std::string hear(); virtual std::string hear();
// Get the current player holding the ball
virtual Player playerOnBall();
// Indicates the agent is done and the environment should // Indicates the agent is done and the environment should
// progress. Returns the game status after the step // progress. Returns the game status after the step
virtual std::vector<int> step(); virtual status_t step();
protected: protected:
int numFeatures; // The number of features in this domain int numFeatures; // The number of features in this domain
...@@ -103,6 +112,7 @@ class HFOEnvironment { ...@@ -103,6 +112,7 @@ class HFOEnvironment {
action_t requested_action; // Action requested action_t requested_action; // Action requested
std::vector<float> action_params; // Action parameters std::vector<float> action_params; // Action parameters
std::string say_msg, hear_msg; // Messages to hear/say std::string say_msg, hear_msg; // Messages to hear/say
Player player_on_ball;
// Handshake with the agent server to ensure data is being correctly // Handshake with the agent server to ensure data is being correctly
// passed. Also sets the number of features to expect. // passed. Also sets the number of features to expect.
......
...@@ -366,23 +366,40 @@ FeatureExtractor* Agent::getFeatureExtractor(feature_set_t feature_set_indx, ...@@ -366,23 +366,40 @@ FeatureExtractor* Agent::getFeatureExtractor(feature_set_t feature_set_indx,
std::vector<int> Agent::getGameStatus(const rcsc::AudioSensor& audio_sensor, std::vector<int> Agent::getGameStatus(const rcsc::AudioSensor& audio_sensor,
long& lastTrainerMessageTime) { long& lastTrainerMessageTime) {
std::vector<int> status; std::vector<int> status;
status_t game_status = IN_GAME; status_t game_status = IN_GAME;
int playerIndex = -1; // Keeps track of which defender stopped the shot int playerIndex = -1; // Keeps track of which defender stopped the shot
int playerTeam = 1; // 1 = offense, -1 = defense, 0 = no possession
if (audio_sensor.trainerMessageTime().cycle() > lastTrainerMessageTime) { if (audio_sensor.trainerMessageTime().cycle() > lastTrainerMessageTime) {
const std::string& message = audio_sensor.trainerMessage(); const std::string& message = audio_sensor.trainerMessage();
bool recognized_message = true; bool recognized_message = true;
if (message.compare("GOAL") == 0) { if (message.find("GOAL") != std::string::npos){
playerIndex = atoi((message.substr(message.find("-")+1)).c_str());
playerTeam = 1;
game_status = GOAL; game_status = GOAL;
} else if (message.find("CAPTURED_BY_DEFENSE") != std::string::npos) { } else if (message.find("CAPTURED_BY_DEFENSE") != std::string::npos) {
playerIndex = atoi((message.substr(message.find("-")+1)).c_str()); playerIndex = atoi((message.substr(message.find("-")+1)).c_str());
playerTeam = -1;
game_status = CAPTURED_BY_DEFENSE; game_status = CAPTURED_BY_DEFENSE;
} else if (message.compare("OUT_OF_BOUNDS") == 0) { } else if (message.compare("OUT_OF_BOUNDS") == 0) {
game_status = OUT_OF_BOUNDS; game_status = OUT_OF_BOUNDS;
} else if (message.compare("OUT_OF_TIME") == 0) { } else if (message.compare("OUT_OF_TIME") == 0) {
game_status = OUT_OF_TIME; game_status = OUT_OF_TIME;
} else { } else if (message.find("IN_GAME") != std::string::npos){
switch (message.at(message.find("-")+1)){
case 'L':
playerTeam = 1;
break;
case 'R':
playerTeam = -1;
break;
case 'U':
playerTeam = 0;
break;
}
playerIndex = atoi((message.substr(message.find("-")+2)).c_str());
}
else {
recognized_message = false; recognized_message = false;
} }
if (recognized_message) { if (recognized_message) {
...@@ -390,7 +407,8 @@ std::vector<int> Agent::getGameStatus(const rcsc::AudioSensor& audio_sensor, ...@@ -390,7 +407,8 @@ std::vector<int> Agent::getGameStatus(const rcsc::AudioSensor& audio_sensor,
} }
} }
status.push_back(game_status); status.push_back(game_status);
status.push_back(playerIndex); status.push_back(playerTeam);
status.push_back(playerIndex);
return status; return status;
} }
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "feature_extractor.h" #include "feature_extractor.h"
#include <rcsc/player/player_agent.h> #include <rcsc/player/player_agent.h>
#include <rcsc/types.h>
#include <vector> #include <vector>
class Agent : public rcsc::PlayerAgent { class Agent : public rcsc::PlayerAgent {
......
...@@ -269,10 +269,9 @@ SamplePlayer::actionImpl() ...@@ -269,10 +269,9 @@ SamplePlayer::actionImpl()
hfo::LOW_LEVEL_FEATURE_SET, num_teammates, num_opponents, playing_offense); hfo::LOW_LEVEL_FEATURE_SET, num_teammates, num_opponents, playing_offense);
} }
} else { } else {
std::vector<int> full_status = Agent::getGameStatus( std::vector<int> game_status = Agent::getGameStatus(
audioSensor(), lastTrainerMessageTime); audioSensor(), lastTrainerMessageTime);
hfo::status_t game_status = (hfo::status_t)full_status[0]; elog.addText(Logger::WORLD, "GameStatus %d", game_status[0]);
elog.addText(Logger::WORLD, "GameStatus %d", game_status);
elog.flush(); elog.flush();
feature_extractor->ExtractFeatures(this->world()); feature_extractor->ExtractFeatures(this->world());
feature_extractor->LogFeatures(); feature_extractor->LogFeatures();
......
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