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
260c2416
Commit
260c2416
authored
Jul 15, 2017
by
drallensmith
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'randomization' into add_preprocess_action - bring in improvements, avoid rebase
parents
3ec6cfef
b06bf087
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
60 additions
and
16 deletions
+60
-16
example/high_level_custom_agent.py
example/high_level_custom_agent.py
+6
-6
example/python_agents_3v3.sh
example/python_agents_3v3.sh
+2
-2
hfo/hfo.py
hfo/hfo.py
+12
-0
hfo/hfo_c_wrapper.h
hfo/hfo_c_wrapper.h
+2
-0
src/HFO.cpp
src/HFO.cpp
+8
-0
src/HFO.hpp
src/HFO.hpp
+6
-0
src/agent.cpp
src/agent.cpp
+8
-8
src/agent.h
src/agent.h
+4
-0
tests/test_with_server.py
tests/test_with_server.py
+6
-0
tests/test_with_server_fullstate.py
tests/test_with_server_fullstate.py
+6
-0
No files found.
example/high_level_custom_agent.py
View file @
260c2416
...
...
@@ -68,8 +68,6 @@ def main():
help
=
"If doing HFO --record"
)
parser
.
add_argument
(
'--rdir'
,
type
=
str
,
default
=
'log/'
,
help
=
"Set directory to use if doing --record"
)
parser
.
add_argument
(
'--numTeammates'
,
type
=
int
,
default
=
0
)
parser
.
add_argument
(
'--numOpponents'
,
type
=
int
,
default
=
1
)
args
=
parser
.
parse_args
()
if
args
.
seed
:
random
.
seed
(
args
.
seed
)
...
...
@@ -83,12 +81,14 @@ def main():
hfo_env
.
connectToServer
(
hfo
.
HIGH_LEVEL_FEATURE_SET
,
'bin/teams/base/config/formations-dt'
,
args
.
port
,
'localhost'
,
'base_left'
,
False
)
num_teammates
=
hfo_env
.
getNumTeammates
()
#num_opponents = hfo_env.getNumOpponents()
if
args
.
seed
:
if
(
args
.
rand_pass
and
(
args
.
numT
eammates
>
1
))
or
(
args
.
epsilon
>
0
):
if
(
args
.
rand_pass
and
(
num_t
eammates
>
1
))
or
(
args
.
epsilon
>
0
):
print
(
"Python randomization seed: {0:d}"
.
format
(
args
.
seed
))
else
:
print
(
"Python randomization seed useless without --rand-pass w/teammates or --epsilon >0"
)
if
args
.
rand_pass
and
(
args
.
numT
eammates
>
1
):
print
(
"Python randomization seed useless without --rand-pass w/
2+
teammates or --epsilon >0"
)
if
args
.
rand_pass
and
(
num_t
eammates
>
1
):
print
(
"Randomizing order of checking for a pass"
)
if
args
.
epsilon
>
0
:
print
(
"Using epsilon {0:n}"
.
format
(
args
.
epsilon
))
...
...
@@ -108,7 +108,7 @@ def main():
hfo_env
.
act
(
hfo
.
DRIBBLE
)
num_eps
+=
1
else
:
get_action
(
state
,
hfo_env
,
args
.
numT
eammates
,
args
.
rand_pass
)
get_action
(
state
,
hfo_env
,
num_t
eammates
,
args
.
rand_pass
)
num_had_ball
+=
1
else
:
hfo_env
.
act
(
hfo
.
MOVE
)
...
...
example/python_agents_3v3.sh
View file @
260c2416
...
...
@@ -3,9 +3,9 @@
./bin/HFO
--offense-agents
=
2
--defense-npcs
=
3
--offense-npcs
=
1
--trials
20
--headless
&
sleep
5
# -x is needed to skip first line - otherwise whatever default python version is will run
python2.7
-x
./example/high_level_custom_agent.py
--
numTeammates
=
2
--numOpponents
=
3
--
port
6000 &> agent1.txt &
python2.7
-x
./example/high_level_custom_agent.py
--port
6000 &> agent1.txt &
sleep
5
python3
-x
./example/high_level_custom_agent.py
--
numTeammates
=
2
--numOpponents
=
3
--
port
6000 &> agent2.txt &
python3
-x
./example/high_level_custom_agent.py
--port
6000 &> agent2.txt &
# The magic line
# $$ holds the PID for this script
...
...
hfo/hfo.py
View file @
260c2416
...
...
@@ -79,6 +79,10 @@ hfo_lib.statusToString.argtypes = [c_int]
hfo_lib
.
statusToString
.
restype
=
c_char_p
hfo_lib
.
getUnum
.
argtypes
=
[
c_void_p
]
hfo_lib
.
getUnum
.
restype
=
c_int
hfo_lib
.
getNumTeammates
.
argtypes
=
[
c_void_p
]
hfo_lib
.
getNumTeammates
.
restype
=
c_int
hfo_lib
.
getNumOpponents
.
argtypes
=
[
c_void_p
]
hfo_lib
.
getNumOpponents
.
restype
=
c_int
class
HFOEnvironment
(
object
):
def
__init__
(
self
):
...
...
@@ -154,3 +158,11 @@ class HFOEnvironment(object):
def
getUnum
(
self
):
""" Return the uniform number of the agent """
return
hfo_lib
.
getUnum
(
self
.
obj
)
def
getNumTeammates
(
self
):
""" Returns the number of teammates of the agent """
return
hfo_lib
.
getNumTeammates
(
self
.
obj
)
def
getNumOpponents
(
self
):
""" Returns the number of opponents of the agent """
return
hfo_lib
.
getNumOpponents
(
self
.
obj
)
hfo/hfo_c_wrapper.h
View file @
260c2416
...
...
@@ -48,6 +48,8 @@ extern "C" {
return
StatusToString
(
status
).
c_str
();
}
int
getUnum
(
hfo
::
HFOEnvironment
*
hfo
)
{
return
hfo
->
getUnum
();}
int
getNumTeammates
(
hfo
::
HFOEnvironment
*
hfo
)
{
return
hfo
->
getNumTeammates
();}
int
getNumOpponents
(
hfo
::
HFOEnvironment
*
hfo
)
{
return
hfo
->
getNumOpponents
();}
}
#endif
src/HFO.cpp
View file @
260c2416
...
...
@@ -115,6 +115,14 @@ int HFOEnvironment::getUnum() {
return
agent
->
getUnum
();
}
int
HFOEnvironment
::
getNumTeammates
()
{
return
agent
->
getNumTeammates
();
}
int
HFOEnvironment
::
getNumOpponents
()
{
return
agent
->
getNumOpponents
();
}
Player
HFOEnvironment
::
playerOnBall
()
{
return
agent
->
getPlayerOnBall
();
}
...
...
src/HFO.hpp
View file @
260c2416
...
...
@@ -49,6 +49,12 @@ class HFOEnvironment {
// Returns the uniform number of the player
virtual
int
getUnum
();
// Returns the number of teammates
virtual
int
getNumTeammates
();
// Returns the number of opponents
virtual
int
getNumOpponents
();
// Get the current player holding the ball
virtual
Player
playerOnBall
();
...
...
src/agent.cpp
View file @
260c2416
...
...
@@ -212,16 +212,16 @@ bool Agent::initImpl(CmdLineParser & cmd_parser) {
}
FeatureExtractor
*
Agent
::
getFeatureExtractor
(
feature_set_t
feature_set_indx
,
int
num
_t
eammates
,
int
num
_o
pponents
,
int
num
T
eammates
,
int
num
O
pponents
,
bool
playing_offense
)
{
switch
(
feature_set_indx
)
{
case
LOW_LEVEL_FEATURE_SET
:
return
new
LowLevelFeatureExtractor
(
num
_teammates
,
num_o
pponents
,
return
new
LowLevelFeatureExtractor
(
num
Teammates
,
numO
pponents
,
playing_offense
);
break
;
case
HIGH_LEVEL_FEATURE_SET
:
return
new
HighLevelFeatureExtractor
(
num
_teammates
,
num_o
pponents
,
return
new
HighLevelFeatureExtractor
(
num
Teammates
,
numO
pponents
,
playing_offense
);
break
;
default:
...
...
@@ -339,9 +339,9 @@ Agent::ProcessTrainerMessages()
hfo
::
Config
hfo_config
;
if
(
hfo
::
ParseConfig
(
message
,
hfo_config
))
{
bool
playing_offense
=
world
().
ourSide
()
==
rcsc
::
LEFT
;
int
num_teammates
=
playing_offense
?
num_teammates
=
playing_offense
?
hfo_config
.
num_offense
-
1
:
hfo_config
.
num_defense
-
1
;
int
num_opponents
=
playing_offense
?
num_opponents
=
playing_offense
?
hfo_config
.
num_defense
:
hfo_config
.
num_offense
;
feature_extractor
=
getFeatureExtractor
(
feature_set
,
num_teammates
,
num_opponents
,
playing_offense
);
...
...
src/agent.h
View file @
260c2416
...
...
@@ -61,6 +61,8 @@ protected:
std
::
string
say_msg
,
hear_msg
;
// Messages to/from teammates
hfo
::
action_t
requested_action
;
// Currently requested action
std
::
vector
<
float
>
params
;
// Parameters of current action
int
num_teammates
;
// Number of teammates
int
num_opponents
;
// Number of opponents
public:
inline
const
std
::
vector
<
float
>&
getState
()
{
return
state
;
}
...
...
@@ -68,6 +70,8 @@ protected:
inline
const
hfo
::
Player
&
getPlayerOnBall
()
{
return
player_on_ball
;
}
inline
const
std
::
string
&
getHearMsg
()
{
return
hear_msg
;
}
int
getUnum
();
// Returns the uniform number of the player
inline
int
getNumTeammates
()
{
return
num_teammates
;
}
inline
int
getNumOpponents
()
{
return
num_opponents
;
}
inline
void
setFeatureSet
(
hfo
::
feature_set_t
fset
)
{
feature_set
=
fset
;
}
inline
std
::
vector
<
float
>*
mutable_params
()
{
return
&
params
;
}
...
...
tests/test_with_server.py
View file @
260c2416
...
...
@@ -53,6 +53,12 @@ def test_with_server():
print
(
"My unum is {!s}"
.
format
(
my_unum
))
num_teammates
=
hfo_env
.
getNumTeammates
()
assert
(
num_teammates
==
2
),
"Wrong num teammates ({!r})"
.
format
(
num_teammates
)
num_opponents
=
hfo_env
.
getNumOpponents
()
assert
(
num_opponents
==
2
),
"Wrong num opponents ({!r})"
.
format
(
num_opponents
)
had_ok_unum
=
False
had_ok_unum_set_my_side
=
set
()
had_ok_unum_set_their_side
=
set
();
...
...
tests/test_with_server_fullstate.py
View file @
260c2416
...
...
@@ -54,6 +54,12 @@ def test_with_server():
print
(
"My unum is {!s}"
.
format
(
my_unum
))
num_teammates
=
hfo_env
.
getNumTeammates
()
assert
(
num_teammates
==
2
),
"Wrong num teammates ({!r})"
.
format
(
num_teammates
)
num_opponents
=
hfo_env
.
getNumOpponents
()
assert
(
num_opponents
==
2
),
"Wrong num opponents ({!r})"
.
format
(
num_opponents
)
had_ok_unum
=
False
had_ok_unum_set_my_side
=
set
()
had_ok_unum_set_their_side
=
set
();
...
...
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