diff --git a/.gitignore b/.gitignore index 7f3d2e39f22043ddedeefb12ecc9e25276bbd1f8..d72c7c256ec6d0e6cf12e8bc30f6f1c5cb4d1d8e 100644 --- a/.gitignore +++ b/.gitignore @@ -73,6 +73,7 @@ example/mid_level_move_agent example/mid_level_kick_agent example/mid_level_dribble_agent example/communication_agent +example/hand_coded_defense_agent # Dependency directories librcsc-prefix/ diff --git a/example/defense_2v2.sh b/example/defense_2v2.sh new file mode 100755 index 0000000000000000000000000000000000000000..c759440712f64182e4f7c0adcd09dd5af359b3ae --- /dev/null +++ b/example/defense_2v2.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +# HAS TO BE RUN FROM EXAMPLE DIR DUE TO hand_coded_defense_agent CONFIG! + +../bin/HFO --offense-npcs=2 --defense-agents=1 --defense-npcs=1 --trials 20 --headless --port=7000 & +sleep 5 +./hand_coded_defense_agent &> agent1.txt & +sleep 5 + +# The magic line +# $$ holds the PID for this script +# Negation means kill by process group id instead of PID +trap "kill -TERM -$$" SIGINT +wait \ No newline at end of file diff --git a/example/hand_coded_defense_agent b/example/hand_coded_defense_agent deleted file mode 100755 index 376dafcf2a52924e5ddec7fc5f64bdbeca7e47d8..0000000000000000000000000000000000000000 Binary files a/example/hand_coded_defense_agent and /dev/null differ diff --git a/example/hand_coded_defense_agent.cpp b/example/hand_coded_defense_agent.cpp index 609c48d1ece0dc0617de04bf39dd0dfccdcf5cbe..4eb28281ffd58cdcd4f2e9d065c304798952e306 100644 --- a/example/hand_coded_defense_agent.cpp +++ b/example/hand_coded_defense_agent.cpp @@ -208,7 +208,8 @@ int main(int argc, char** argv) { HFOEnvironment hfo; int random = 0; double numGoals = 0; - double numEpisodes = 5000; + 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, @@ -233,15 +234,15 @@ int main(int argc, char** argv) { string s = hfo::ActionToString(a.action) + " " +to_string(a.param) + "\n"; // std::cout << s; } else { - std::cout <<"Randm"; - action_t a = get_random_high_lv_action(); - if (a == hfo :: MARK_PLAYER) { - hfo.act(NOOP); - } else { - hfo.act(a); - } - } - //hfo.act(hfo::INTERCEPT); + 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) @@ -249,8 +250,14 @@ int main(int argc, char** argv) { // 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/numEpisodes; + double cost = numGoals/actualNumEpisodes; hfo.act(QUIT); //write_cost(cost); };