Commit d40cbab2 authored by Matthew Hausknecht's avatar Matthew Hausknecht

Added example mid-level agents.

parent 6f642689
...@@ -109,6 +109,21 @@ target_link_libraries(low_level_random_agent hfo-lib) ...@@ -109,6 +109,21 @@ target_link_libraries(low_level_random_agent hfo-lib)
add_executable(high_level_random_agent ${CMAKE_CURRENT_SOURCE_DIR}/example/high_level_random_agent.cpp) add_executable(high_level_random_agent ${CMAKE_CURRENT_SOURCE_DIR}/example/high_level_random_agent.cpp)
set_target_properties(high_level_random_agent PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/example) set_target_properties(high_level_random_agent PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/example)
target_link_libraries(high_level_random_agent hfo-lib) target_link_libraries(high_level_random_agent hfo-lib)
add_executable(mid_level_move_agent ${CMAKE_CURRENT_SOURCE_DIR}/example/mid_level_move_agent.cpp)
set_target_properties(mid_level_move_agent PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/example)
target_link_libraries(mid_level_move_agent hfo-lib)
add_executable(mid_level_kick_agent ${CMAKE_CURRENT_SOURCE_DIR}/example/mid_level_kick_agent.cpp)
set_target_properties(mid_level_kick_agent PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/example)
target_link_libraries(mid_level_kick_agent hfo-lib)
add_executable(mid_level_dribble_agent ${CMAKE_CURRENT_SOURCE_DIR}/example/mid_level_dribble_agent.cpp)
set_target_properties(mid_level_dribble_agent PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/example)
target_link_libraries(mid_level_dribble_agent hfo-lib)
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/example DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/ USE_SOURCE_PERMISSIONS) install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/example DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/ USE_SOURCE_PERMISSIONS)
install(DIRECTORY ${RCSSSERVER_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/bin DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/ USE_SOURCE_PERMISSIONS) install(DIRECTORY ${RCSSSERVER_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/bin DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/ USE_SOURCE_PERMISSIONS)
...@@ -48,13 +48,14 @@ def main(args, team1='left', team2='right'): ...@@ -48,13 +48,14 @@ def main(args, team1='left', team2='right'):
'server::fullstate_l=%i server::fullstate_r=%i ' \ 'server::fullstate_l=%i server::fullstate_r=%i ' \
'server::coach_w_referee=1 server::hfo_max_trial_time=%i ' \ 'server::coach_w_referee=1 server::hfo_max_trial_time=%i ' \
'server::hfo_max_trials=%i server::hfo_max_frames=%i ' \ 'server::hfo_max_trials=%i server::hfo_max_frames=%i ' \
'server::hfo_offense_on_ball=%i server::random_seed=%i' \ 'server::hfo_offense_on_ball=%i server::random_seed=%i ' \
'server::hfo_max_untouched_time=%i' \
%(server_port, coach_port, olcoach_port, %(server_port, coach_port, olcoach_port,
args.logging, args.logging, args.logging, args.logging, args.logging, args.logging,
args.logDir, args.logDir, args.logDir, args.logDir, args.logDir, args.logDir,
args.sync, args.fullstate, args.fullstate, args.sync, args.fullstate, args.fullstate,
args.maxFramesPerTrial, args.numTrials, args.numFrames, args.maxFramesPerTrial, args.numTrials, args.numFrames,
args.offenseOnBall, args.seed) args.offenseOnBall, args.seed, args.maxUntouchedTime)
# server::record_messages=on -- useful for debug # server::record_messages=on -- useful for debug
try: try:
# Launch the Server # Launch the Server
...@@ -101,6 +102,9 @@ def parseArgs(): ...@@ -101,6 +102,9 @@ def parseArgs():
p.add_argument('--frames-per-trial', dest='maxFramesPerTrial', type=int, p.add_argument('--frames-per-trial', dest='maxFramesPerTrial', type=int,
default=1000, help='Max number of frames per trial. '\ default=1000, help='Max number of frames per trial. '\
'Negative values mean unlimited.') 'Negative values mean unlimited.')
p.add_argument('--untouched-time', dest='maxUntouchedTime', type=int,
default=100, help='Ends trial if ball is untouched for this long. '\
'Negative values mean unlimited.')
p.add_argument('--offense-agents', dest='offenseAgents', type=int, default=0, p.add_argument('--offense-agents', dest='offenseAgents', type=int, default=0,
help='Number of offensive agents') help='Number of offensive agents')
p.add_argument('--defense-agents', dest='defenseAgents', type=int, default=0, p.add_argument('--defense-agents', dest='defenseAgents', type=int, default=0,
......
#include <iostream>
#include <vector>
#include <HFO.hpp>
#include <cstdlib>
#include <math.h>
using namespace std;
using namespace hfo;
// This agent demonstrates the use of the DRIBBLE_TO action. Before
// running this program, first Start HFO server: $./bin/HFO
// --offense-agents 1
#define PI 3.14159265
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);
for (int episode=0; ; episode++) {
status_t status = IN_GAME;
int step = 0;
while (status == IN_GAME) {
// Get the vector of state features for the current state
const vector<float>& feature_vec = hfo.getState();
// Dribble in a circle around center field
float target_x = sin((step % 360) * PI/180);
float target_y = cos((step % 360) * PI/180);
status = hfo.act(DRIBBLE_TO, target_x, target_y);
step += 2;
}
}
hfo.act(QUIT);
};
#include <iostream>
#include <vector>
#include <HFO.hpp>
#include <cstdlib>
#include <math.h>
using namespace std;
using namespace hfo;
// This agent demonstrates the use of the KICK_TO action. 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);
for (int episode=0; ; 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();
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
status = hfo.act(KICK_TO, 1., 0., 3.0);
} else {
// Kick to center of hfo field
status = hfo.act(KICK_TO, 0., 0., dist_to_target);
}
} else {
status = hfo.act(INTERCEPT);
}
}
}
hfo.act(QUIT);
};
#include <iostream>
#include <vector>
#include <HFO.hpp>
#include <cstdlib>
using namespace std;
using namespace hfo;
// 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 and recieve the current game status
status = hfo.act(MOVE_TO, target_x, target_y);
}
}
hfo.act(QUIT);
};
...@@ -17,17 +17,17 @@ enum feature_set_t ...@@ -17,17 +17,17 @@ enum feature_set_t
// The actions available to the agent // The actions available to the agent
enum action_t enum action_t
{ {
DASH, // [Low-Level] Dash(power, direction) DASH, // [Low-Level] Dash(power [0,100], direction [-180,180])
TURN, // [Low-Level] Turn(direction) TURN, // [Low-Level] Turn(direction [-180,180])
TACKLE, // [Low-Level] Tackle(direction) TACKLE, // [Low-Level] Tackle(direction [-180,180])
KICK, // [Low-Level] Kick(power, direction) KICK, // [Low-Level] Kick(power [0,100], direction [-180,180])
KICK_TO, // [Mid-Level] Kick_To(target_x, target_y, speed) KICK_TO, // [Mid-Level] Kick_To(target_x [-1,1], target_y [-1,1], speed [0,3])
MOVE_TO, // [Mid-Level] Move(target_x, target_y) MOVE_TO, // [Mid-Level] Move(target_x [-1,1], target_y [-1,1])
DRIBBLE_TO, // [Mid-Level] Dribble(target_x, target_y) DRIBBLE_TO, // [Mid-Level] Dribble(target_x [-1,1], target_y [-1,1])
INTERCEPT, // [Mid-Level] Intercept(): Intercept the ball INTERCEPT, // [Mid-Level] Intercept(): Intercept the ball
MOVE, // [High-Level] Move(): Reposition player according to strategy MOVE, // [High-Level] Move(): Reposition player according to strategy
SHOOT, // [High-Level] Shoot(): Shoot the ball SHOOT, // [High-Level] Shoot(): Shoot the ball
PASS, // [High-Level] Pass(teammate_unum): Pass to the most open teammate PASS, // [High-Level] Pass(teammate_unum [0,11]): Pass to the most open teammate
DRIBBLE, // [High-Level] Dribble(): Offensive dribble DRIBBLE, // [High-Level] Dribble(): Offensive dribble
NOOP, // Do nothing NOOP, // Do nothing
QUIT // Special action to quit the game QUIT // Special action to quit the game
......
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