Commit b387747e authored by Matthew Hausknecht's avatar Matthew Hausknecht

Simplified includes.

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