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
731070be
Commit
731070be
authored
Jan 20, 2016
by
sanmit
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added player index to defense captures. [Interface breaking change]
parent
2687b320
Changes
17
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
121 additions
and
53 deletions
+121
-53
bin/Trainer.py
bin/Trainer.py
+2
-1
example/communication_agent.cpp
example/communication_agent.cpp
+3
-1
example/communication_agent.py
example/communication_agent.py
+14
-14
example/example_high_level_random_agent.py
example/example_high_level_random_agent.py
+1
-1
example/hfo_example_agent.cpp
example/hfo_example_agent.cpp
+3
-1
example/hfo_example_agent.py
example/hfo_example_agent.py
+2
-2
example/high_level_random_agent.cpp
example/high_level_random_agent.cpp
+23
-1
example/low_level_random_agent.cpp
example/low_level_random_agent.cpp
+3
-1
example/mid_level_dribble_agent.cpp
example/mid_level_dribble_agent.cpp
+3
-1
example/mid_level_kick_agent.cpp
example/mid_level_kick_agent.cpp
+28
-1
example/mid_level_move_agent.cpp
example/mid_level_move_agent.cpp
+3
-1
hfo/hfo.py
hfo/hfo.py
+6
-5
src/HFO.cpp
src/HFO.cpp
+11
-11
src/HFO.hpp
src/HFO.hpp
+1
-1
src/agent.cpp
src/agent.cpp
+15
-9
src/agent.h
src/agent.h
+1
-1
src/sample_player.cpp
src/sample_player.cpp
+2
-1
No files found.
bin/Trainer.py
View file @
731070be
...
@@ -220,8 +220,9 @@ class Trainer(object):
...
@@ -220,8 +220,9 @@ class Trainer(object):
self
.
_numGoalFrames
+=
self
.
_frame
-
self
.
_lastTrialStart
self
.
_numGoalFrames
+=
self
.
_frame
-
self
.
_lastTrialStart
elif
event
==
'OUT_OF_BOUNDS'
:
elif
event
==
'OUT_OF_BOUNDS'
:
self
.
_numBallsOOB
+=
1
self
.
_numBallsOOB
+=
1
elif
event
==
'CAPTURED_BY_DEFENSE'
:
elif
'CAPTURED_BY_DEFENSE'
in
event
:
self
.
_numBallsCaptured
+=
1
self
.
_numBallsCaptured
+=
1
event
=
"CAPTURED_BY_DEFENSE"
# This clears the defender number from the printout below, but it doesn't really matter here.
elif
event
==
'OUT_OF_TIME'
:
elif
event
==
'OUT_OF_TIME'
:
self
.
_numOutOfTime
+=
1
self
.
_numOutOfTime
+=
1
elif
event
==
'HFO_FINISHED'
:
elif
event
==
'HFO_FINISHED'
:
...
...
example/communication_agent.cpp
View file @
731070be
...
@@ -25,6 +25,7 @@ int main(int argc, char** argv) {
...
@@ -25,6 +25,7 @@ int main(int argc, char** argv) {
// Play 5 episodes
// Play 5 episodes
for
(
int
episode
=
0
;
;
episode
++
)
{
for
(
int
episode
=
0
;
;
episode
++
)
{
int
step
=
0
;
int
step
=
0
;
vector
<
int
>
game_status
;
status_t
status
=
IN_GAME
;
status_t
status
=
IN_GAME
;
while
(
status
==
IN_GAME
)
{
while
(
status
==
IN_GAME
)
{
// Get the vector of state features for the current state
// Get the vector of state features for the current state
...
@@ -40,7 +41,8 @@ int main(int argc, char** argv) {
...
@@ -40,7 +41,8 @@ int main(int argc, char** argv) {
// Do something with outgoing communication
// Do something with outgoing communication
hfo
.
say
(
"Message"
);
hfo
.
say
(
"Message"
);
// Advance the environment and get the game status
// Advance the environment and get the game status
status
=
hfo
.
step
();
game_status
=
hfo
.
step
();
status
=
(
status_t
)
game_status
[
0
];
step
+=
2
;
step
+=
2
;
}
}
}
}
...
...
example/communication_agent.py
View file @
731070be
...
@@ -37,20 +37,20 @@ if __name__ == '__main__':
...
@@ -37,20 +37,20 @@ if __name__ == '__main__':
hfo_env
.
act
(
HFO_Actions
.
DASH
,
20.0
,
0
)
hfo_env
.
act
(
HFO_Actions
.
DASH
,
20.0
,
0
)
# Do something with outgoing communication
# Do something with outgoing communication
hfo_env
.
say
(
'Message'
)
hfo_env
.
say
(
'Message'
)
status
=
hfo_env
.
step
()
(
status
,
playerIndex
)
=
hfo_env
.
step
()
print
'Episode'
,
episode
,
'ended with'
,
print
'Episode'
,
episode
,
'ended with'
,
# Check what the outcome of the episode was
# Check what the outcome of the episode was
if
status
==
HFO_Status
.
GOAL
:
if
status
==
HFO_Status
.
GOAL
:
print
'goal'
print
'goal'
elif
status
==
HFO_Status
.
CAPTURED_BY_DEFENSE
:
elif
status
==
HFO_Status
.
CAPTURED_BY_DEFENSE
:
print
'captured by defense'
print
'captured by defense'
,
playerIndex
elif
status
==
HFO_Status
.
OUT_OF_BOUNDS
:
elif
status
==
HFO_Status
.
OUT_OF_BOUNDS
:
print
'out of bounds'
print
'out of bounds'
elif
status
==
HFO_Status
.
OUT_OF_TIME
:
elif
status
==
HFO_Status
.
OUT_OF_TIME
:
print
'out of time'
print
'out of time'
else
:
else
:
print
'Unknown status'
,
status
print
'Unknown status'
,
status
exit
()
exit
()
# Cleanup when finished
# Cleanup when finished
hfo_env
.
cleanup
()
hfo_env
.
cleanup
()
example/example_high_level_random_agent.py
View file @
731070be
...
@@ -28,7 +28,7 @@ def play_hfo(num):
...
@@ -28,7 +28,7 @@ def play_hfo(num):
hfo_env
.
act
(
get_random_action
())
hfo_env
.
act
(
get_random_action
())
else
:
else
:
hfo_env
.
act
(
HFO_Actions
.
MOVE
)
hfo_env
.
act
(
HFO_Actions
.
MOVE
)
status
=
hfo_env
.
step
()
(
status
,
playerIndex
)
=
hfo_env
.
step
()
except
:
except
:
pass
pass
finally
:
finally
:
...
...
example/hfo_example_agent.cpp
View file @
731070be
...
@@ -17,6 +17,7 @@ int main() {
...
@@ -17,6 +17,7 @@ int main() {
hfo
.
connectToAgentServer
(
6000
,
LOW_LEVEL_FEATURE_SET
);
hfo
.
connectToAgentServer
(
6000
,
LOW_LEVEL_FEATURE_SET
);
// Play 5 episodes
// Play 5 episodes
for
(
int
episode
=
0
;
episode
<
5
;
episode
++
)
{
for
(
int
episode
=
0
;
episode
<
5
;
episode
++
)
{
vector
<
int
>
game_status
;
status_t
status
=
IN_GAME
;
status_t
status
=
IN_GAME
;
while
(
status
==
IN_GAME
)
{
while
(
status
==
IN_GAME
)
{
// Get the vector of state features for the current state
// Get the vector of state features for the current state
...
@@ -24,7 +25,8 @@ int main() {
...
@@ -24,7 +25,8 @@ int main() {
// Perform the dash
// Perform the dash
hfo
.
act
(
DASH
,
20.0
);
hfo
.
act
(
DASH
,
20.0
);
// Advance the environment and recieve current game status
// Advance the environment and recieve current game status
status
=
hfo
.
step
();
game_status
=
hfo
.
step
();
status
=
(
status_t
)
game_status
[
0
];
}
}
// Check what the outcome of the episode was
// Check what the outcome of the episode was
cout
<<
"Episode "
<<
episode
<<
" ended with status: "
;
cout
<<
"Episode "
<<
episode
<<
" ended with status: "
;
...
...
example/hfo_example_agent.py
View file @
731070be
...
@@ -27,13 +27,13 @@ if __name__ == '__main__':
...
@@ -27,13 +27,13 @@ if __name__ == '__main__':
features
=
hfo
.
getState
()
features
=
hfo
.
getState
()
# Take an action and get the current game status
# Take an action and get the current game status
hfo
.
act
(
HFO_Actions
.
DASH
,
20.0
,
0
)
hfo
.
act
(
HFO_Actions
.
DASH
,
20.0
,
0
)
hfo
.
step
()
(
status
,
playerIndex
)
=
hfo
.
step
()
print
'Episode'
,
episode
,
'ended with'
,
print
'Episode'
,
episode
,
'ended with'
,
# Check what the outcome of the episode was
# Check what the outcome of the episode was
if
status
==
HFO_Status
.
GOAL
:
if
status
==
HFO_Status
.
GOAL
:
print
'goal'
print
'goal'
elif
status
==
HFO_Status
.
CAPTURED_BY_DEFENSE
:
elif
status
==
HFO_Status
.
CAPTURED_BY_DEFENSE
:
print
'captured by defense'
print
'captured by defense'
,
playerIndex
elif
status
==
HFO_Status
.
OUT_OF_BOUNDS
:
elif
status
==
HFO_Status
.
OUT_OF_BOUNDS
:
print
'out of bounds'
print
'out of bounds'
elif
status
==
HFO_Status
.
OUT_OF_TIME
:
elif
status
==
HFO_Status
.
OUT_OF_TIME
:
...
...
example/high_level_random_agent.cpp
View file @
731070be
...
@@ -27,6 +27,7 @@ int main(int argc, char** argv) {
...
@@ -27,6 +27,7 @@ int main(int argc, char** argv) {
hfo
.
connectToAgentServer
(
port
,
HIGH_LEVEL_FEATURE_SET
);
hfo
.
connectToAgentServer
(
port
,
HIGH_LEVEL_FEATURE_SET
);
// Play 5 episodes
// Play 5 episodes
for
(
int
episode
=
0
;
;
episode
++
)
{
for
(
int
episode
=
0
;
;
episode
++
)
{
vector
<
int
>
game_status
;
status_t
status
=
IN_GAME
;
status_t
status
=
IN_GAME
;
while
(
status
==
IN_GAME
)
{
while
(
status
==
IN_GAME
)
{
// Get the vector of state features for the current state
// Get the vector of state features for the current state
...
@@ -34,7 +35,28 @@ int main(int argc, char** argv) {
...
@@ -34,7 +35,28 @@ int main(int argc, char** argv) {
// Perform the action
// Perform the action
hfo
.
act
(
get_random_high_lv_action
());
hfo
.
act
(
get_random_high_lv_action
());
// Advance the environment and get the game status
// Advance the environment and get the game status
status
=
hfo
.
step
();
game_status
=
hfo
.
step
();
status
=
(
status_t
)
game_status
[
0
];
}
// 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 "
<<
game_status
[
1
]
<<
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
);
}
}
}
}
hfo
.
act
(
QUIT
);
hfo
.
act
(
QUIT
);
...
...
example/low_level_random_agent.cpp
View file @
731070be
...
@@ -51,6 +51,7 @@ int main(int argc, char** argv) {
...
@@ -51,6 +51,7 @@ int main(int argc, char** argv) {
hfo
.
connectToAgentServer
(
port
,
LOW_LEVEL_FEATURE_SET
);
hfo
.
connectToAgentServer
(
port
,
LOW_LEVEL_FEATURE_SET
);
// Play 5 episodes
// Play 5 episodes
for
(
int
episode
=
0
;
;
episode
++
)
{
for
(
int
episode
=
0
;
;
episode
++
)
{
vector
<
int
>
game_status
;
status_t
status
=
IN_GAME
;
status_t
status
=
IN_GAME
;
while
(
status
==
IN_GAME
)
{
while
(
status
==
IN_GAME
)
{
// Get the vector of state features for the current state
// Get the vector of state features for the current state
...
@@ -58,7 +59,8 @@ int main(int argc, char** argv) {
...
@@ -58,7 +59,8 @@ int main(int argc, char** argv) {
// Perform the action and recieve the current game status
// Perform the action and recieve the current game status
hfo
.
act
(
get_random_low_lv_action
(),
arg1
,
arg2
);
hfo
.
act
(
get_random_low_lv_action
(),
arg1
,
arg2
);
status
=
hfo
.
step
();
game_status
=
hfo
.
step
();
status
=
(
status_t
)
game_status
[
0
];
}
}
}
}
};
};
example/mid_level_dribble_agent.cpp
View file @
731070be
...
@@ -24,6 +24,7 @@ int main(int argc, char** argv) {
...
@@ -24,6 +24,7 @@ int main(int argc, char** argv) {
// feature set. See manual for more information on feature sets.
// feature set. See manual for more information on feature sets.
hfo
.
connectToAgentServer
(
port
,
HIGH_LEVEL_FEATURE_SET
);
hfo
.
connectToAgentServer
(
port
,
HIGH_LEVEL_FEATURE_SET
);
for
(
int
episode
=
0
;
;
episode
++
)
{
for
(
int
episode
=
0
;
;
episode
++
)
{
vector
<
int
>
game_status
;
status_t
status
=
IN_GAME
;
status_t
status
=
IN_GAME
;
int
step
=
0
;
int
step
=
0
;
while
(
status
==
IN_GAME
)
{
while
(
status
==
IN_GAME
)
{
...
@@ -34,7 +35,8 @@ int main(int argc, char** argv) {
...
@@ -34,7 +35,8 @@ int main(int argc, char** argv) {
float
target_y
=
cos
((
step
%
360
)
*
PI
/
180
);
float
target_y
=
cos
((
step
%
360
)
*
PI
/
180
);
hfo
.
act
(
DRIBBLE_TO
,
target_x
,
target_y
);
hfo
.
act
(
DRIBBLE_TO
,
target_x
,
target_y
);
// Advance the environment and get the game status
// Advance the environment and get the game status
status
=
hfo
.
step
();
game_status
=
hfo
.
step
();
status
=
(
status_t
)
game_status
[
0
];
step
+=
2
;
step
+=
2
;
}
}
}
}
...
...
example/mid_level_kick_agent.cpp
View file @
731070be
...
@@ -22,6 +22,7 @@ int main(int argc, char** argv) {
...
@@ -22,6 +22,7 @@ int main(int argc, char** argv) {
// feature set. See manual for more information on feature sets.
// feature set. See manual for more information on feature sets.
hfo
.
connectToAgentServer
(
port
,
HIGH_LEVEL_FEATURE_SET
);
hfo
.
connectToAgentServer
(
port
,
HIGH_LEVEL_FEATURE_SET
);
for
(
int
episode
=
0
;
;
episode
++
)
{
for
(
int
episode
=
0
;
;
episode
++
)
{
vector
<
int
>
game_status
;
status_t
status
=
IN_GAME
;
status_t
status
=
IN_GAME
;
while
(
status
==
IN_GAME
)
{
while
(
status
==
IN_GAME
)
{
// Get the vector of state features for the current state
// Get the vector of state features for the current state
...
@@ -44,8 +45,34 @@ int main(int argc, char** argv) {
...
@@ -44,8 +45,34 @@ int main(int argc, char** argv) {
hfo
.
act
(
INTERCEPT
);
hfo
.
act
(
INTERCEPT
);
}
}
// Advance the environment and get the game status
// Advance the environment and get the game status
status
=
hfo
.
step
();
game_status
=
hfo
.
step
();
status
=
(
status_t
)
game_status
[
0
];
}
}
// 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 "
<<
game_status
[
1
]
<<
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
);
}
}
}
hfo
.
act
(
QUIT
);
hfo
.
act
(
QUIT
);
};
};
example/mid_level_move_agent.cpp
View file @
731070be
...
@@ -22,6 +22,7 @@ int main(int argc, char** argv) {
...
@@ -22,6 +22,7 @@ int main(int argc, char** argv) {
float
target_x
=
1.0
;
float
target_x
=
1.0
;
float
target_y
=
1.0
;
float
target_y
=
1.0
;
for
(
int
episode
=
0
;
;
episode
++
)
{
for
(
int
episode
=
0
;
;
episode
++
)
{
vector
<
int
>
game_status
;
status_t
status
=
IN_GAME
;
status_t
status
=
IN_GAME
;
if
(
episode
%
2
!=
0
)
{
if
(
episode
%
2
!=
0
)
{
target_x
*=
-
1
;
target_x
*=
-
1
;
...
@@ -35,7 +36,8 @@ int main(int argc, char** argv) {
...
@@ -35,7 +36,8 @@ int main(int argc, char** argv) {
// Perform the action
// Perform the action
hfo
.
act
(
MOVE_TO
,
target_x
,
target_y
);
hfo
.
act
(
MOVE_TO
,
target_x
,
target_y
);
// Advance the environment and get the game status
// Advance the environment and get the game status
status
=
hfo
.
step
();
game_status
=
hfo
.
step
();
status
=
(
status_t
)
game_status
[
0
];
}
}
}
}
hfo
.
act
(
QUIT
);
hfo
.
act
(
QUIT
);
...
...
hfo/hfo.py
View file @
731070be
...
@@ -117,8 +117,8 @@ class HFOEnvironment(object):
...
@@ -117,8 +117,8 @@ class HFOEnvironment(object):
# Send what we recieved
# Send what we recieved
self
.
socket
.
send
(
struct
.
pack
(
"i"
,
self
.
numFeatures
))
self
.
socket
.
send
(
struct
.
pack
(
"i"
,
self
.
numFeatures
))
# Get the current game status
# Get the current game status
data
=
self
.
socket
.
recv
(
struct
.
calcsize
(
"i"
))
data
=
self
.
socket
.
recv
(
struct
.
calcsize
(
"i"
)
*
2
)
status
=
struct
.
unpack
(
"i"
,
data
)[
0
]
status
=
struct
.
unpack
(
"i
i
"
,
data
)[
0
]
assert
status
==
HFO_Status
.
IN_GAME
,
"Status check failed"
assert
status
==
HFO_Status
.
IN_GAME
,
"Status check failed"
print
'[Agent Client] Handshake complete'
print
'[Agent Client] Handshake complete'
...
@@ -157,8 +157,9 @@ class HFOEnvironment(object):
...
@@ -157,8 +157,9 @@ class HFOEnvironment(object):
self
.
say_msg
=
''
self
.
say_msg
=
''
# Get the current game status
# Get the current game status
data
=
self
.
socket
.
recv
(
struct
.
calcsize
(
"i"
))
data
=
self
.
socket
.
recv
(
struct
.
calcsize
(
"i"
)
*
2
)
status
=
struct
.
unpack
(
"i"
,
data
)[
0
]
status
=
struct
.
unpack
(
"ii"
,
data
)[
0
]
playerIndex
=
struct
.
unpack
(
"ii"
,
data
)[
1
]
# Get the next state features
# Get the next state features
state_data
=
self
.
socket
.
recv
(
struct
.
calcsize
(
'f'
)
*
self
.
numFeatures
)
state_data
=
self
.
socket
.
recv
(
struct
.
calcsize
(
'f'
)
*
self
.
numFeatures
)
...
@@ -175,7 +176,7 @@ class HFOEnvironment(object):
...
@@ -175,7 +176,7 @@ class HFOEnvironment(object):
hearMsgData
=
self
.
socket
.
recv
(
struct
.
calcsize
(
'c'
)
*
hearMsgLength
)
hearMsgData
=
self
.
socket
.
recv
(
struct
.
calcsize
(
'c'
)
*
hearMsgLength
)
self
.
hear_msg
=
struct
.
unpack
(
str
(
hearMsgLength
)
+
's'
,
hearMsgData
)[
0
]
self
.
hear_msg
=
struct
.
unpack
(
str
(
hearMsgLength
)
+
's'
,
hearMsgData
)[
0
]
return
status
return
(
status
,
playerIndex
)
def
cleanup
(
self
):
def
cleanup
(
self
):
''' Send a quit and close the connection to the agent's server. '''
''' Send a quit and close the connection to the agent's server. '''
...
...
src/HFO.cpp
View file @
731070be
...
@@ -248,13 +248,13 @@ void HFOEnvironment::handshakeAgentServer(feature_set_t feature_set) {
...
@@ -248,13 +248,13 @@ void HFOEnvironment::handshakeAgentServer(feature_set_t feature_set) {
exit
(
1
);
exit
(
1
);
}
}
// Recieve the game status
// Recieve the game status
st
atus_t
status
;
st
d
::
vector
<
int
>
game_status
(
2
,
-
1
)
;
if
(
recv
(
sockfd
,
&
status
,
sizeof
(
status_
t
),
0
)
<
0
)
{
if
(
recv
(
sockfd
,
&
(
game_status
.
front
()),
2
*
sizeof
(
in
t
),
0
)
<
0
)
{
perror
(
"[Agent Client] ERROR rec
v
from socket"
);
perror
(
"[Agent Client] ERROR rec
eiving game status
from socket"
);
close
(
sockfd
);
close
(
sockfd
);
exit
(
1
);
exit
(
1
);
}
}
if
(
status
!=
IN_GAME
)
{
if
(
(
status_t
)
game_status
[
0
]
!=
IN_GAME
)
{
std
::
cout
<<
"[Agent Client] Handshake failed: status check."
<<
std
::
endl
;
std
::
cout
<<
"[Agent Client] Handshake failed: status check."
<<
std
::
endl
;
close
(
sockfd
);
close
(
sockfd
);
exit
(
1
);
exit
(
1
);
...
@@ -289,8 +289,8 @@ std::string HFOEnvironment::hear() {
...
@@ -289,8 +289,8 @@ std::string HFOEnvironment::hear() {
return
hear_msg
;
return
hear_msg
;
}
}
st
atus_t
HFOEnvironment
::
step
()
{
st
d
::
vector
<
int
>
HFOEnvironment
::
step
()
{
st
atus_t
game_status
;
st
d
::
vector
<
int
>
game_status
(
2
,
-
1
)
;
// Send the action_type
// Send the action_type
if
(
send
(
sockfd
,
&
requested_action
,
sizeof
(
action_t
),
0
)
<
0
)
{
if
(
send
(
sockfd
,
&
requested_action
,
sizeof
(
action_t
),
0
)
<
0
)
{
...
@@ -328,14 +328,14 @@ status_t HFOEnvironment::step() {
...
@@ -328,14 +328,14 @@ status_t HFOEnvironment::step() {
say_msg
.
clear
();
say_msg
.
clear
();
// Get the game status
// Get the game status
if
(
recv
(
sockfd
,
&
game_status
,
sizeof
(
status_
t
),
0
)
<
0
)
{
if
(
recv
(
sockfd
,
&
(
game_status
.
front
()),
2
*
sizeof
(
in
t
),
0
)
<
0
)
{
perror
(
"[Agent Client] ERROR rec
ieving
from socket"
);
perror
(
"[Agent Client] ERROR rec
eiving game status
from socket"
);
close
(
sockfd
);
close
(
sockfd
);
exit
(
1
);
exit
(
1
);
}
}
// Get the next game state
// Get the next game state
if
(
recv
(
sockfd
,
&
(
feature_vec
.
front
()),
numFeatures
*
sizeof
(
float
),
0
)
<
0
)
{
if
(
recv
(
sockfd
,
&
(
feature_vec
.
front
()),
numFeatures
*
sizeof
(
float
),
0
)
<
0
)
{
perror
(
"[Agent Client] ERROR rec
ie
ving state features from socket"
);
perror
(
"[Agent Client] ERROR rec
ei
ving state features from socket"
);
close
(
sockfd
);
close
(
sockfd
);
exit
(
1
);
exit
(
1
);
}
}
...
@@ -345,7 +345,7 @@ status_t HFOEnvironment::step() {
...
@@ -345,7 +345,7 @@ status_t HFOEnvironment::step() {
// Message length
// Message length
uint32_t
msgLength
;
uint32_t
msgLength
;
if
(
recv
(
sockfd
,
&
msgLength
,
sizeof
(
uint32_t
),
0
)
<
0
){
if
(
recv
(
sockfd
,
&
msgLength
,
sizeof
(
uint32_t
),
0
)
<
0
){
perror
(
"[Agent Client] ERROR rec
ie
ving hear message length from socket"
);
perror
(
"[Agent Client] ERROR rec
ei
ving hear message length from socket"
);
close
(
sockfd
);
close
(
sockfd
);
exit
(
1
);
exit
(
1
);
}
}
...
@@ -354,7 +354,7 @@ status_t HFOEnvironment::step() {
...
@@ -354,7 +354,7 @@ status_t HFOEnvironment::step() {
std
::
vector
<
char
>
hearMsgBuffer
;
std
::
vector
<
char
>
hearMsgBuffer
;
hearMsgBuffer
.
resize
(
msgLength
);
hearMsgBuffer
.
resize
(
msgLength
);
if
(
recv
(
sockfd
,
&
hearMsgBuffer
[
0
],
msgLength
,
0
)
<
0
){
if
(
recv
(
sockfd
,
&
hearMsgBuffer
[
0
],
msgLength
,
0
)
<
0
){
perror
(
"[Agent Client] ERROR rec
ie
ving hear message from socket"
);
perror
(
"[Agent Client] ERROR rec
ei
ving hear message from socket"
);
close
(
sockfd
);
close
(
sockfd
);
exit
(
1
);
exit
(
1
);
}
}
...
...
src/HFO.hpp
View file @
731070be
...
@@ -94,7 +94,7 @@ class HFOEnvironment {
...
@@ -94,7 +94,7 @@ class HFOEnvironment {
// Indicates the agent is done and the environment should
// Indicates the agent is done and the environment should
// progress. Returns the game status after the step
// progress. Returns the game status after the step
virtual
st
atus_t
step
();
virtual
st
d
::
vector
<
int
>
step
();
protected:
protected:
int
numFeatures
;
// The number of features in this domain
int
numFeatures
;
// The number of features in this domain
...
...
src/agent.cpp
View file @
731070be
...
@@ -364,15 +364,19 @@ FeatureExtractor* Agent::getFeatureExtractor(feature_set_t feature_set_indx,
...
@@ -364,15 +364,19 @@ FeatureExtractor* Agent::getFeatureExtractor(feature_set_t feature_set_indx,
}
}
}
}
st
atus_t
Agent
::
getGameStatus
(
const
rcsc
::
AudioSensor
&
audio_sensor
,
st
d
::
vector
<
int
>
Agent
::
getGameStatus
(
const
rcsc
::
AudioSensor
&
audio_sensor
,
long
&
lastTrainerMessageTime
)
{
long
&
lastTrainerMessageTime
)
{
std
::
vector
<
int
>
status
;
status_t
game_status
=
IN_GAME
;
status_t
game_status
=
IN_GAME
;
int
playerIndex
=
-
1
;
// Keeps track of which defender stopped the shot
if
(
audio_sensor
.
trainerMessageTime
().
cycle
()
>
lastTrainerMessageTime
)
{
if
(
audio_sensor
.
trainerMessageTime
().
cycle
()
>
lastTrainerMessageTime
)
{
const
std
::
string
&
message
=
audio_sensor
.
trainerMessage
();
const
std
::
string
&
message
=
audio_sensor
.
trainerMessage
();
bool
recognized_message
=
true
;
bool
recognized_message
=
true
;
if
(
message
.
compare
(
"GOAL"
)
==
0
)
{
if
(
message
.
compare
(
"GOAL"
)
==
0
)
{
game_status
=
GOAL
;
game_status
=
GOAL
;
}
else
if
(
message
.
compare
(
"CAPTURED_BY_DEFENSE"
)
==
0
)
{
}
else
if
(
message
.
find
(
"CAPTURED_BY_DEFENSE"
)
!=
std
::
string
::
npos
)
{
playerIndex
=
atoi
((
message
.
substr
(
message
.
find
(
"-"
)
+
1
)).
c_str
());
game_status
=
CAPTURED_BY_DEFENSE
;
game_status
=
CAPTURED_BY_DEFENSE
;
}
else
if
(
message
.
compare
(
"OUT_OF_BOUNDS"
)
==
0
)
{
}
else
if
(
message
.
compare
(
"OUT_OF_BOUNDS"
)
==
0
)
{
game_status
=
OUT_OF_BOUNDS
;
game_status
=
OUT_OF_BOUNDS
;
...
@@ -385,7 +389,9 @@ status_t Agent::getGameStatus(const rcsc::AudioSensor& audio_sensor,
...
@@ -385,7 +389,9 @@ status_t Agent::getGameStatus(const rcsc::AudioSensor& audio_sensor,
lastTrainerMessageTime
=
audio_sensor
.
trainerMessageTime
().
cycle
();
lastTrainerMessageTime
=
audio_sensor
.
trainerMessageTime
().
cycle
();
}
}
}
}
return
game_status
;
status
.
push_back
(
game_status
);
status
.
push_back
(
playerIndex
);
return
status
;
}
}
/*!
/*!
...
@@ -403,20 +409,20 @@ void Agent::actionImpl() {
...
@@ -403,20 +409,20 @@ void Agent::actionImpl() {
}
}
// Update and send the game status
// Update and send the game status
st
atus_t
game_status
=
getGameStatus
(
audioSensor
(),
lastTrainerMessageTime
);
st
d
::
vector
<
int
>
game_status
=
getGameStatus
(
audioSensor
(),
lastTrainerMessageTime
);
if
(
send
(
newsockfd
,
&
game_status
,
sizeof
(
int
),
0
)
<
0
)
{
if
(
send
(
newsockfd
,
&
(
game_status
.
front
()),
game_status
.
size
()
*
sizeof
(
int
),
0
)
<
0
)
{
perror
(
"[Agent Server] ERROR sending from socket"
);
perror
(
"[Agent Server] ERROR sending
game state
from socket"
);
close
(
sockfd
);
close
(
sockfd
);
exit
(
1
);
exit
(
1
);
}
}
// Update and send the state features
// Update and send the state features
const
std
::
vector
<
float
>&
features
=
const
std
::
vector
<
float
>&
features
=
feature_extractor
->
ExtractFeatures
(
this
->
world
());
feature_extractor
->
ExtractFeatures
(
this
->
world
());
#ifdef ELOG
#ifdef ELOG
if
(
config
().
record
())
{
if
(
config
().
record
())
{
elog
.
addText
(
Logger
::
WORLD
,
"GameStatus %d"
,
game_status
);
elog
.
addText
(
Logger
::
WORLD
,
"GameStatus %d"
,
game_status
[
0
]
);
elog
.
flush
();
elog
.
flush
();
feature_extractor
->
LogFeatures
();
feature_extractor
->
LogFeatures
();
}
}
...
...
src/agent.h
View file @
731070be
...
@@ -43,7 +43,7 @@ public:
...
@@ -43,7 +43,7 @@ public:
virtual
FieldEvaluator
::
ConstPtr
getFieldEvaluator
()
const
;
virtual
FieldEvaluator
::
ConstPtr
getFieldEvaluator
()
const
;
// Get the current game status
// Get the current game status
static
hfo
::
status_t
getGameStatus
(
const
rcsc
::
AudioSensor
&
audio_sensor
,
static
std
::
vector
<
int
>
getGameStatus
(
const
rcsc
::
AudioSensor
&
audio_sensor
,
long
&
lastTrainerMessageTime
);
long
&
lastTrainerMessageTime
);
// Returns the feature extractor corresponding to the feature_set_t
// Returns the feature extractor corresponding to the feature_set_t
...
...
src/sample_player.cpp
View file @
731070be
...
@@ -269,8 +269,9 @@ SamplePlayer::actionImpl()
...
@@ -269,8 +269,9 @@ SamplePlayer::actionImpl()
hfo
::
LOW_LEVEL_FEATURE_SET
,
num_teammates
,
num_opponents
,
playing_offense
);
hfo
::
LOW_LEVEL_FEATURE_SET
,
num_teammates
,
num_opponents
,
playing_offense
);
}
}
}
else
{
}
else
{
hfo
::
status_t
game_status
=
Agent
::
getGameStatus
(
std
::
vector
<
int
>
full_status
=
Agent
::
getGameStatus
(
audioSensor
(),
lastTrainerMessageTime
);
audioSensor
(),
lastTrainerMessageTime
);
hfo
::
status_t
game_status
=
(
hfo
::
status_t
)
full_status
[
0
];
elog
.
addText
(
Logger
::
WORLD
,
"GameStatus %d"
,
game_status
);
elog
.
addText
(
Logger
::
WORLD
,
"GameStatus %d"
,
game_status
);
elog
.
flush
();
elog
.
flush
();
feature_extractor
->
ExtractFeatures
(
this
->
world
());
feature_extractor
->
ExtractFeatures
(
this
->
world
());
...
...
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