hfo_example_agent.cpp 1.36 KB
Newer Older
1 2 3
#include <iostream>
#include <vector>
#include <HFO.hpp>
4
#include <cstdlib>
5 6

using namespace std;
7
using namespace hfo;
8

9
// Before running this program, first Start HFO server:
10 11 12 13 14 15 16 17 18 19
// $> ./bin/HFO --offense-agents 1

// Server Connection Options. See printouts from bin/HFO.
feature_set_t features = LOW_LEVEL_FEATURE_SET;
string config_dir = "bin/teams/base/config/formations-dt";
int unum = 11;
int port = 6001;
string server_addr = "localhost";
string team_name = "base_left";
bool goalie = false;
20 21 22 23

int main() {
  // Create the HFO environment
  HFOEnvironment hfo;
24 25 26 27
  // Connect to the server and request low-level feature set. See
  // manual for more information on feature sets.
  hfo.connectToServer(features, config_dir, unum, port, server_addr,
                           team_name, goalie);
28 29
  // Play 5 episodes
  for (int episode=0; episode<5; episode++) {
30
    status_t status = IN_GAME;
31
    while (status == IN_GAME) {
32
      // Get the vector of state features for the current state
33
      const std::vector<float>& feature_vec = hfo.getState();
34
      // Perform the dash
35
      hfo.act(DASH, 20.0, 0.0);
36 37
      // Advance the environment and recieve current game status
      status = hfo.step();
38 39
    }
    // Check what the outcome of the episode was
40 41
    cout << "Episode " << episode << " ended with status: "
         << StatusToString(status) << std::endl;;
42
  }
43
  hfo.act(QUIT);
44
};