hfo_c_wrapper.h 2.04 KB
Newer Older
1 2 3 4
#ifndef __HFO_C_WRAPPER_H__
#define __HFO_C_WRAPPER_H__

#include <vector>
Matthew Hausknecht's avatar
Matthew Hausknecht committed
5
#include <string.h>
6 7 8 9 10 11 12 13 14 15 16 17
#include <HFO.hpp>
#include <common.hpp>

extern "C" {
  hfo::HFOEnvironment* HFO_new() { return new hfo::HFOEnvironment(); }
  void HFO_del(hfo::HFOEnvironment *hfo) { delete hfo; }
  void connectToServer(hfo::HFOEnvironment *hfo,
                       hfo::feature_set_t feature_set,
                       char* config_dir,
                       int server_port,
                       char* server_addr,
                       char* team_name,
18 19
                       bool play_goalie,
                       char* record_dir) {
20
    return hfo->connectToServer(feature_set, config_dir,
21
                                server_port, server_addr, team_name,
22
                                play_goalie, record_dir);
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
  }
  int getStateSize(hfo::HFOEnvironment *hfo) { return hfo->getState().size(); }
  void getState(hfo::HFOEnvironment *hfo, float *state_data) {
    const float* state_features = hfo->getState().data();
    memcpy(state_data, state_features, getStateSize(hfo) * sizeof(float));
  }
  void act(hfo::HFOEnvironment *hfo, hfo::action_t action, float* params) {
    int n_params = NumParams(action);
    std::vector<float> p(n_params);
    for (int i=0; i<n_params; ++i) {
      p[i] = params[i];
    }
    hfo->act(action, p);
  }
  void say(hfo::HFOEnvironment *hfo, const char *message) { hfo->say(message); }
  const char* hear(hfo::HFOEnvironment *hfo) { return hfo->hear().c_str(); }
  hfo::Player playerOnBall(hfo::HFOEnvironment *hfo) { return hfo->playerOnBall(); }
  hfo::status_t step(hfo::HFOEnvironment *hfo) { return hfo->step(); }

  int numParams(const hfo::action_t action) { return NumParams(action); }
  const char* actionToString(const hfo::action_t action) {
    return ActionToString(action).c_str();
  }
  const char* statusToString(const hfo::status_t status) {
47
    StatusToString(status); // TODO: OSX requires two calls...?!
48 49
    return StatusToString(status).c_str();
  }
50
  int getUnum(hfo::HFOEnvironment *hfo) {return hfo->getUnum();}
51 52 53
}

#endif