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
3c70ad03
Commit
3c70ad03
authored
Aug 13, 2017
by
Matthew Hausknecht
Committed by
GitHub
Aug 13, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #39 from drallensmith/docs_update
Feedback enabled
parents
a02aa143
28c26906
Changes
15
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
255 additions
and
124 deletions
+255
-124
doc/manual.pdf
doc/manual.pdf
+0
-0
doc/manual.tex
doc/manual.tex
+8
-0
example/hand_coded_defense_agent.py
example/hand_coded_defense_agent.py
+1
-1
hfo/hfo.py
hfo/hfo.py
+46
-13
src/agent.cpp
src/agent.cpp
+131
-77
src/agent.h
src/agent.h
+4
-0
src/bhv_basic_move.cpp
src/bhv_basic_move.cpp
+24
-17
src/bhv_basic_move.h
src/bhv_basic_move.h
+1
-1
src/common.hpp
src/common.hpp
+4
-4
src/feature_extractor.h
src/feature_extractor.h
+4
-1
src/highlevel_feature_extractor.cpp
src/highlevel_feature_extractor.cpp
+11
-3
src/highlevel_feature_extractor.h
src/highlevel_feature_extractor.h
+4
-1
src/lowlevel_feature_extractor.cpp
src/lowlevel_feature_extractor.cpp
+12
-4
src/lowlevel_feature_extractor.h
src/lowlevel_feature_extractor.h
+4
-1
src/sample_player.cpp
src/sample_player.cpp
+1
-1
No files found.
doc/manual.pdf
View file @
3c70ad03
No preview for this file type
doc/manual.tex
View file @
3c70ad03
...
...
@@ -324,6 +324,10 @@ features.
\item
[
$
3
O
$
]
{
\textbf
{
X, Y, and Uniform Number of
Opponents
}
- For each opponent: the x-position, y-position and
uniform number of that opponent.
}
\item
[
$
+
1
$
]
{
\textbf
{
Last
\_
Action
\_
Success
\_
Possible
}
- Whether there is any chance
the last action taken was successful, either in accomplishing the
usual intent of the action or (primarily for the offense) in some other way such as
getting out of a goal-collision state. 1 for yes, -1 for no.
}
\end{enumerate}
\begin{figure}
[htp]
...
...
@@ -518,6 +522,10 @@ low-level features:
sorted by proximity to the agent.
}
\item
[
$
O
$
]
{
\textbf
{
Opponent Uniform Nums
}
[Unum] One uniform number for each opponent active in HFO,
sorted by proximity to the player.
}
\item
[
$
+
1
$
]
{
\textbf
{
Last
\_
Action
\_
Success
\_
Possible
}
[Boolean] Whether there is any chance
the last action taken was successful, either in accomplishing the
usual intent of the action or (primarily for the offense) in some other way such as getting
out of a goal-collision state.
}
\end{enumerate}
\section
{
Action Space
}
...
...
example/hand_coded_defense_agent.py
View file @
3c70ad03
...
...
@@ -19,7 +19,7 @@ except ImportError:
' run:
\"
pip install .
\"
'
)
exit
()
GOAL_POS_X
=
1.0
GOAL_POS_X
=
0.9
GOAL_POS_Y
=
0.0
# below - from hand_coded_defense_agent.cpp except LOW_KICK_DIST
...
...
hfo/hfo.py
View file @
3c70ad03
...
...
@@ -6,11 +6,12 @@ import os
hfo_lib
=
cdll
.
LoadLibrary
(
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'libhfo_c.so'
))
''' Possible feature sets '''
"""Possible feature sets"""
NUM_FEATURE_SETS
=
2
LOW_LEVEL_FEATURE_SET
,
HIGH_LEVEL_FEATURE_SET
=
list
(
range
(
NUM_FEATURE_SETS
))
''' An enum of the possible HFO actions
"""
An enum of the possible HFO actions, including:
[Low-Level] Dash(power, relative_direction)
[Low-Level] Turn(direction)
[Low-Level] Tackle(direction)
...
...
@@ -25,25 +26,50 @@ LOW_LEVEL_FEATURE_SET, HIGH_LEVEL_FEATURE_SET = list(range(NUM_FEATURE_SETS))
[High-Level] Dribble(): Offensive dribble
[High-Level] Catch(): Catch the ball (Goalie Only)
NOOP(): Do Nothing
QUIT(): Quit the game '''
QUIT(): Quit the game
"""
NUM_HFO_ACTIONS
=
20
DASH
,
TURN
,
TACKLE
,
KICK
,
KICK_TO
,
MOVE_TO
,
DRIBBLE_TO
,
INTERCEPT
,
\
MOVE
,
SHOOT
,
PASS
,
DRIBBLE
,
CATCH
,
NOOP
,
QUIT
,
REDUCE_ANGLE_TO_GOAL
,
MARK_PLAYER
,
DEFEND_GOAL
,
GO_TO_BALL
,
REORIENT
=
list
(
range
(
NUM_HFO_ACTIONS
))
ACTION_STRINGS
=
[
"Dash"
,
"Turn"
,
"Tackle"
,
"Kick"
,
"KickTo"
,
"MoveTo"
,
"DribbleTo"
,
"Intercept"
,
"Move"
,
"Shoot"
,
"Pass"
,
"Dribble"
,
"Catch"
,
"No-op"
,
"Quit"
,
"Reduce_Angle_To_Goal"
,
"Mark_Player"
,
"Defend_Goal"
,
"Go_To_Ball"
,
"Reorient"
]
''' Possible game status
DASH
,
TURN
,
TACKLE
,
KICK
,
KICK_TO
,
MOVE_TO
,
DRIBBLE_TO
,
INTERCEPT
,
MOVE
,
SHOOT
,
PASS
,
DRIBBLE
,
CATCH
,
NOOP
,
QUIT
,
REDUCE_ANGLE_TO_GOAL
,
MARK_PLAYER
,
DEFEND_GOAL
,
GO_TO_BALL
,
REORIENT
=
list
(
range
(
NUM_HFO_ACTIONS
))
ACTION_STRINGS
=
{
DASH
:
"Dash"
,
TURN
:
"Turn"
,
TACKLE
:
"Tackle"
,
KICK
:
"Kick"
,
KICK_TO
:
"KickTo"
,
MOVE_TO
:
"MoveTo"
,
DRIBBLE_TO
:
"DribbleTo"
,
INTERCEPT
:
"Intercept"
,
MOVE
:
"Move"
,
SHOOT
:
"Shoot"
,
PASS
:
"Pass"
,
DRIBBLE
:
"Dribble"
,
CATCH
:
"Catch"
,
NOOP
:
"No-op"
,
QUIT
:
"Quit"
,
REDUCE_ANGLE_TO_GOAL
:
"Reduce_Angle_To_Goal"
,
MARK_PLAYER
:
"Mark_Player"
,
DEFEND_GOAL
:
"Defend_Goal"
,
GO_TO_BALL
:
"Go_To_Ball"
,
REORIENT
:
"Reorient"
}
"""
Possible game statuses:
[IN_GAME] Game is currently active
[GOAL] A goal has been scored by the offense
[CAPTURED_BY_DEFENSE] The defense has captured the ball
[OUT_OF_BOUNDS] Ball has gone out of bounds
[OUT_OF_TIME] Trial has ended due to time limit
[SERVER_DOWN] Server is not alive
'''
"""
NUM_GAME_STATUS_STATES
=
6
IN_GAME
,
GOAL
,
CAPTURED_BY_DEFENSE
,
OUT_OF_BOUNDS
,
OUT_OF_TIME
,
SERVER_DOWN
=
list
(
range
(
NUM_GAME_STATUS_STATES
))
STATUS_STRINGS
=
[
"InGame"
,
"Goal"
,
"CapturedByDefense"
,
"OutOfBounds"
,
"OutOfTime"
,
"ServerDown"
]
''' Possible sides '''
STATUS_STRINGS
=
{
IN_GAME
:
"InGame"
,
GOAL
:
"Goal"
,
CAPTURED_BY_DEFENSE
:
"CapturedByDefense"
,
OUT_OF_BOUNDS
:
"OutOfBounds"
,
OUT_OF_TIME
:
"OutOfTime"
,
SERVER_DOWN
:
"ServerDown"
}
"""Possible sides."""
RIGHT
,
NEUTRAL
,
LEFT
=
list
(
range
(
-
1
,
2
))
class
Player
(
Structure
):
pass
...
...
@@ -109,7 +135,14 @@ class HFOEnvironment(object):
play_goalie: is this player the goalie
record_dir: record agent's states/actions/rewards to this directory
"""
hfo_lib
.
connectToServer
(
self
.
obj
,
feature_set
,
config_dir
.
encode
(
'utf-8'
),
server_port
,
server_addr
.
encode
(
'utf-8'
),
team_name
.
encode
(
'utf-8'
),
play_goalie
,
record_dir
.
encode
(
'utf-8'
))
hfo_lib
.
connectToServer
(
self
.
obj
,
feature_set
,
config_dir
.
encode
(
'utf-8'
),
server_port
,
server_addr
.
encode
(
'utf-8'
),
team_name
.
encode
(
'utf-8'
),
play_goalie
,
record_dir
.
encode
(
'utf-8'
))
def
getStateSize
(
self
):
""" Returns the number of state features """
return
hfo_lib
.
getStateSize
(
self
.
obj
)
...
...
src/agent.cpp
View file @
3c70ad03
This diff is collapsed.
Click to expand it.
src/agent.h
View file @
3c70ad03
// -*-c++-*-
#ifndef AGENT_H
#define AGENT_H
...
...
@@ -63,6 +65,7 @@ protected:
std
::
vector
<
float
>
params
;
// Parameters of current action
int
num_teammates
;
// Number of teammates
int
num_opponents
;
// Number of opponents
bool
last_action_status
;
// Recorded return status of last action
public:
inline
const
std
::
vector
<
float
>&
getState
()
{
return
state
;
}
...
...
@@ -72,6 +75,7 @@ protected:
int
getUnum
();
// Returns the uniform number of the player
inline
int
getNumTeammates
()
{
return
num_teammates
;
}
inline
int
getNumOpponents
()
{
return
num_opponents
;
}
inline
bool
getLastActionStatus
()
{
return
last_action_status
;
}
inline
void
setFeatureSet
(
hfo
::
feature_set_t
fset
)
{
feature_set
=
fset
;
}
inline
std
::
vector
<
float
>*
mutable_params
()
{
return
&
params
;
}
...
...
src/bhv_basic_move.cpp
View file @
3c70ad03
...
...
@@ -65,7 +65,7 @@ Bhv_BasicMove::execute( PlayerAgent * agent )
// tackle
if
(
Bhv_BasicTackle
(
0.8
,
80.0
).
execute
(
agent
)
)
{
return
true
;
return
true
;
}
const
WorldModel
&
wm
=
agent
->
world
();
...
...
@@ -84,16 +84,17 @@ Bhv_BasicMove::execute( PlayerAgent * agent )
{
dlog
.
addText
(
Logger
::
TEAM
,
__FILE__
": intercept"
);
Body_Intercept
().
execute
(
agent
);
bool
success
=
Body_Intercept
().
execute
(
agent
);
agent
->
setNeckAction
(
new
Neck_OffensiveInterceptNeck
()
);
return
true
;
return
success
;
}
const
Vector2D
target_point
=
Strategy
::
i
().
getPosition
(
wm
.
self
().
unum
()
);
const
double
dash_power
=
Strategy
::
get_normal_dash_power
(
wm
);
double
dist_thr
=
wm
.
ball
().
distFromSelf
()
*
0.1
;
const
BallObject
&
ball
=
wm
.
ball
();
double
dist_thr
=
ball
.
distFromSelf
()
*
0.1
;
if
(
dist_thr
<
1.0
)
dist_thr
=
1.0
;
dlog
.
addText
(
Logger
::
TEAM
,
...
...
@@ -105,21 +106,27 @@ Bhv_BasicMove::execute( PlayerAgent * agent )
agent
->
debugClient
().
setTarget
(
target_point
);
agent
->
debugClient
().
addCircle
(
target_point
,
dist_thr
);
if
(
!
Body_GoToPoint
(
target_point
,
dist_thr
,
dash_power
).
execute
(
agent
)
)
{
Body_TurnToBall
().
execute
(
agent
);
bool
success
=
false
;
if
(
Body_GoToPoint
(
target_point
,
dist_thr
,
dash_power
).
execute
(
agent
)
||
Body_TurnToBall
().
execute
(
agent
)
)
{
if
(
ball
.
posValid
()
||
wm
.
self
().
collidesWithPost
())
{
success
=
true
;
}
}
else
{
success
=
false
;
}
if
(
wm
.
existKickableOpponent
()
&&
wm
.
ball
().
distFromSelf
()
<
18.0
)
{
agent
->
setNeckAction
(
new
Neck_TurnToBall
()
);
}
else
{
agent
->
setNeckAction
(
new
Neck_TurnToBallOrScan
()
);
&&
ball
.
distFromSelf
()
<
18.0
)
{
agent
->
setNeckAction
(
new
Neck_TurnToBall
()
);
}
else
if
(
ball
.
posValid
()
)
{
agent
->
setNeckAction
(
new
Neck_TurnToBallOrScan
()
);
}
else
{
agent
->
setNeckAction
(
new
Neck_TurnToBall
()
);
}
return
true
;
return
success
;
}
src/bhv_basic_move.h
View file @
3c70ad03
...
...
@@ -36,7 +36,7 @@ public:
Bhv_BasicMove
()
{
}
bool
execute
(
rcsc
::
PlayerAgent
*
agent
);
bool
execute
(
rcsc
::
PlayerAgent
*
agent
);
private:
double
getDashPower
(
const
rcsc
::
PlayerAgent
*
agent
);
...
...
src/common.hpp
View file @
3c70ad03
...
...
@@ -33,15 +33,15 @@ enum action_t
DRIBBLE
,
// [High-Level] Dribble(): Offensive dribble
CATCH
,
// [High-Level] Catch(): Catch the ball (Goalie only!)
NOOP
,
// Do nothing
QUIT
,
// Special action to quit the game
QUIT
,
// Special action to quit the game
REDUCE_ANGLE_TO_GOAL
,
// [High-Level] Reduce_Angle_To_Goal : Reduces the shooting angle
MARK_PLAYER
,
// [High-Level] Mark_Player(opponent_unum [0,11]) : Moves to the position in between the kicker and a given player
MARK_PLAYER
,
// [High-Level] Mark_Player(opponent_unum [0,11]) : Moves to the position in between the kicker and a given player
DEFEND_GOAL
,
GO_TO_BALL
,
REORIENT
// [High-Level] Handle lost position of self/ball, misc other situations; variant of doPreprocess called in DRIBBLE
};
// Status of a HFO game
// Status of a
n
HFO game
enum
status_t
{
IN_GAME
,
// Game is currently active
...
...
@@ -176,7 +176,7 @@ inline std::string ActionToString(action_t action) {
};
/**
* Returns a string representation of a game
_
status.
* Returns a string representation of a game
status.
*/
inline
std
::
string
StatusToString
(
status_t
status
)
{
switch
(
status
)
{
...
...
src/feature_extractor.h
View file @
3c70ad03
// -*-c++-*-
#ifndef FEATURE_EXTRACTOR_H
#define FEATURE_EXTRACTOR_H
...
...
@@ -12,7 +14,8 @@ public:
virtual
~
FeatureExtractor
();
// Updated the state features stored in feature_vec
virtual
const
std
::
vector
<
float
>&
ExtractFeatures
(
const
rcsc
::
WorldModel
&
wm
)
=
0
;
virtual
const
std
::
vector
<
float
>&
ExtractFeatures
(
const
rcsc
::
WorldModel
&
wm
,
bool
last_action_status
)
=
0
;
// Record the current state
void
LogFeatures
();
...
...
src/highlevel_feature_extractor.cpp
View file @
3c70ad03
...
...
@@ -10,19 +10,21 @@ using namespace rcsc;
HighLevelFeatureExtractor
::
HighLevelFeatureExtractor
(
int
num_teammates
,
int
num_opponents
,
bool
playing_offense
)
:
FeatureExtractor
(
num_teammates
,
num_opponents
,
playing_offense
)
FeatureExtractor
(
num_teammates
,
num_opponents
,
playing_offense
)
{
assert
(
numTeammates
>=
0
);
assert
(
numOpponents
>=
0
);
numFeatures
=
num_basic_features
+
features_per_teammate
*
numTeammates
+
features_per_opponent
*
numOpponents
;
numFeatures
++
;
// action status
feature_vec
.
resize
(
numFeatures
);
}
HighLevelFeatureExtractor
::~
HighLevelFeatureExtractor
()
{}
const
std
::
vector
<
float
>&
HighLevelFeatureExtractor
::
ExtractFeatures
(
const
WorldModel
&
wm
)
{
const
std
::
vector
<
float
>&
HighLevelFeatureExtractor
::
ExtractFeatures
(
const
rcsc
::
WorldModel
&
wm
,
bool
last_action_status
)
{
featIndx
=
0
;
const
ServerParam
&
SP
=
ServerParam
::
i
();
const
SelfObject
&
self
=
wm
.
self
();
...
...
@@ -178,6 +180,12 @@ const std::vector<float>& HighLevelFeatureExtractor::ExtractFeatures(
addFeature
(
FEAT_INVALID
);
}
if
(
last_action_status
)
{
addFeature
(
FEAT_MAX
);
}
else
{
addFeature
(
FEAT_MIN
);
}
assert
(
featIndx
==
numFeatures
);
// checkFeatures();
return
feature_vec
;
...
...
src/highlevel_feature_extractor.h
View file @
3c70ad03
// -*-c++-*-
#ifndef HIGHLEVEL_FEATURE_EXTRACTOR_H
#define HIGHLEVEL_FEATURE_EXTRACTOR_H
...
...
@@ -18,7 +20,8 @@ public:
virtual
~
HighLevelFeatureExtractor
();
// Updated the state features stored in feature_vec
virtual
const
std
::
vector
<
float
>&
ExtractFeatures
(
const
rcsc
::
WorldModel
&
wm
);
virtual
const
std
::
vector
<
float
>&
ExtractFeatures
(
const
rcsc
::
WorldModel
&
wm
,
bool
last_action_status
);
protected:
// Number of features for non-player objects.
...
...
src/lowlevel_feature_extractor.cpp
View file @
3c70ad03
...
...
@@ -17,13 +17,15 @@ LowLevelFeatureExtractor::LowLevelFeatureExtractor(int num_teammates,
numFeatures
=
num_basic_features
+
features_per_player
*
(
numTeammates
+
numOpponents
);
numFeatures
+=
numTeammates
+
numOpponents
;
// Uniform numbers
numFeatures
++
;
// action state
feature_vec
.
resize
(
numFeatures
);
}
LowLevelFeatureExtractor
::~
LowLevelFeatureExtractor
()
{}
const
std
::
vector
<
float
>&
LowLevelFeatureExtractor
::
ExtractFeatures
(
const
WorldModel
&
wm
)
{
const
std
::
vector
<
float
>&
LowLevelFeatureExtractor
::
ExtractFeatures
(
const
rcsc
::
WorldModel
&
wm
,
bool
last_action_status
)
{
featIndx
=
0
;
const
ServerParam
&
SP
=
ServerParam
::
i
();
// ======================== SELF FEATURES ======================== //
...
...
@@ -197,7 +199,7 @@ const std::vector<float>& LowLevelFeatureExtractor::ExtractFeatures(
detected_teammates
++
;
}
}
// Add -
2
features for any missing teammates
// Add -
1
features for any missing teammates
for
(
int
i
=
detected_teammates
;
i
<
numTeammates
;
++
i
)
{
addFeature
(
FEAT_MIN
);
}
...
...
@@ -212,11 +214,17 @@ const std::vector<float>& LowLevelFeatureExtractor::ExtractFeatures(
detected_opponents
++
;
}
}
// Add -
2
features for any missing opponents
// Add -
1
features for any missing opponents
for
(
int
i
=
detected_opponents
;
i
<
numOpponents
;
++
i
)
{
addFeature
(
FEAT_MIN
);
}
if
(
last_action_status
)
{
addFeature
(
FEAT_MAX
);
}
else
{
addFeature
(
FEAT_MIN
);
}
assert
(
featIndx
==
numFeatures
);
checkFeatures
();
return
feature_vec
;
...
...
src/lowlevel_feature_extractor.h
View file @
3c70ad03
// -*-c++-*-
#ifndef LOWLEVEL_FEATURE_EXTRACTOR_H
#define LOWLEVEL_FEATURE_EXTRACTOR_H
...
...
@@ -12,7 +14,8 @@ public:
virtual
~
LowLevelFeatureExtractor
();
// Updated the state features stored in feature_vec
virtual
const
std
::
vector
<
float
>&
ExtractFeatures
(
const
rcsc
::
WorldModel
&
wm
);
virtual
const
std
::
vector
<
float
>&
ExtractFeatures
(
const
rcsc
::
WorldModel
&
wm
,
bool
last_action_status
);
protected:
// Number of features for non-player objects.
...
...
src/sample_player.cpp
View file @
3c70ad03
...
...
@@ -257,7 +257,7 @@ SamplePlayer::actionImpl()
lastTrainerMessageTime
=
audioSensor
().
trainerMessageTime
().
cycle
();
}
if
(
feature_extractor
!=
NULL
)
{
feature_extractor
->
ExtractFeatures
(
this
->
world
());
feature_extractor
->
ExtractFeatures
(
this
->
world
()
,
true
);
feature_extractor
->
LogFeatures
();
}
}
...
...
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