// This agent demonstrates the use of the MOVE_TO action to visit the // corners of the play field. Before running this program, first Start // HFO server: $./bin/HFO --offense-agents 1 int main(int argc, char** argv) { int port = 6000; if (argc > 1) { port = atoi(argv[1]); } // Create the HFO environment HFOEnvironment hfo; // Connect to the agent's server on port 6000 and request low-level // feature set. See manual for more information on feature sets. hfo.connectToAgentServer(port, HIGH_LEVEL_FEATURE_SET); float target_x = 1.0; float target_y = 1.0; for (int episode=0; ; episode++) { status_t status = IN_GAME; if (episode % 2 != 0) { target_x *= -1; } else { target_y *= -1; } std::cout << "target (x,y) = " << target_x << ", " << target_y << std::endl; while (status == IN_GAME) { // Get the vector of state features for the current state const vector<float>& feature_vec = hfo.getState(); // Perform the action hfo.act(MOVE_TO, target_x, target_y); // Advance the environment and get the game status status = hfo.step(); } } hfo.act(QUIT); };
int main(int argc, char** argv) { // Create the HFO environment //read_params(); HFOEnvironment hfo; int random = 0; double numGoals = 0; int numEpisodes = 5000; double actualNumEpisodes = 0; // Connect to the server and request high-level feature set. See // manual for more information on feature sets. hfo.connectToServer(features, config_dir, port, server_addr, team_name, goalie); for (int episode=0; episode<numEpisodes; episode++) { status_t status = IN_GAME; while (status == IN_GAME) { // Get the vector of state features for the current state const vector<float>& feature_vec = hfo.getState(); if (random == 0) { action_with_params a = get_defense_action(feature_vec, 2, hfo.getNumTeammates()); // std::cout << a.action << a.param; if (a.action == hfo :: MARK_PLAYER || a.action == hfo::TACKLE) { hfo.act(a.action, a.param); } else if (a.action == hfo :: DASH) { double power = 100; hfo.act(a.action, power, a.param); } else { hfo.act(a.action); } string s = hfo::ActionToString(a.action) + " " +to_string(a.param) + "\n"; // std::cout << s; } else { std::cout <<"Random"; action_t a = get_random_high_lv_action(); if (a == hfo :: MARK_PLAYER) { hfo.act(NOOP); // why not MOVE? } else { hfo.act(a); } } //hfo.act(hfo::INTERCEPT); status = hfo.step(); } if (status==GOAL) numGoals = numGoals+1; // Check what the outcome of the episode was cout << "Episode " << episode << " ended with status: " << StatusToString(status) << std::endl; if (status==SERVER_DOWN) { break; } else { actualNumEpisodes++; } } double cost = numGoals/actualNumEpisodes; hfo.act(QUIT); //write_cost(cost); };
int main(int argc, char** argv) { // Create the HFO environment HFOEnvironment hfo; // Connect to the server and request low-level feature set. See // manual for more information on feature sets. hfo.connectToServer(features, config_dir, port, server_addr, team_name, goalie); status_t status = IN_GAME; for (int episode = 0; status != SERVER_DOWN; episode++) { status = IN_GAME; while (status == IN_GAME) { // Get the vector of state features for the current state const vector<float>& feature_vec = hfo.getState(); float x = feature_vec[0]; float y = feature_vec[1]; float dist_to_target = sqrt(x*x + y*y) * 3; // Perform the action and recieve the current game status bool able_to_kick = feature_vec[5] > 0; if (able_to_kick) { // Valid kick speed varies in the range [0, 3] if (dist_to_target < .1) { // Max power kick to goal hfo.act(KICK_TO, 1., 0., 3.0); } else { // Kick to center of hfo field hfo.act(KICK_TO, 0., 0., dist_to_target); } } else { hfo.act(INTERCEPT); } // Advance the environment and get the game status status = hfo.step(); } // Check what the outcome of the episode was cout << "Episode " << episode << " ended with status: " << StatusToString(status) << endl;; } hfo.act(QUIT); };
int main() { // Create the HFO environment HFOEnvironment hfo; // Connect to the server and request low-level feature set. See // manual for more information on feature sets. hfo.connectToServer(features, config_dir, port, server_addr, team_name, goalie); status_t status = IN_GAME; for (int episode = 0; status != SERVER_DOWN; episode++) { status = IN_GAME; while (status == IN_GAME) { // Get the vector of state features for the current state const std::vector<float>& feature_vec = hfo.getState(); // Perform the dash hfo.act(DASH, 20.0, 0.0); // Advance the environment and recieve current game status status = hfo.step(); } // Check what the outcome of the episode was cout << "Episode " << episode << " ended with status: " << StatusToString(status) << endl; } hfo.act(QUIT); };