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
ab0990d6
You need to sign in or sign up before continuing.
Commit
ab0990d6
authored
Jun 21, 2016
by
Matthew Hausknecht
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More work on the agent-environment interface.
parent
a625a971
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
66 additions
and
21 deletions
+66
-21
example/high_level_random_agent.cpp
example/high_level_random_agent.cpp
+7
-3
example/random_2v1.sh
example/random_2v1.sh
+3
-3
src/HFO.cpp
src/HFO.cpp
+28
-6
src/HFO.hpp
src/HFO.hpp
+1
-0
src/agent.cpp
src/agent.cpp
+17
-8
src/agent.h
src/agent.h
+7
-0
src/common.hpp
src/common.hpp
+2
-0
src/feature_extractor.cpp
src/feature_extractor.cpp
+1
-1
No files found.
example/high_level_random_agent.cpp
View file @
ab0990d6
...
...
@@ -17,8 +17,8 @@ string server_addr = "localhost";
string
team_name
=
"base_left"
;
bool
goalie
=
false
;
// We omit PASS & CATCH actions here
action_t
HIGH_LEVEL_ACTIONS
[
3
]
=
{
MOVE
,
SHOOT
,
DRIBBLE
};
// We omit PASS & CATCH
& MOVE
actions here
action_t
HIGH_LEVEL_ACTIONS
[
2
]
=
{
SHOOT
,
DRIBBLE
};
int
main
(
int
argc
,
char
**
argv
)
{
// Create the HFO environment
...
...
@@ -34,7 +34,11 @@ int main(int argc, char** argv) {
// Get the vector of state features for the current state
const
vector
<
float
>&
feature_vec
=
hfo
.
getState
();
// Perform the action
hfo
.
act
(
HIGH_LEVEL_ACTIONS
[
rand
()
%
3
]);
if
(
feature_vec
[
5
]
==
1
)
{
// Feature 5 is 1 when the player can kick the ball
hfo
.
act
(
HIGH_LEVEL_ACTIONS
[
rand
()
%
2
]);
}
else
{
hfo
.
act
(
MOVE
);
}
// Advance the environment and get the game status
status
=
hfo
.
step
();
}
...
...
example/random_2v1.sh
View file @
ab0990d6
#!/bin/bash
./bin/HFO
--offense-agents
=
2
--defense-npcs
=
1
--trials
10
0
--headless
&
./bin/HFO
--offense-agents
=
2
--defense-npcs
=
1
--trials
2
0
--headless
&
sleep
5
./example/high_level_random_agent 6000 &
./example/high_level_random_agent 6000 &
> agent1.txt &
sleep
5
./example/high_level_random_agent 6000 &
./example/high_level_random_agent 6000 &
> agent2.txt &
# The magic line
# $$ holds the PID for this script
...
...
src/HFO.cpp
View file @
ab0990d6
...
...
@@ -60,11 +60,21 @@ void HFOEnvironment::connectToServer(feature_set_t feature_set,
act
(
NOOP
);
while
(
agent
->
getState
().
empty
())
{
if
(
!
client
->
isServerAlive
())
{
std
::
cerr
<<
"Server Down!"
<<
std
::
endl
;
std
::
cerr
<<
"
[ConnectToServer]
Server Down!"
<<
std
::
endl
;
exit
(
1
);
}
client
->
runStep
(
agent
);
ready_for_action
=
client
->
runStep
(
agent
);
if
(
ready_for_action
)
{
agent
->
action
();
}
}
// Step until it is time to act
do
{
ready_for_action
=
client
->
runStep
(
agent
);
}
while
(
!
ready_for_action
);
agent
->
ProcessTrainerMessages
();
agent
->
ProcessTeammateMessages
();
agent
->
UpdateFeatures
();
current_cycle
=
agent
->
currentTime
().
cycle
();
}
...
...
@@ -111,12 +121,24 @@ Player HFOEnvironment::playerOnBall() {
status_t
HFOEnvironment
::
step
()
{
assert
(
agent
->
currentTime
().
cycle
()
==
current_cycle
);
while
(
agent
->
statusUpdateTime
()
<=
current_cycle
)
{
if
(
!
client
->
isServerAlive
())
{
assert
(
ready_for_action
);
// Execute the action
agent
->
action
();
// Advance the environment by one step
do
{
ready_for_action
=
client
->
runStep
(
agent
);
if
(
!
client
->
isServerAlive
()
||
agent
->
getGameStatus
()
==
SERVER_DOWN
)
{
return
SERVER_DOWN
;
}
client
->
runStep
(
agent
);
}
agent
->
ProcessTrainerMessages
();
}
while
(
agent
->
statusUpdateTime
()
<=
current_cycle
||
!
ready_for_action
);
// Update the state features
agent
->
ProcessTeammateMessages
();
agent
->
UpdateFeatures
();
assert
(
agent
->
currentTime
().
cycle
()
==
(
current_cycle
+
1
));
current_cycle
=
agent
->
currentTime
().
cycle
();
return
agent
->
getGameStatus
();
...
...
src/HFO.hpp
View file @
ab0990d6
...
...
@@ -60,6 +60,7 @@ class HFOEnvironment {
rcsc
::
BasicClient
*
client
;
Agent
*
agent
;
long
current_cycle
;
bool
ready_for_action
;
};
}
// namespace hfo
...
...
src/agent.cpp
View file @
ab0990d6
...
...
@@ -311,14 +311,9 @@ void Agent::actionImpl() {
this
->
setNeckAction
(
new
Neck_TurnToBallOrScan
());
}
/*-------------------------------------------------------------------*/
/*!
*/
void
Agent
::
handleActionStart
()
Agent
::
ProcessTrainerMessages
()
{
// Process new trainer messages
if
(
audioSensor
().
trainerMessageTime
().
cycle
()
>
lastTrainerMessageTime
)
{
const
std
::
string
&
message
=
audioSensor
().
trainerMessage
();
if
(
feature_extractor
==
NULL
)
{
...
...
@@ -339,8 +334,11 @@ Agent::handleActionStart()
hfo
::
ParsePlayerOnBall
(
message
,
player_on_ball
);
lastTrainerMessageTime
=
audioSensor
().
trainerMessageTime
().
cycle
();
}
}
// Process new teammate message
void
Agent
::
ProcessTeammateMessages
()
{
hear_msg
.
clear
();
if
(
audioSensor
().
teammateMessageTime
().
cycle
()
>
lastTeammateMessageTime
)
{
const
std
::
list
<
HearMessage
>
teammateMessages
=
audioSensor
().
teammateMessages
();
...
...
@@ -353,11 +351,22 @@ Agent::handleActionStart()
}
lastTeammateMessageTime
=
audioSensor
().
teammateMessageTime
().
cycle
();
}
}
// Update state features
void
Agent
::
UpdateFeatures
()
{
if
(
feature_extractor
!=
NULL
)
{
state
=
feature_extractor
->
ExtractFeatures
(
this
->
world
());
}
}
void
Agent
::
handleActionStart
()
{
ProcessTrainerMessages
();
ProcessTeammateMessages
();
UpdateFeatures
();
// Optionally write to logfile
#ifdef ELOG
...
...
src/agent.h
View file @
ab0990d6
...
...
@@ -24,6 +24,13 @@ public:
inline
long
statusUpdateTime
()
{
return
lastStatusUpdateTime
;
}
// Process incoming trainer messages. Used to update the game status.
void
ProcessTrainerMessages
();
// Process incoming teammate messages.
void
ProcessTeammateMessages
();
// Update the state features from the world model.
void
UpdateFeatures
();
protected:
// You can override this method. But you must call
// PlayerAgent::initImpl() in this method.
...
...
src/common.hpp
View file @
ab0990d6
...
...
@@ -263,6 +263,8 @@ inline bool ParseGameStatus(const std::string& message, status_t& status) {
status
=
OUT_OF_TIME
;
}
else
if
(
message
.
find
(
"IN_GAME"
)
!=
std
::
string
::
npos
){
status
=
IN_GAME
;
}
else
if
(
message
.
find
(
"HFO_FINISHED"
)
!=
std
::
string
::
npos
){
status
=
SERVER_DOWN
;
}
else
{
return
false
;
}
...
...
src/feature_extractor.cpp
View file @
ab0990d6
...
...
@@ -146,7 +146,7 @@ bool FeatureExtractor::valid(const rcsc::PlayerObject& player) {
pos
.
x
<
-
ALLOWED_PITCH_FRAC
*
rcsc
::
ServerParam
::
i
().
pitchHalfLength
())
{
return
false
;
}
return
p
layer
.
unum
()
>
0
&&
p
os
.
isValid
();
return
pos
.
isValid
();
}
float
FeatureExtractor
::
angleToPoint
(
const
rcsc
::
Vector2D
&
self
,
...
...
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