Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
Seminar-HFO
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Shashank Suhas
Seminar-HFO
Commits
7aaa40f4
Commit
7aaa40f4
authored
Sep 24, 2015
by
Matthew Hausknecht
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added low and high level random agents.
parent
208508a8
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
141 additions
and
2 deletions
+141
-2
CMakeLists.txt
CMakeLists.txt
+7
-2
example/high_level_random_agent.cpp
example/high_level_random_agent.cpp
+56
-0
example/low_level_random_agent.cpp
example/low_level_random_agent.cpp
+78
-0
No files found.
CMakeLists.txt
View file @
7aaa40f4
...
@@ -101,9 +101,14 @@ target_link_libraries(agent ${LINK_LIBS} player_chain_action)
...
@@ -101,9 +101,14 @@ target_link_libraries(agent ${LINK_LIBS} player_chain_action)
link_directories
(
${
CMAKE_CURRENT_SOURCE_DIR
}
/lib
)
link_directories
(
${
CMAKE_CURRENT_SOURCE_DIR
}
/lib
)
add_executable
(
hfo_example_agent
${
CMAKE_CURRENT_SOURCE_DIR
}
/example/hfo_example_agent.cpp
)
add_executable
(
hfo_example_agent
${
CMAKE_CURRENT_SOURCE_DIR
}
/example/hfo_example_agent.cpp
)
set_target_properties
(
hfo_example_agent PROPERTIES RUNTIME_OUTPUT_DIRECTORY
${
CMAKE_BINARY_DIR
}
/example
)
set_target_properties
(
hfo_example_agent PROPERTIES RUNTIME_OUTPUT_DIRECTORY
${
CMAKE_
CURRENT_
BINARY_DIR
}
/example
)
target_link_libraries
(
hfo_example_agent hfo
)
target_link_libraries
(
hfo_example_agent hfo
)
add_dependencies
(
hfo_example_agent hfo-lib
)
add_executable
(
low_level_random_agent
${
CMAKE_CURRENT_SOURCE_DIR
}
/example/low_level_random_agent.cpp
)
set_target_properties
(
low_level_random_agent PROPERTIES RUNTIME_OUTPUT_DIRECTORY
${
CMAKE_CURRENT_BINARY_DIR
}
/example
)
target_link_libraries
(
low_level_random_agent hfo
)
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
)
target_link_libraries
(
high_level_random_agent hfo
)
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
)
example/high_level_random_agent.cpp
0 → 100644
View file @
7aaa40f4
#include <iostream>
#include <vector>
#include <HFO.hpp>
#include <cstdlib>
using
namespace
std
;
using
namespace
hfo
;
// Before running this program, first Start HFO server:
// $./bin/HFO --offense-agents 1
// Returns a random high-level action
Action
get_random_high_lv_action
()
{
action_t
action_indx
=
(
action_t
)
((
rand
()
%
4
)
+
4
);
Action
act
=
{
action_indx
,
0
,
0
};
return
act
;
}
int
main
()
{
// 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
(
6000
,
HIGH_LEVEL_FEATURE_SET
);
// Play 5 episodes
for
(
int
episode
=
0
;
episode
<
5
;
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
();
// Create a dash action
Action
a
=
get_random_high_lv_action
();
// Perform the dash and recieve the current game status
status
=
hfo
.
act
(
a
);
}
// Check what the outcome of the episode was
cout
<<
"Episode "
<<
episode
<<
" ended with status: "
;
switch
(
status
)
{
case
GOAL
:
cout
<<
"goal"
<<
endl
;
break
;
case
CAPTURED_BY_DEFENSE
:
cout
<<
"captured by defense"
<<
endl
;
break
;
case
OUT_OF_BOUNDS
:
cout
<<
"out of bounds"
<<
endl
;
break
;
case
OUT_OF_TIME
:
cout
<<
"out of time"
<<
endl
;
break
;
default:
cout
<<
"Unknown status "
<<
status
<<
endl
;
exit
(
1
);
}
}
};
example/low_level_random_agent.cpp
0 → 100644
View file @
7aaa40f4
#include <iostream>
#include <vector>
#include <HFO.hpp>
#include <cstdlib>
using
namespace
std
;
using
namespace
hfo
;
// Before running this program, first Start HFO server:
// $./bin/HFO --offense-agents 1
// Returns a random low-level action
Action
get_random_low_lv_action
()
{
action_t
action_indx
=
(
action_t
)
(
rand
()
%
4
);
float
arg1
,
arg2
;
switch
(
action_indx
)
{
case
DASH
:
arg1
=
(
rand
()
/
float
(
RAND_MAX
))
*
200
-
100
;
// power: [-100, 100]
arg2
=
(
rand
()
/
float
(
RAND_MAX
))
*
360
-
180
;
// direction: [-180, 180]
break
;
case
TURN
:
arg1
=
(
rand
()
/
float
(
RAND_MAX
))
*
360
-
180
;
// direction: [-180, 180]
arg2
=
0
;
break
;
case
TACKLE
:
arg1
=
(
rand
()
/
float
(
RAND_MAX
))
*
360
-
180
;
// direction: [-180, 180]
arg2
=
0
;
break
;
case
KICK
:
arg1
=
(
rand
()
/
float
(
RAND_MAX
))
*
100
;
// power: [0, 100]
arg2
=
(
rand
()
/
float
(
RAND_MAX
))
*
360
-
180
;
// direction: [-180, 180]
break
;
default:
cout
<<
"Invalid Action Index: "
<<
action_indx
;
break
;
}
Action
act
=
{
action_indx
,
arg1
,
arg2
};
return
act
;
}
int
main
()
{
// 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
(
6000
,
LOW_LEVEL_FEATURE_SET
);
// Play 5 episodes
for
(
int
episode
=
0
;
episode
<
5
;
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
();
// Create a dash action
Action
a
=
get_random_low_lv_action
();
// Perform the dash and recieve the current game status
status
=
hfo
.
act
(
a
);
}
// Check what the outcome of the episode was
cout
<<
"Episode "
<<
episode
<<
" ended with status: "
;
switch
(
status
)
{
case
GOAL
:
cout
<<
"goal"
<<
endl
;
break
;
case
CAPTURED_BY_DEFENSE
:
cout
<<
"captured by defense"
<<
endl
;
break
;
case
OUT_OF_BOUNDS
:
cout
<<
"out of bounds"
<<
endl
;
break
;
case
OUT_OF_TIME
:
cout
<<
"out of time"
<<
endl
;
break
;
default:
cout
<<
"Unknown status "
<<
status
<<
endl
;
exit
(
1
);
}
}
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment