Commit de23d119 authored by sanmit's avatar sanmit

Minor updates

parent baa4413c
......@@ -215,20 +215,23 @@ class Trainer(object):
assert body[0] == 'referee', 'Expected referee message.'
_,ts,event = body
self._frame = int(ts)
endOfTrial = False
if 'GOAL' in event:
self._numGoals += 1
self._numGoalFrames += self._frame - self._lastTrialStart
event = 'GOAL'
endOfTrial = True
elif event == 'OUT_OF_BOUNDS':
self._numBallsOOB += 1
endOfTrial = True
elif 'CAPTURED_BY_DEFENSE' in event:
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':
self._numOutOfTime += 1
endOfTrial = True
elif event == 'HFO_FINISHED':
self._done = True
if event in {'GOAL','OUT_OF_BOUNDS','CAPTURED_BY_DEFENSE','OUT_OF_TIME'}:
if endOfTrial:
self._numTrials += 1
print 'EndOfTrial: %d / %d %d %s'%\
(self._numGoals, self._numTrials, self._frame, event)
......
......@@ -42,9 +42,9 @@ if __name__ == '__main__':
print 'Episode', episode, 'ended with',
# Check what the outcome of the episode was
if status == HFO_Status.GOAL:
print 'goal'
print 'goal', hfo.playerOnBall().unum
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:
print 'out of bounds'
elif status == HFO_Status.OUT_OF_TIME:
......
......@@ -41,10 +41,10 @@ int main(int argc, char** argv) {
cout << "Episode " << episode << " ended with status: ";
switch (status) {
case GOAL:
cout << "goal" << endl;
cout << "goal " << hfo.playerOnBall().unum << endl;
break;
case CAPTURED_BY_DEFENSE:
cout << "captured by defense " << endl;
cout << "captured by defense " << hfo.playerOnBall().unum << endl;
break;
case OUT_OF_BOUNDS:
cout << "out of bounds" << endl;
......
......@@ -46,7 +46,6 @@ int main(int argc, char** argv) {
// Advance the environment and get the game status
status = hfo.step();
}
// Check what the outcome of the episode was
cout << "Episode " << episode << " ended with status: ";
switch (status) {
......@@ -66,11 +65,6 @@ int main(int argc, char** argv) {
cout << "Unknown status " << status << endl;
exit(1);
}
}
hfo.act(QUIT);
};
......@@ -170,8 +170,8 @@ class HFOEnvironment(object):
# Get the current game status
data = self.socket.recv(struct.calcsize("iii"))
status = struct.unpack("iii", data)[0]
self.player_on_ball = HFO_Player(struct.unpack("iii", data)[1], struct.unpack("iii",data)[2])
status, side, unum = struct.unpack("iii", data)
self.player_on_ball = HFO_Player(side,unum)
# Get the next state features
state_data = self.socket.recv(struct.calcsize('f')*self.numFeatures)
......
......@@ -248,8 +248,8 @@ void HFOEnvironment::handshakeAgentServer(feature_set_t feature_set) {
exit(1);
}
// Recieve the game status
std::vector<int> game_status(3, -1);
if (recv(sockfd, &(game_status.front()), 3 * sizeof(int), 0) < 0) {
int game_status[3];
if (recv(sockfd, &(game_status[0]), 3 * sizeof(int), 0) < 0) {
perror("[Agent Client] ERROR receiving game status from socket");
close(sockfd);
exit(1);
......@@ -259,6 +259,8 @@ void HFOEnvironment::handshakeAgentServer(feature_set_t feature_set) {
close(sockfd);
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;
}
......@@ -332,14 +334,14 @@ status_t HFOEnvironment::step() {
say_msg.clear();
// Get the game status
std::vector<int> full_status(3,-1);
if (recv(sockfd, &(full_status.front()), 3 * sizeof(int), 0) < 0) {
int full_status[3];
if (recv(sockfd, &(full_status[0]), 3 * sizeof(int), 0) < 0) {
perror("[Agent Client] ERROR receiving game status from socket");
close(sockfd);
exit(1);
}
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];
// Get the next game state
......
......@@ -3,7 +3,6 @@
#include <string>
#include <vector>
#include <rcsc/types.h>
namespace hfo {
......@@ -53,6 +52,12 @@ enum status_t
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
// numbers for each team. This struct is populated by ParseConfig().
struct Config {
......@@ -65,7 +70,7 @@ struct Config {
};
struct Player {
rcsc::SideID side; // SideID is an enum: 1 = LEFT, 0 = NEUTRAL, -1 = RIGHT
SideID side;
int unum;
};
......
......@@ -34,7 +34,6 @@
#include "feature_extractor.h"
#include <rcsc/player/player_agent.h>
#include <rcsc/types.h>
#include <vector>
class Agent : public rcsc::PlayerAgent {
......@@ -43,7 +42,7 @@ public:
virtual ~Agent();
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,
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