Commit e074f351 authored by Matthew Hausknecht's avatar Matthew Hausknecht

Fix for elog missing issue.

parent ec2fa47f
...@@ -4,6 +4,8 @@ project(hfo) ...@@ -4,6 +4,8 @@ project(hfo)
# Change these to reflect the location of your librcsc-4.1.0 install # Change these to reflect the location of your librcsc-4.1.0 install
set(LIBRCSC_INCLUDE ~/.local/include) set(LIBRCSC_INCLUDE ~/.local/include)
set(LIBRCSC_LINK ~/.local/lib) set(LIBRCSC_LINK ~/.local/lib)
# Add this definition if using Librcsc from https://github.com/mhauskn/librcsc
# add_definitions(-DELOG)
set(SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src) set(SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY bin) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY bin)
......
...@@ -137,8 +137,7 @@ Agent::Agent() ...@@ -137,8 +137,7 @@ Agent::Agent()
M_action_generator(createActionGenerator()), M_action_generator(createActionGenerator()),
lastTrainerMessageTime(-1), lastTrainerMessageTime(-1),
server_port(6008), server_port(6008),
server_running(false), server_running(false)
record(false)
{ {
boost::shared_ptr< AudioMemory > audio_memory( new AudioMemory ); boost::shared_ptr< AudioMemory > audio_memory( new AudioMemory );
...@@ -202,25 +201,35 @@ bool Agent::initImpl(CmdLineParser & cmd_parser) { ...@@ -202,25 +201,35 @@ bool Agent::initImpl(CmdLineParser & cmd_parser) {
int numTeammates, numOpponents; int numTeammates, numOpponents;
bool playingOffense; bool playingOffense;
rcsc::ParamMap my_params("Additional options"); rcsc::ParamMap my_params("Additional options");
my_params.add()("numTeammates", "", &numTeammates, "number of teammates"); my_params.add()
my_params.add()("numOpponents", "", &numOpponents, "number of opponents"); ("numTeammates", "", &numTeammates)
my_params.add()("playingOffense", "", &playingOffense, ("numOpponents", "", &numOpponents)
"are we playing offense or defense"); ("playingOffense", "", &playingOffense)
my_params.add()("serverPort", "", &server_port, "Port to start server on"); ("serverPort", "", &server_port);
record = cmd_parser.count("record") > 0;
cmd_parser.parse(my_params); cmd_parser.parse(my_params);
if (cmd_parser.count("help") > 0) { if (cmd_parser.count("help") > 0) {
my_params.printHelp( std::cout ); my_params.printHelp(std::cout);
return false; return false;
} }
if (cmd_parser.failed()) { if (cmd_parser.failed()) {
std::cerr << "player: ***WARNING*** detected unsuppprted options: "; std::cerr << "player: ***WARNING*** detected unsuppprted options: ";
cmd_parser.print( std::cerr ); cmd_parser.print( std::cerr );
std::cerr << std::endl; std::cerr << std::endl;
} }
#ifdef ELOG
#else
const std::list<std::string>& args = cmd_parser.args();
if (std::find(args.begin(), args.end(), "--record") != args.end()) {
std::cerr
<< "[Agent Client] ERROR: Action recording requested but no supported."
<< " To enable action recording, install https://github.com/mhauskn/librcsc"
<< " and recompile with -DELOG. See CMakeLists.txt"
<< std::endl;
return false;
}
#endif
if (!result) { if (!result) {
return false; return false;
} }
...@@ -340,11 +349,15 @@ void Agent::actionImpl() { ...@@ -340,11 +349,15 @@ void Agent::actionImpl() {
// Update and send the state features // Update and send the state features
const std::vector<float>& features = const std::vector<float>& features =
feature_extractor->ExtractFeatures(this->world()); feature_extractor->ExtractFeatures(this->world());
if (record) {
#ifdef ELOG
if (config().record()) {
elog.addText(Logger::WORLD, "GameStatus %d", game_status); elog.addText(Logger::WORLD, "GameStatus %d", game_status);
elog.flush(); elog.flush();
feature_extractor->LogFeatures(); feature_extractor->LogFeatures();
} }
#endif
if (send(newsockfd, &(features.front()), if (send(newsockfd, &(features.front()),
features.size() * sizeof(float), 0) < 0) { features.size() * sizeof(float), 0) < 0) {
error("[Agent Server] ERROR sending state features from socket"); error("[Agent Server] ERROR sending state features from socket");
......
...@@ -75,7 +75,6 @@ protected: ...@@ -75,7 +75,6 @@ protected:
int server_port; // Port to start the server on int server_port; // Port to start the server on
bool server_running; // Is the server running? bool server_running; // Is the server running?
int sockfd, newsockfd; // Server sockets int sockfd, newsockfd; // Server sockets
bool record; // Record states + actions
private: private:
bool doPreprocess(); bool doPreprocess();
......
...@@ -31,6 +31,7 @@ FeatureExtractor::FeatureExtractor() : ...@@ -31,6 +31,7 @@ FeatureExtractor::FeatureExtractor() :
FeatureExtractor::~FeatureExtractor() {} FeatureExtractor::~FeatureExtractor() {}
void FeatureExtractor::LogFeatures() { void FeatureExtractor::LogFeatures() {
#ifdef ELOG
assert(feature_vec.size() == numFeatures); assert(feature_vec.size() == numFeatures);
std::stringstream ss; std::stringstream ss;
for (int i=0; i<numFeatures; ++i) { for (int i=0; i<numFeatures; ++i) {
...@@ -38,6 +39,7 @@ void FeatureExtractor::LogFeatures() { ...@@ -38,6 +39,7 @@ void FeatureExtractor::LogFeatures() {
} }
elog.addText(Logger::WORLD, "StateFeatures %s", ss.str().c_str()); elog.addText(Logger::WORLD, "StateFeatures %s", ss.str().c_str());
elog.flush(); elog.flush();
#endif
} }
void FeatureExtractor::addAngFeature(const rcsc::AngleDeg& ang) { void FeatureExtractor::addAngFeature(const rcsc::AngleDeg& ang) {
......
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