Commit b387747e authored by Matthew Hausknecht's avatar Matthew Hausknecht

Simplified includes.

parent 875bde45
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#define __HFO_C_WRAPPER_H__ #define __HFO_C_WRAPPER_H__
#include <vector> #include <vector>
#include <string.h>
#include <HFO.hpp> #include <HFO.hpp>
#include <common.hpp> #include <common.hpp>
......
...@@ -8,7 +8,7 @@ if not os.path.isfile(hfo_c_lib): ...@@ -8,7 +8,7 @@ if not os.path.isfile(hfo_c_lib):
module1 = Extension('hfo.hfo_c_wrapper', module1 = Extension('hfo.hfo_c_wrapper',
libraries = ['hfo_c'], libraries = ['hfo_c'],
include_dirs = ['src','src/chain_action','build/librcsc-prefix/src/librcsc'], include_dirs = ['src'],
library_dirs = ['hfo'], library_dirs = ['hfo'],
extra_compile_args=['-D__STDC_CONSTANT_MACROS'], extra_compile_args=['-D__STDC_CONSTANT_MACROS'],
sources=['hfo/hfo_c_wrapper.cpp']) sources=['hfo/hfo_c_wrapper.cpp'])
......
...@@ -11,9 +11,22 @@ ...@@ -11,9 +11,22 @@
#include <iostream> #include <iostream>
#include <stdarg.h> #include <stdarg.h>
#include <agent.h> #include <agent.h>
#include <rcsc/common/basic_client.h>
#include <rcsc/player/player_config.h>
#include <rcsc/player/world_model.h>
using namespace hfo; using namespace hfo;
HFOEnvironment::HFOEnvironment() {
client = new rcsc::BasicClient();
agent = new Agent();
}
HFOEnvironment::~HFOEnvironment() {
delete client;
delete agent;
}
void HFOEnvironment::connectToServer(feature_set_t feature_set, void HFOEnvironment::connectToServer(feature_set_t feature_set,
std::string config_dir, std::string config_dir,
int uniform_number, int uniform_number,
...@@ -21,37 +34,37 @@ void HFOEnvironment::connectToServer(feature_set_t feature_set, ...@@ -21,37 +34,37 @@ void HFOEnvironment::connectToServer(feature_set_t feature_set,
std::string server_addr, std::string server_addr,
std::string team_name, std::string team_name,
bool play_goalie) { bool play_goalie) {
agent.setFeatureSet(feature_set); agent->setFeatureSet(feature_set);
rcsc::PlayerConfig& config = agent.mutable_config(); rcsc::PlayerConfig& config = agent->mutable_config();
config.setConfigDir(config_dir); config.setConfigDir(config_dir);
config.setPlayerNumber(uniform_number); config.setPlayerNumber(uniform_number);
config.setPort(server_port); config.setPort(server_port);
config.setHost(server_addr); config.setHost(server_addr);
config.setTeamName(team_name); config.setTeamName(team_name);
config.setGoalie(play_goalie); config.setGoalie(play_goalie);
if (!agent.init(&client, 0, NULL)) { if (!agent->init(client, 0, NULL)) {
std::cerr << "Init failed" << std::endl; std::cerr << "Init failed" << std::endl;
exit(1); exit(1);
} }
client.setClientMode(rcsc::BasicClient::ONLINE); client->setClientMode(rcsc::BasicClient::ONLINE);
if (!client.startAgent(&agent)) { if (!client->startAgent(agent)) {
std::cerr << "Unable to start agent" << std::endl; std::cerr << "Unable to start agent" << std::endl;
exit(1); exit(1);
} }
assert(client.isServerAlive() == true); assert(client->isServerAlive() == true);
while (agent.getState().empty()) { while (agent->getState().empty()) {
step(); step();
} }
} }
const std::vector<float>& HFOEnvironment::getState() { const std::vector<float>& HFOEnvironment::getState() {
return agent.getState(); return agent->getState();
} }
void HFOEnvironment::act(action_t action, ...) { void HFOEnvironment::act(action_t action, ...) {
agent.setAction(action); agent->setAction(action);
int n_args = NumParams(action); int n_args = NumParams(action);
std::vector<float> *params = agent.mutable_params(); std::vector<float> *params = agent->mutable_params();
params->resize(n_args); params->resize(n_args);
va_list vl; va_list vl;
va_start(vl, action); va_start(vl, action);
...@@ -62,35 +75,35 @@ void HFOEnvironment::act(action_t action, ...) { ...@@ -62,35 +75,35 @@ void HFOEnvironment::act(action_t action, ...) {
} }
void HFOEnvironment::act(action_t action, const std::vector<float>& params) { void HFOEnvironment::act(action_t action, const std::vector<float>& params) {
agent.setAction(action); agent->setAction(action);
int n_args = NumParams(action); int n_args = NumParams(action);
assert(n_args == params.size()); assert(n_args == params.size());
std::vector<float> *agent_params = agent.mutable_params(); std::vector<float> *agent_params = agent->mutable_params();
(*agent_params) = params; (*agent_params) = params;
} }
void HFOEnvironment::say(const std::string& message) { void HFOEnvironment::say(const std::string& message) {
agent.setSayMsg(message); agent->setSayMsg(message);
} }
std::string HFOEnvironment::hear() { std::string HFOEnvironment::hear() {
return agent.getHearMsg(); return agent->getHearMsg();
} }
Player HFOEnvironment::playerOnBall() { Player HFOEnvironment::playerOnBall() {
return agent.getPlayerOnBall(); return agent->getPlayerOnBall();
} }
status_t HFOEnvironment::step() { status_t HFOEnvironment::step() {
bool end_of_trial = agent.getGameStatus() != IN_GAME; bool end_of_trial = agent->getGameStatus() != IN_GAME;
long start_cycle = agent.cycle(); long start_cycle = agent->cycle();
while ((agent.cycle() <= start_cycle) while ((agent->cycle() <= start_cycle)
|| (agent.getLastDecisionTime() < agent.cycle()) || (agent->getLastDecisionTime() < agent->cycle())
|| (end_of_trial && agent.getGameStatus() != IN_GAME)) { || (end_of_trial && agent->getGameStatus() != IN_GAME)) {
client.runStep(&agent); client->runStep(agent);
if (!client.isServerAlive()) { if (!client->isServerAlive()) {
return SERVER_DOWN; return SERVER_DOWN;
} }
} }
return agent.getGameStatus(); return agent->getGameStatus();
} }
...@@ -3,18 +3,17 @@ ...@@ -3,18 +3,17 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <rcsc/common/basic_client.h>
#include <rcsc/player/player_config.h>
#include <rcsc/player/world_model.h>
#include "agent.h"
#include "common.hpp" #include "common.hpp"
class Agent;
namespace rcsc { class BasicClient; }
namespace hfo { namespace hfo {
class HFOEnvironment { class HFOEnvironment {
public: public:
HFOEnvironment() {}; HFOEnvironment();
virtual ~HFOEnvironment() {}; virtual ~HFOEnvironment();
/** /**
* Connect to the server on the specified port. The * Connect to the server on the specified port. The
...@@ -54,9 +53,9 @@ class HFOEnvironment { ...@@ -54,9 +53,9 @@ class HFOEnvironment {
// progress. Returns the game status after the step // progress. Returns the game status after the step
virtual status_t step(); virtual status_t step();
protected: private:
rcsc::BasicClient client; rcsc::BasicClient* client;
Agent agent; Agent* agent;
}; };
} // namespace hfo } // namespace hfo
......
#ifndef __COMMON_HPP__ #ifndef __COMMON_HPP__
#define __COMMON_HPP__ #define __COMMON_HPP__
#include <assert.h>
#include <stdlib.h>
#include <iostream>
#include <sstream> #include <sstream>
namespace hfo { namespace hfo {
......
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