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
d061c331
Commit
d061c331
authored
Jan 08, 2016
by
sanmit
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implemented communication
parent
a1022b8d
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
271 additions
and
18 deletions
+271
-18
bin/Trainer.py
bin/Trainer.py
+1
-0
example/communication_agent.cpp
example/communication_agent.cpp
+13
-5
example/communication_agent.py
example/communication_agent.py
+56
-0
example/hfo_example_agent.py
example/hfo_example_agent.py
+12
-2
example/mid_level_move_agent.cpp
example/mid_level_move_agent.cpp
+3
-0
hfo/hfo.py
hfo/hfo.py
+21
-4
src/HFO.cpp
src/HFO.cpp
+63
-3
src/agent.cpp
src/agent.cpp
+75
-4
src/agent.h
src/agent.h
+1
-0
src/custom_message.h
src/custom_message.h
+26
-0
No files found.
bin/Trainer.py
View file @
d061c331
...
@@ -119,6 +119,7 @@ class Trainer(object):
...
@@ -119,6 +119,7 @@ class Trainer(object):
agent_cmd
+=
' -g'
agent_cmd
+=
' -g'
if
self
.
_record
:
if
self
.
_record
:
agent_cmd
+=
' --record'
agent_cmd
+=
' --record'
# Comment next two lines to show output from agent.cpp and the server
kwargs
=
{
'stdout'
:
open
(
'/dev/null'
,
'w'
),
kwargs
=
{
'stdout'
:
open
(
'/dev/null'
,
'w'
),
'stderr'
:
open
(
'/dev/null'
,
'w'
)}
'stderr'
:
open
(
'/dev/null'
,
'w'
)}
p
=
subprocess
.
Popen
(
agent_cmd
.
split
(
' '
),
shell
=
False
,
**
kwargs
)
p
=
subprocess
.
Popen
(
agent_cmd
.
split
(
' '
),
shell
=
False
,
**
kwargs
)
...
...
example/communication_agent.cpp
View file @
d061c331
...
@@ -2,13 +2,16 @@
...
@@ -2,13 +2,16 @@
#include <vector>
#include <vector>
#include <HFO.hpp>
#include <HFO.hpp>
#include <cstdlib>
#include <cstdlib>
#include <stdio.h>
#include <math.h>
#include <iostream>
using
namespace
std
;
using
namespace
std
;
using
namespace
hfo
;
using
namespace
hfo
;
// Before running this program, first Start HFO server:
// Before running this program, first Start HFO server:
// $./bin/HFO --offense-agents 1
// $./bin/HFO --offense-agents 1
#define PI 3.14159265
int
main
(
int
argc
,
char
**
argv
)
{
int
main
(
int
argc
,
char
**
argv
)
{
int
port
=
6000
;
int
port
=
6000
;
if
(
argc
>
1
)
{
if
(
argc
>
1
)
{
...
@@ -21,19 +24,24 @@ int main(int argc, char** argv) {
...
@@ -21,19 +24,24 @@ 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
++
)
{
int
step
=
0
;
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
const
vector
<
float
>&
feature_vec
=
hfo
.
getState
();
const
vector
<
float
>&
feature_vec
=
hfo
.
getState
();
// Get any incoming communication
// Get any incoming communication
std
::
string
msg
=
hfo
.
hear
();
std
::
string
msg
=
hfo
.
hear
();
// TODO: [Sanmit] Do something with incoming communication
// Do something with incoming communication
// Perform the action
cout
<<
"HEARD: "
<<
msg
.
c_str
()
<<
endl
;
hfo
.
act
(
DASH
,
0
,
0
);
float
target_x
=
sin
((
step
%
360
)
*
PI
/
180
);
// TODO: [Sanmit] Do something with outgoing communication
float
target_y
=
cos
((
step
%
360
)
*
PI
/
180
);
hfo
.
act
(
DRIBBLE_TO
,
target_x
,
target_y
);
// 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
();
status
=
hfo
.
step
();
step
+=
2
;
}
}
}
}
hfo
.
act
(
QUIT
);
hfo
.
act
(
QUIT
);
...
...
example/communication_agent.py
0 → 100755
View file @
d061c331
#!/usr/bin/env python
# encoding: utf-8
import
sys
# First Start the server: $> bin/start.py
if
__name__
==
'__main__'
:
port
=
6000
if
len
(
sys
.
argv
)
>
1
:
port
=
int
(
sys
.
argv
[
1
])
try
:
from
hfo
import
*
except
:
print
'Failed to import hfo. To install hfo, in the HFO directory'
\
' run:
\"
pip install .
\"
'
exit
()
# Create the HFO Environment
hfo_env
=
hfo
.
HFOEnvironment
()
# Connect to the agent server on port 6000 with the specified
# feature set. See feature sets in hfo.py/hfo.hpp.
hfo_env
.
connectToAgentServer
(
port
,
HFO_Features
.
HIGH_LEVEL_FEATURE_SET
)
# Play 5 episodes
for
episode
in
xrange
(
5
):
status
=
HFO_Status
.
IN_GAME
while
status
==
HFO_Status
.
IN_GAME
:
# Grab the state features from the environment
features
=
hfo_env
.
getState
()
# Get any incoming communication
msg
=
hfo_env
.
hear
()
# Do something with incoming communication
print
'Heard: '
,
msg
# Take an action and get the current game status
hfo_env
.
act
(
HFO_Actions
.
DASH
,
20.0
,
0
)
# Do something with outgoing communication
hfo_env
.
say
(
'Message'
)
status
=
hfo_env
.
step
()
print
'Episode'
,
episode
,
'ended with'
,
# Check what the outcome of the episode was
if
status
==
HFO_Status
.
GOAL
:
print
'goal'
elif
status
==
HFO_Status
.
CAPTURED_BY_DEFENSE
:
print
'captured by defense'
elif
status
==
HFO_Status
.
OUT_OF_BOUNDS
:
print
'out of bounds'
elif
status
==
HFO_Status
.
OUT_OF_TIME
:
print
'out of time'
else
:
print
'Unknown status'
,
status
exit
()
# Cleanup when finished
hfo_env
.
cleanup
()
example/hfo_example_agent.py
View file @
d061c331
#!/usr/bin/env python
#!/usr/bin/env python
# encoding: utf-8
# encoding: utf-8
import
sys
# First Start the server: $> bin/start.py
# First Start the server: $> bin/start.py
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
port
=
6000
if
len
(
sys
.
argv
)
>
1
:
port
=
int
(
sys
.
argv
[
1
])
try
:
try
:
from
hfo
import
*
from
hfo
import
*
except
:
except
:
...
@@ -14,7 +21,7 @@ if __name__ == '__main__':
...
@@ -14,7 +21,7 @@ if __name__ == '__main__':
hfo
=
hfo
.
HFOEnvironment
()
hfo
=
hfo
.
HFOEnvironment
()
# Connect to the agent server on port 6000 with the specified
# Connect to the agent server on port 6000 with the specified
# feature set. See feature sets in hfo.py/hfo.hpp.
# feature set. See feature sets in hfo.py/hfo.hpp.
hfo
.
connectToAgentServer
(
6000
,
HFO_Features
.
HIGH_LEVEL_FEATURE_SET
)
hfo
.
connectToAgentServer
(
port
,
HFO_Features
.
HIGH_LEVEL_FEATURE_SET
)
# Play 5 episodes
# Play 5 episodes
for
episode
in
xrange
(
5
):
for
episode
in
xrange
(
5
):
status
=
HFO_Status
.
IN_GAME
status
=
HFO_Status
.
IN_GAME
...
@@ -22,7 +29,10 @@ if __name__ == '__main__':
...
@@ -22,7 +29,10 @@ if __name__ == '__main__':
# Grab the state features from the environment
# Grab the state features from the environment
features
=
hfo
.
getState
()
features
=
hfo
.
getState
()
# Take an action and get the current game status
# Take an action and get the current game status
status
=
hfo
.
act
(
HFO_Actions
.
DASH
,
20.0
,
0
)
hfo
.
act
(
HFO_Actions
.
DASH
,
20.0
,
0
)
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
:
...
...
example/mid_level_move_agent.cpp
View file @
d061c331
...
@@ -31,12 +31,15 @@ int main(int argc, char** argv) {
...
@@ -31,12 +31,15 @@ int main(int argc, char** argv) {
}
}
std
::
cout
<<
"target (x,y) = "
<<
target_x
<<
", "
<<
target_y
<<
std
::
endl
;
std
::
cout
<<
"target (x,y) = "
<<
target_x
<<
", "
<<
target_y
<<
std
::
endl
;
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
const
vector
<
float
>&
feature_vec
=
hfo
.
getState
();
const
vector
<
float
>&
feature_vec
=
hfo
.
getState
();
// 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
();
status
=
hfo
.
step
();
std
::
cout
<<
"Status: "
<<
status
<<
" (IN_GAME = "
<<
IN_GAME
<<
")
\n
"
;
}
}
}
}
hfo
.
act
(
QUIT
);
hfo
.
act
(
QUIT
);
...
...
hfo/hfo.py
View file @
d061c331
...
@@ -45,8 +45,8 @@ class HFOEnvironment(object):
...
@@ -45,8 +45,8 @@ class HFOEnvironment(object):
self
.
numFeatures
=
None
# Given by the server in handshake
self
.
numFeatures
=
None
# Given by the server in handshake
self
.
features
=
None
# The state features
self
.
features
=
None
# The state features
self
.
requested_action
=
None
# Action to execute and parameters
self
.
requested_action
=
None
# Action to execute and parameters
self
.
say_msg
=
None
# Outgoing message to say
self
.
say_msg
=
''
# Outgoing message to say
self
.
hear_msg
=
None
# Incoming heard message
self
.
hear_msg
=
''
# Incoming heard message
def
NumParams
(
self
,
action_type
):
def
NumParams
(
self
,
action_type
):
''' Returns the number of required parameters for each action type. '''
''' Returns the number of required parameters for each action type. '''
...
@@ -94,6 +94,12 @@ class HFOEnvironment(object):
...
@@ -94,6 +94,12 @@ class HFOEnvironment(object):
self
.
cleanup
()
self
.
cleanup
()
exit
(
1
)
exit
(
1
)
self
.
features
=
struct
.
unpack
(
'f'
*
self
.
numFeatures
,
state_data
)
self
.
features
=
struct
.
unpack
(
'f'
*
self
.
numFeatures
,
state_data
)
# Get first hear message
hearMsgLengthData
=
self
.
socket
.
recv
(
struct
.
calcsize
(
'I'
))
hearMsgLength
=
struct
.
unpack
(
'I'
,
hearMsgLengthData
)[
0
]
if
hearMsgLength
>
0
:
hearMsgData
=
self
.
socket
.
recv
(
struct
.
calcsize
(
'c'
)
*
hearMsgLength
)
self
.
hear_msg
=
struct
.
unpack
(
str
(
hearMsgLength
)
+
's'
,
hearMsgData
)[
0
]
def
handshakeAgentServer
(
self
,
feature_set
):
def
handshakeAgentServer
(
self
,
feature_set
):
'''Handshake with the agent's server. '''
'''Handshake with the agent's server. '''
...
@@ -144,11 +150,16 @@ class HFOEnvironment(object):
...
@@ -144,11 +150,16 @@ class HFOEnvironment(object):
# Send action and parameters
# Send action and parameters
self
.
socket
.
send
(
struct
.
pack
(
'i'
+
'f'
*
(
len
(
self
.
requested_action
)
-
1
),
self
.
socket
.
send
(
struct
.
pack
(
'i'
+
'f'
*
(
len
(
self
.
requested_action
)
-
1
),
*
self
.
requested_action
))
*
self
.
requested_action
))
# TODO: [Sanmit] Send self.say_msg
# [Sanmit] Send self.say_msg
self
.
socket
.
send
(
struct
.
pack
(
'I'
,
len
(
self
.
say_msg
)))
if
len
(
self
.
say_msg
)
>
0
:
self
.
socket
.
send
(
struct
.
pack
(
str
(
len
(
self
.
say_msg
))
+
's'
,
self
.
say_msg
))
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"
))
status
=
struct
.
unpack
(
"i"
,
data
)[
0
]
status
=
struct
.
unpack
(
"i"
,
data
)[
0
]
# 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
)
if
not
state_data
:
if
not
state_data
:
...
@@ -157,7 +168,13 @@ class HFOEnvironment(object):
...
@@ -157,7 +168,13 @@ class HFOEnvironment(object):
exit
(
1
)
exit
(
1
)
self
.
features
=
struct
.
unpack
(
'f'
*
self
.
numFeatures
,
state_data
)
self
.
features
=
struct
.
unpack
(
'f'
*
self
.
numFeatures
,
state_data
)
self
.
hear_msg
=
''
self
.
hear_msg
=
''
# TODO: [Sanmit] Receive self.hear_msg
# [Sanmit] Receive self.hear_msg
hearMsgLengthData
=
self
.
socket
.
recv
(
struct
.
calcsize
(
'I'
))
hearMsgLength
=
struct
.
unpack
(
'I'
,
hearMsgLengthData
)[
0
]
if
hearMsgLength
>
0
:
hearMsgData
=
self
.
socket
.
recv
(
struct
.
calcsize
(
'c'
)
*
hearMsgLength
)
self
.
hear_msg
=
struct
.
unpack
(
str
(
hearMsgLength
)
+
's'
,
hearMsgData
)[
0
]
return
status
return
status
def
cleanup
(
self
):
def
cleanup
(
self
):
...
...
src/HFO.cpp
View file @
d061c331
...
@@ -188,6 +188,28 @@ void HFOEnvironment::connectToAgentServer(int server_port,
...
@@ -188,6 +188,28 @@ void HFOEnvironment::connectToAgentServer(int server_port,
close
(
sockfd
);
close
(
sockfd
);
exit
(
1
);
exit
(
1
);
}
}
// Get first hear message
// Message length
uint32_t
msgLength
;
if
(
recv
(
sockfd
,
&
msgLength
,
sizeof
(
uint32_t
),
0
)
<
0
){
perror
(
"[Agent Client] ERROR recieving hear message length from socket"
);
close
(
sockfd
);
exit
(
1
);
}
// Message
if
(
msgLength
>
0
){
std
::
vector
<
char
>
hearMsgBuffer
;
hearMsgBuffer
.
resize
(
msgLength
);
if
(
recv
(
sockfd
,
&
hearMsgBuffer
[
0
],
msgLength
,
0
)
<
0
){
perror
(
"[Agent Client] ERROR recieving hear message from socket"
);
close
(
sockfd
);
exit
(
1
);
}
hear_msg
.
assign
(
&
(
hearMsgBuffer
[
0
]),
hearMsgBuffer
.
size
());
}
}
}
void
HFOEnvironment
::
handshakeAgentServer
(
feature_set_t
feature_set
)
{
void
HFOEnvironment
::
handshakeAgentServer
(
feature_set_t
feature_set
)
{
...
@@ -288,7 +310,24 @@ status_t HFOEnvironment::step() {
...
@@ -288,7 +310,24 @@ status_t HFOEnvironment::step() {
exit
(
1
);
exit
(
1
);
}
}
}
}
// TODO: [Sanmit] Send say_msg
// [Sanmit] Send say_msg
// Send message length
uint32_t
sendMsgLength
=
say_msg
.
size
();
if
(
send
(
sockfd
,
&
sendMsgLength
,
sizeof
(
uint32_t
),
0
)
<
0
){
perror
(
"[Agent Client] ERROR sending from socket"
);
close
(
sockfd
);
exit
(
1
);
}
// Send message
if
(
sendMsgLength
>
0
){
if
(
send
(
sockfd
,
say_msg
.
c_str
(),
say_msg
.
size
(),
0
)
<
0
){
perror
(
"[Agent Client] ERROR sending from socket"
);
close
(
sockfd
);
exit
(
1
);
}
}
// Clear say message buffer
say_msg
.
clear
();
say_msg
.
clear
();
// Get the game status
// Get the game status
...
@@ -298,13 +337,34 @@ status_t HFOEnvironment::step() {
...
@@ -298,13 +337,34 @@ status_t HFOEnvironment::step() {
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 recieving state features from socket"
);
perror
(
"[Agent Client] ERROR recieving state features from socket"
);
close
(
sockfd
);
close
(
sockfd
);
exit
(
1
);
exit
(
1
);
}
}
// [Sanmit] Receive comm_msg
// Clear last message
hear_msg
.
clear
();
hear_msg
.
clear
();
// TODO: [Sanmit] Receive comm_msg
// Message length
uint32_t
msgLength
;
if
(
recv
(
sockfd
,
&
msgLength
,
sizeof
(
uint32_t
),
0
)
<
0
){
perror
(
"[Agent Client] ERROR recieving hear message length from socket"
);
close
(
sockfd
);
exit
(
1
);
}
// Message
if
(
msgLength
>
0
){
std
::
vector
<
char
>
hearMsgBuffer
;
hearMsgBuffer
.
resize
(
msgLength
);
if
(
recv
(
sockfd
,
&
hearMsgBuffer
[
0
],
msgLength
,
0
)
<
0
){
perror
(
"[Agent Client] ERROR recieving hear message from socket"
);
close
(
sockfd
);
exit
(
1
);
}
hear_msg
.
assign
(
&
(
hearMsgBuffer
[
0
]),
hearMsgBuffer
.
size
());
}
return
game_status
;
return
game_status
;
}
}
src/agent.cpp
View file @
d061c331
...
@@ -29,6 +29,7 @@
...
@@ -29,6 +29,7 @@
#endif
#endif
#include "agent.h"
#include "agent.h"
#include "custom_message.h"
#include "strategy.h"
#include "strategy.h"
#include "field_analyzer.h"
#include "field_analyzer.h"
...
@@ -100,6 +101,7 @@
...
@@ -100,6 +101,7 @@
#include <rcsc/param/cmd_line_parser.h>
#include <rcsc/param/cmd_line_parser.h>
#include <iostream>
#include <iostream>
#include <fstream>
#include <sstream>
#include <sstream>
#include <string>
#include <string>
#include <cstdlib>
#include <cstdlib>
...
@@ -120,8 +122,10 @@ Agent::Agent()
...
@@ -120,8 +122,10 @@ Agent::Agent()
M_field_evaluator
(
createFieldEvaluator
()),
M_field_evaluator
(
createFieldEvaluator
()),
M_action_generator
(
createActionGenerator
()),
M_action_generator
(
createActionGenerator
()),
lastTrainerMessageTime
(
-
1
),
lastTrainerMessageTime
(
-
1
),
lastTeammateMessageTime
(
-
1
),
server_port
(
6008
),
server_port
(
6008
),
client_connected
(
false
),
client_connected
(
false
),
num_teammates
(
-
1
),
num_teammates
(
-
1
),
num_opponents
(
-
1
),
num_opponents
(
-
1
),
playing_offense
(
false
)
playing_offense
(
false
)
...
@@ -422,9 +426,39 @@ void Agent::actionImpl() {
...
@@ -422,9 +426,39 @@ void Agent::actionImpl() {
if
(
send
(
newsockfd
,
&
(
features
.
front
()),
if
(
send
(
newsockfd
,
&
(
features
.
front
()),
features
.
size
()
*
sizeof
(
float
),
0
)
<
0
)
{
features
.
size
()
*
sizeof
(
float
),
0
)
<
0
)
{
perror
(
"[Agent Server] ERROR sending state features from socket"
);
perror
(
"[Agent Server] ERROR sending state features from socket"
);
close
(
sockfd
);
exit
(
1
);
exit
(
1
);
}
}
// TODO: [Sanmit] Send the communication heard by the agent
// [Sanmit] Send the communication heard by the agent
// Hear for teammate messages and send them via socket to the HFO interface.
std
::
string
teammateMessage
=
""
;
// Received a new message
if
(
audioSensor
().
teammateMessageTime
().
cycle
()
>
lastTeammateMessageTime
){
// Receive all teammate messages
std
::
list
<
HearMessage
>
teammateMessages
=
audioSensor
().
teammateMessages
();
for
(
std
::
list
<
HearMessage
>::
iterator
msgIterator
=
teammateMessages
.
begin
();
msgIterator
!=
teammateMessages
.
end
();
msgIterator
++
){
if
((
*
msgIterator
).
unum_
!=
world
().
self
().
unum
()){
teammateMessage
=
(
*
msgIterator
).
str_
;
break
;
// For now we just take one. Remove this and concatenate messages if desired -- though technically, agents should only be able to hear one message.
}
}
}
// Send message size
uint32_t
hearMsgLength
=
teammateMessage
.
size
();
if
(
send
(
newsockfd
,
&
hearMsgLength
,
sizeof
(
uint32_t
),
0
)
<
0
){
perror
(
"[Agent Server] ERROR sending hear message length from socket"
);
close
(
sockfd
);
exit
(
1
);
}
// Send message
if
(
hearMsgLength
>
0
){
if
(
send
(
newsockfd
,
teammateMessage
.
c_str
(),
teammateMessage
.
size
(),
0
)
<
0
){
perror
(
"[Agent Server] ERROR sending hear message from socket"
);
close
(
sockfd
);
exit
(
1
);
}
}
// Get the action type
// Get the action type
action_t
action
;
action_t
action
;
...
@@ -443,8 +477,44 @@ void Agent::actionImpl() {
...
@@ -443,8 +477,44 @@ void Agent::actionImpl() {
exit
(
1
);
exit
(
1
);
}
}
}
}
// TODO: [Sanmit] Receive the outgoing communication
// [Sanmit] Receive the outgoing communication
// TODO: [Sanmit] "Say" in the actual game
// Receive message length
uint32_t
sayMsgLength
;
if
(
recv
(
newsockfd
,
&
sayMsgLength
,
sizeof
(
uint32_t
),
0
)
<
0
){
perror
(
"[Agent Server] ERROR recv size of say message from socket"
);
close
(
sockfd
);
exit
(
1
);
}
std
::
cout
<<
"[AGENT.CPP] Say message length "
<<
sayMsgLength
<<
std
::
endl
;
// Receive message
std
::
vector
<
char
>
sayMsgBuffer
;
sayMsgBuffer
.
resize
(
sayMsgLength
);
std
::
string
msgString
=
""
;
// Check message size
if
(
sayMsgLength
>
ServerParam
::
i
().
playerSayMsgSize
()){
perror
(
"[Agent Server] ERROR message size too large. Increase size by starting bin/HFO with larger --messageSize argument"
);
close
(
sockfd
);
exit
(
1
);
}
if
(
sayMsgLength
>
0
)
{
if
(
recv
(
newsockfd
,
&
sayMsgBuffer
[
0
],
sayMsgLength
,
0
)
<
0
){
perror
(
"[Agent Server] ERROR recv say message from socket"
);
close
(
sockfd
);
exit
(
1
);
}
msgString
.
assign
(
&
(
sayMsgBuffer
[
0
]),
sayMsgBuffer
.
size
());
// [Sanmit] "Say" in the actual game
addSayMessage
(
new
CustomMessage
(
msgString
));
std
::
cout
<<
"
\n\n
[AGENT SERVER] "
<<
msgString
<<
std
::
endl
;
}
if
(
action
==
SHOOT
)
{
if
(
action
==
SHOOT
)
{
const
ShootGenerator
::
Container
&
cont
=
const
ShootGenerator
::
Container
&
cont
=
...
@@ -704,7 +774,8 @@ Agent::communicationImpl()
...
@@ -704,7 +774,8 @@ Agent::communicationImpl()
{
{
if
(
M_communication
)
if
(
M_communication
)
{
{
M_communication
->
execute
(
this
);
// [Sanmit]: Turning this off since it adds default communication messages which can conflict with our comm messages.
// M_communication->execute( this );
}
}
}
}
...
...
src/agent.h
View file @
d061c331
...
@@ -79,6 +79,7 @@ protected:
...
@@ -79,6 +79,7 @@ protected:
protected:
protected:
FeatureExtractor
*
feature_extractor
;
FeatureExtractor
*
feature_extractor
;
long
lastTrainerMessageTime
;
// Last time the trainer sent a message
long
lastTrainerMessageTime
;
// Last time the trainer sent a message
long
lastTeammateMessageTime
;
// Last time a teammate sent a message
int
server_port
;
// Port to start the server on
int
server_port
;
// Port to start the server on
bool
client_connected
;
// Has the client connected and handshake?
bool
client_connected
;
// Has the client connected and handshake?
int
sockfd
,
newsockfd
;
// Server sockets
int
sockfd
,
newsockfd
;
// Server sockets
...
...
src/custom_message.h
0 → 100644
View file @
d061c331
#ifndef CUSTOM_MESSAGE_H
#define CUSTOM_MESSAGE_H
#include <rcsc/player/say_message_builder.h>
class
CustomMessage
:
public
rcsc
::
SayMessage
{
private:
std
::
string
msg
;
public:
CustomMessage
(
std
::
string
m
)
:
msg
(
m
)
{}
char
header
()
const
{
return
'm'
;
}
// Should be one (unique) character
int
length
()
const
{
return
msg
.
length
();
}
bool
toStr
(
std
::
string
&
to
)
const
{
to
+=
msg
;
return
true
;}
std
::
ostream
&
printDebug
(
std
::
ostream
&
os
)
const
{
os
<<
"[MYMSG]"
;
return
os
;}
// TODO [SANMIT]
};
#endif
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