Commit de23d119 authored by sanmit's avatar sanmit

Minor updates

parent baa4413c
...@@ -215,20 +215,23 @@ class Trainer(object): ...@@ -215,20 +215,23 @@ 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)
endOfTrial = False
if 'GOAL' in event: if 'GOAL' in event:
self._numGoals += 1 self._numGoals += 1
self._numGoalFrames += self._frame - self._lastTrialStart self._numGoalFrames += self._frame - self._lastTrialStart
event = 'GOAL' endOfTrial = True
elif event == 'OUT_OF_BOUNDS': elif event == 'OUT_OF_BOUNDS':
self._numBallsOOB += 1 self._numBallsOOB += 1
endOfTrial = True
elif 'CAPTURED_BY_DEFENSE' in event: elif 'CAPTURED_BY_DEFENSE' in event:
self._numBallsCaptured += 1 self._numBallsCaptured += 1
event = "CAPTURED_BY_DEFENSE" # This clears the defender number from the printout below, but it doesn't really matter here. endOfTrial = True
elif event == 'OUT_OF_TIME': elif event == 'OUT_OF_TIME':
self._numOutOfTime += 1 self._numOutOfTime += 1
endOfTrial = True
elif event == 'HFO_FINISHED': elif event == 'HFO_FINISHED':
self._done = True self._done = True
if event in {'GOAL','OUT_OF_BOUNDS','CAPTURED_BY_DEFENSE','OUT_OF_TIME'}: if endOfTrial:
self._numTrials += 1 self._numTrials += 1
print 'EndOfTrial: %d / %d %d %s'%\ print 'EndOfTrial: %d / %d %d %s'%\
(self._numGoals, self._numTrials, self._frame, event) (self._numGoals, self._numTrials, self._frame, event)
......
...@@ -42,9 +42,9 @@ if __name__ == '__main__': ...@@ -42,9 +42,9 @@ if __name__ == '__main__':
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' 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:
......
...@@ -41,10 +41,10 @@ int main(int argc, char** argv) { ...@@ -41,10 +41,10 @@ int main(int argc, char** argv) {
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 " << 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;
......
...@@ -46,7 +46,6 @@ int main(int argc, char** argv) { ...@@ -46,7 +46,6 @@ int main(int argc, char** argv) {
// Advance the environment and get the game status // Advance the environment and get the game status
status = hfo.step(); status = hfo.step();
} }
// 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) {
...@@ -66,11 +65,6 @@ int main(int argc, char** argv) { ...@@ -66,11 +65,6 @@ int main(int argc, char** argv) {
cout << "Unknown status " << status << endl; cout << "Unknown status " << status << endl;
exit(1); exit(1);
} }
} }
hfo.act(QUIT); hfo.act(QUIT);
}; };
...@@ -170,8 +170,8 @@ class HFOEnvironment(object): ...@@ -170,8 +170,8 @@ class HFOEnvironment(object):
# Get the current game status # Get the current game status
data = self.socket.recv(struct.calcsize("iii")) data = self.socket.recv(struct.calcsize("iii"))
status = struct.unpack("iii", data)[0] status, side, unum = struct.unpack("iii", data)
self.player_on_ball = HFO_Player(struct.unpack("iii", data)[1], struct.unpack("iii",data)[2]) self.player_on_ball = HFO_Player(side,unum)
# 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)
......
...@@ -248,8 +248,8 @@ void HFOEnvironment::handshakeAgentServer(feature_set_t feature_set) { ...@@ -248,8 +248,8 @@ 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(3, -1); int game_status[3];
if (recv(sockfd, &(game_status.front()), 3 * sizeof(int), 0) < 0) { if (recv(sockfd, &(game_status[0]), 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);
...@@ -259,6 +259,8 @@ void HFOEnvironment::handshakeAgentServer(feature_set_t feature_set) { ...@@ -259,6 +259,8 @@ void HFOEnvironment::handshakeAgentServer(feature_set_t feature_set) {
close(sockfd); close(sockfd);
exit(1); exit(1);
} }
player_on_ball.side = (SideID)game_status[1];
player_on_ball.unum = game_status[2];
std::cout << "[Agent Client] Handshake complete" << std::endl; std::cout << "[Agent Client] Handshake complete" << std::endl;
} }
...@@ -332,14 +334,14 @@ status_t HFOEnvironment::step() { ...@@ -332,14 +334,14 @@ status_t HFOEnvironment::step() {
say_msg.clear(); say_msg.clear();
// Get the game status // Get the game status
std::vector<int> full_status(3,-1); int full_status[3];
if (recv(sockfd, &(full_status.front()), 3 * sizeof(int), 0) < 0) { if (recv(sockfd, &(full_status[0]), 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]; game_status = (status_t)full_status[0];
player_on_ball.side = (rcsc::SideID)full_status[1]; player_on_ball.side = (SideID)full_status[1];
player_on_ball.unum = full_status[2]; player_on_ball.unum = full_status[2];
// Get the next game state // Get the next game state
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <rcsc/types.h>
namespace hfo { namespace hfo {
...@@ -53,6 +52,12 @@ enum status_t ...@@ -53,6 +52,12 @@ enum status_t
OUT_OF_TIME // Trial has ended due to time limit OUT_OF_TIME // Trial has ended due to time limit
}; };
enum SideID {
RIGHT = -1,
NEUTRAL = 0,
LEFT = 1
};
// Configuration of the HFO domain including the team names and player // Configuration of the HFO domain including the team names and player
// numbers for each team. This struct is populated by ParseConfig(). // numbers for each team. This struct is populated by ParseConfig().
struct Config { struct Config {
...@@ -65,7 +70,7 @@ struct Config { ...@@ -65,7 +70,7 @@ struct Config {
}; };
struct Player { struct Player {
rcsc::SideID side; // SideID is an enum: 1 = LEFT, 0 = NEUTRAL, -1 = RIGHT SideID side;
int unum; int unum;
}; };
......
...@@ -34,7 +34,6 @@ ...@@ -34,7 +34,6 @@
#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 {
...@@ -43,7 +42,7 @@ public: ...@@ -43,7 +42,7 @@ public:
virtual ~Agent(); virtual ~Agent();
virtual FieldEvaluator::ConstPtr getFieldEvaluator() const; virtual FieldEvaluator::ConstPtr getFieldEvaluator() const;
// Get the current game status // Get the current game status, and the side and uniform number of the player holding the ball
static std::vector<int> getGameStatus(const rcsc::AudioSensor& audio_sensor, static std::vector<int> getGameStatus(const rcsc::AudioSensor& audio_sensor,
long& lastTrainerMessageTime); long& lastTrainerMessageTime);
......
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