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
a98beae9
Commit
a98beae9
authored
10 years ago
by
Matthew Hausknecht
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added an agent class.
parent
f53a4d22
master
mod
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
1035 additions
and
0 deletions
+1035
-0
src/agent.cpp
src/agent.cpp
+828
-0
src/agent.h
src/agent.h
+100
-0
src/main_agent.cpp
src/main_agent.cpp
+107
-0
No files found.
src/agent.cpp
0 → 100644
View file @
a98beae9
// -*-c++-*-
/*
*Copyright:
Copyright (C) Hidehisa AKIYAMA
This code is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
This code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this code; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*EndCopyright:
*/
/////////////////////////////////////////////////////////////////////
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "agent.h"
#include "strategy.h"
#include "field_analyzer.h"
#include "action_chain_holder.h"
#include "sample_field_evaluator.h"
#include "soccer_role.h"
#include "sample_communication.h"
#include "keepaway_communication.h"
#include "bhv_penalty_kick.h"
#include "bhv_set_play.h"
#include "bhv_set_play_kick_in.h"
#include "bhv_set_play_indirect_free_kick.h"
#include "bhv_custom_before_kick_off.h"
#include "bhv_strict_check_shoot.h"
#include "view_tactical.h"
#include "intention_receive.h"
#include <rcsc/action/basic_actions.h>
#include <rcsc/action/bhv_emergency.h>
#include <rcsc/action/body_go_to_point.h>
#include <rcsc/action/body_intercept.h>
#include <rcsc/action/body_kick_one_step.h>
#include <rcsc/action/neck_scan_field.h>
#include <rcsc/action/neck_turn_to_ball_or_scan.h>
#include <rcsc/action/view_synch.h>
#include <rcsc/formation/formation.h>
#include <rcsc/action/kick_table.h>
#include <rcsc/player/intercept_table.h>
#include <rcsc/player/say_message_builder.h>
#include <rcsc/player/audio_sensor.h>
#include <rcsc/player/freeform_parser.h>
#include <rcsc/common/basic_client.h>
#include <rcsc/common/logger.h>
#include <rcsc/common/server_param.h>
#include <rcsc/common/player_param.h>
#include <rcsc/common/audio_memory.h>
#include <rcsc/common/say_message_parser.h>
// #include <rcsc/common/free_message_parser.h>
#include <rcsc/param/param_map.h>
#include <rcsc/param/cmd_line_parser.h>
#include <iostream>
#include <sstream>
#include <string>
#include <cstdlib>
using
namespace
rcsc
;
/*-------------------------------------------------------------------*/
/*!
*/
Agent
::
Agent
()
:
PlayerAgent
(),
M_communication
(),
M_field_evaluator
(
createFieldEvaluator
()
),
M_action_generator
(
createActionGenerator
()
)
{
boost
::
shared_ptr
<
AudioMemory
>
audio_memory
(
new
AudioMemory
);
M_worldmodel
.
setAudioMemory
(
audio_memory
);
//
// set communication message parser
//
addSayMessageParser
(
SayMessageParser
::
Ptr
(
new
BallMessageParser
(
audio_memory
)
)
);
addSayMessageParser
(
SayMessageParser
::
Ptr
(
new
PassMessageParser
(
audio_memory
)
)
);
addSayMessageParser
(
SayMessageParser
::
Ptr
(
new
InterceptMessageParser
(
audio_memory
)
)
);
addSayMessageParser
(
SayMessageParser
::
Ptr
(
new
GoalieMessageParser
(
audio_memory
)
)
);
addSayMessageParser
(
SayMessageParser
::
Ptr
(
new
GoalieAndPlayerMessageParser
(
audio_memory
)
)
);
addSayMessageParser
(
SayMessageParser
::
Ptr
(
new
OffsideLineMessageParser
(
audio_memory
)
)
);
addSayMessageParser
(
SayMessageParser
::
Ptr
(
new
DefenseLineMessageParser
(
audio_memory
)
)
);
addSayMessageParser
(
SayMessageParser
::
Ptr
(
new
WaitRequestMessageParser
(
audio_memory
)
)
);
addSayMessageParser
(
SayMessageParser
::
Ptr
(
new
PassRequestMessageParser
(
audio_memory
)
)
);
addSayMessageParser
(
SayMessageParser
::
Ptr
(
new
DribbleMessageParser
(
audio_memory
)
)
);
addSayMessageParser
(
SayMessageParser
::
Ptr
(
new
BallGoalieMessageParser
(
audio_memory
)
)
);
addSayMessageParser
(
SayMessageParser
::
Ptr
(
new
OnePlayerMessageParser
(
audio_memory
)
)
);
addSayMessageParser
(
SayMessageParser
::
Ptr
(
new
TwoPlayerMessageParser
(
audio_memory
)
)
);
addSayMessageParser
(
SayMessageParser
::
Ptr
(
new
ThreePlayerMessageParser
(
audio_memory
)
)
);
addSayMessageParser
(
SayMessageParser
::
Ptr
(
new
SelfMessageParser
(
audio_memory
)
)
);
addSayMessageParser
(
SayMessageParser
::
Ptr
(
new
TeammateMessageParser
(
audio_memory
)
)
);
addSayMessageParser
(
SayMessageParser
::
Ptr
(
new
OpponentMessageParser
(
audio_memory
)
)
);
addSayMessageParser
(
SayMessageParser
::
Ptr
(
new
BallPlayerMessageParser
(
audio_memory
)
)
);
addSayMessageParser
(
SayMessageParser
::
Ptr
(
new
StaminaMessageParser
(
audio_memory
)
)
);
addSayMessageParser
(
SayMessageParser
::
Ptr
(
new
RecoveryMessageParser
(
audio_memory
)
)
);
// addSayMessageParser( SayMessageParser::Ptr( new FreeMessageParser< 9 >( audio_memory ) ) );
// addSayMessageParser( SayMessageParser::Ptr( new FreeMessageParser< 8 >( audio_memory ) ) );
// addSayMessageParser( SayMessageParser::Ptr( new FreeMessageParser< 7 >( audio_memory ) ) );
// addSayMessageParser( SayMessageParser::Ptr( new FreeMessageParser< 6 >( audio_memory ) ) );
// addSayMessageParser( SayMessageParser::Ptr( new FreeMessageParser< 5 >( audio_memory ) ) );
// addSayMessageParser( SayMessageParser::Ptr( new FreeMessageParser< 4 >( audio_memory ) ) );
// addSayMessageParser( SayMessageParser::Ptr( new FreeMessageParser< 3 >( audio_memory ) ) );
// addSayMessageParser( SayMessageParser::Ptr( new FreeMessageParser< 2 >( audio_memory ) ) );
// addSayMessageParser( SayMessageParser::Ptr( new FreeMessageParser< 1 >( audio_memory ) ) );
//
// set freeform message parser
//
setFreeformParser
(
FreeformParser
::
Ptr
(
new
FreeformParser
(
M_worldmodel
)
)
);
//
// set action generators
//
// M_action_generators.push_back( ActionGenerator::Ptr( new PassGenerator() ) );
//
// set communication planner
//
M_communication
=
Communication
::
Ptr
(
new
SampleCommunication
()
);
}
/*-------------------------------------------------------------------*/
/*!
*/
Agent
::~
Agent
()
{
}
/*-------------------------------------------------------------------*/
/*!
*/
bool
Agent
::
initImpl
(
CmdLineParser
&
cmd_parser
)
{
bool
result
=
PlayerAgent
::
initImpl
(
cmd_parser
);
// read additional options
result
&=
Strategy
::
instance
().
init
(
cmd_parser
);
rcsc
::
ParamMap
my_params
(
"Additional options"
);
#if 0
std::string param_file_path = "params";
param_map.add()
( "param-file", "", ¶m_file_path, "specified parameter file" );
#endif
cmd_parser
.
parse
(
my_params
);
if
(
cmd_parser
.
count
(
"help"
)
>
0
)
{
my_params
.
printHelp
(
std
::
cout
);
return
false
;
}
if
(
cmd_parser
.
failed
()
)
{
std
::
cerr
<<
"player: ***WARNING*** detected unsuppprted options: "
;
cmd_parser
.
print
(
std
::
cerr
);
std
::
cerr
<<
std
::
endl
;
}
if
(
!
result
)
{
return
false
;
}
if
(
!
Strategy
::
instance
().
read
(
config
().
configDir
()
)
)
{
std
::
cerr
<<
"***ERROR*** Failed to read team strategy."
<<
std
::
endl
;
return
false
;
}
if
(
KickTable
::
instance
().
read
(
config
().
configDir
()
+
"/kick-table"
)
)
{
std
::
cerr
<<
"Loaded the kick table: ["
<<
config
().
configDir
()
<<
"/kick-table]"
<<
std
::
endl
;
}
return
true
;
}
/*-------------------------------------------------------------------*/
/*!
main decision
virtual method in super class
*/
void
Agent
::
actionImpl
()
{
//
// update strategy and analyzer
//
Strategy
::
instance
().
update
(
world
()
);
FieldAnalyzer
::
instance
().
update
(
world
()
);
//
// prepare action chain
//
M_field_evaluator
=
createFieldEvaluator
();
M_action_generator
=
createActionGenerator
();
ActionChainHolder
::
instance
().
setFieldEvaluator
(
M_field_evaluator
);
ActionChainHolder
::
instance
().
setActionGenerator
(
M_action_generator
);
//
// special situations (tackle, objects accuracy, intention...)
//
if
(
doPreprocess
()
)
{
dlog
.
addText
(
Logger
::
TEAM
,
__FILE__
": preprocess done"
);
return
;
}
//
// update action chain
//
ActionChainHolder
::
instance
().
update
(
world
()
);
//
// create current role
//
SoccerRole
::
Ptr
role_ptr
;
{
role_ptr
=
Strategy
::
i
().
createRole
(
world
().
self
().
unum
(),
world
()
);
if
(
!
role_ptr
)
{
std
::
cerr
<<
config
().
teamName
()
<<
": "
<<
world
().
self
().
unum
()
<<
" Error. Role is not registerd.
\n
Exit ..."
<<
std
::
endl
;
M_client
->
setServerAlive
(
false
);
return
;
}
}
//
// override execute if role accept
//
if
(
role_ptr
->
acceptExecution
(
world
()
)
)
{
role_ptr
->
execute
(
this
);
return
;
}
//
// play_on mode
//
if
(
world
().
gameMode
().
type
()
==
GameMode
::
PlayOn
)
{
role_ptr
->
execute
(
this
);
return
;
}
//
// penalty kick mode
//
if
(
world
().
gameMode
().
isPenaltyKickMode
()
)
{
dlog
.
addText
(
Logger
::
TEAM
,
__FILE__
": penalty kick"
);
Bhv_PenaltyKick
().
execute
(
this
);
return
;
}
//
// other set play mode
//
Bhv_SetPlay
().
execute
(
this
);
}
/*-------------------------------------------------------------------*/
/*!
*/
void
Agent
::
handleActionStart
()
{
}
/*-------------------------------------------------------------------*/
/*!
*/
void
Agent
::
handleActionEnd
()
{
if
(
world
().
self
().
posValid
()
)
{
#if 0
const ServerParam & SP = ServerParam::i();
//
// inside of pitch
//
// top,lower
debugClient().addLine( Vector2D( world().ourOffenseLineX(),
-SP.pitchHalfWidth() ),
Vector2D( world().ourOffenseLineX(),
-SP.pitchHalfWidth() + 3.0 ) );
// top,lower
debugClient().addLine( Vector2D( world().ourDefenseLineX(),
-SP.pitchHalfWidth() ),
Vector2D( world().ourDefenseLineX(),
-SP.pitchHalfWidth() + 3.0 ) );
// bottom,upper
debugClient().addLine( Vector2D( world().theirOffenseLineX(),
+SP.pitchHalfWidth() - 3.0 ),
Vector2D( world().theirOffenseLineX(),
+SP.pitchHalfWidth() ) );
//
debugClient().addLine( Vector2D( world().offsideLineX(),
world().self().pos().y - 15.0 ),
Vector2D( world().offsideLineX(),
world().self().pos().y + 15.0 ) );
// outside of pitch
// top,upper
debugClient().addLine( Vector2D( world().ourOffensePlayerLineX(),
-SP.pitchHalfWidth() - 3.0 ),
Vector2D( world().ourOffensePlayerLineX(),
-SP.pitchHalfWidth() ) );
// top,upper
debugClient().addLine( Vector2D( world().ourDefensePlayerLineX(),
-SP.pitchHalfWidth() - 3.0 ),
Vector2D( world().ourDefensePlayerLineX(),
-SP.pitchHalfWidth() ) );
// bottom,lower
debugClient().addLine( Vector2D( world().theirOffensePlayerLineX(),
+SP.pitchHalfWidth() ),
Vector2D( world().theirOffensePlayerLineX(),
+SP.pitchHalfWidth() + 3.0 ) );
// bottom,lower
debugClient().addLine( Vector2D( world().theirDefensePlayerLineX(),
+SP.pitchHalfWidth() ),
Vector2D( world().theirDefensePlayerLineX(),
+SP.pitchHalfWidth() + 3.0 ) );
#else
// top,lower
debugClient
().
addLine
(
Vector2D
(
world
().
ourDefenseLineX
(),
world
().
self
().
pos
().
y
-
2.0
),
Vector2D
(
world
().
ourDefenseLineX
(),
world
().
self
().
pos
().
y
+
2.0
)
);
//
debugClient
().
addLine
(
Vector2D
(
world
().
offsideLineX
(),
world
().
self
().
pos
().
y
-
15.0
),
Vector2D
(
world
().
offsideLineX
(),
world
().
self
().
pos
().
y
+
15.0
)
);
#endif
}
//
// ball position & velocity
//
dlog
.
addText
(
Logger
::
WORLD
,
"WM: BALL pos=(%lf, %lf), vel=(%lf, %lf, r=%lf, ang=%lf)"
,
world
().
ball
().
pos
().
x
,
world
().
ball
().
pos
().
y
,
world
().
ball
().
vel
().
x
,
world
().
ball
().
vel
().
y
,
world
().
ball
().
vel
().
r
(),
world
().
ball
().
vel
().
th
().
degree
()
);
dlog
.
addText
(
Logger
::
WORLD
,
"WM: SELF move=(%lf, %lf, r=%lf, th=%lf)"
,
world
().
self
().
lastMove
().
x
,
world
().
self
().
lastMove
().
y
,
world
().
self
().
lastMove
().
r
(),
world
().
self
().
lastMove
().
th
().
degree
()
);
Vector2D
diff
=
world
().
ball
().
rpos
()
-
world
().
ball
().
rposPrev
();
dlog
.
addText
(
Logger
::
WORLD
,
"WM: BALL rpos=(%lf %lf) prev_rpos=(%lf %lf) diff=(%lf %lf)"
,
world
().
ball
().
rpos
().
x
,
world
().
ball
().
rpos
().
y
,
world
().
ball
().
rposPrev
().
x
,
world
().
ball
().
rposPrev
().
y
,
diff
.
x
,
diff
.
y
);
Vector2D
ball_move
=
diff
+
world
().
self
().
lastMove
();
Vector2D
diff_vel
=
ball_move
*
ServerParam
::
i
().
ballDecay
();
dlog
.
addText
(
Logger
::
WORLD
,
"---> ball_move=(%lf %lf) vel=(%lf, %lf, r=%lf, th=%lf)"
,
ball_move
.
x
,
ball_move
.
y
,
diff_vel
.
x
,
diff_vel
.
y
,
diff_vel
.
r
(),
diff_vel
.
th
().
degree
()
);
}
/*-------------------------------------------------------------------*/
/*!
*/
void
Agent
::
handleServerParam
()
{
if
(
KickTable
::
instance
().
createTables
()
)
{
std
::
cerr
<<
world
().
teamName
()
<<
' '
<<
world
().
self
().
unum
()
<<
": "
<<
" KickTable created."
<<
std
::
endl
;
}
else
{
std
::
cerr
<<
world
().
teamName
()
<<
' '
<<
world
().
self
().
unum
()
<<
": "
<<
" KickTable failed..."
<<
std
::
endl
;
M_client
->
setServerAlive
(
false
);
}
if
(
ServerParam
::
i
().
keepawayMode
()
)
{
std
::
cerr
<<
"set Keepaway mode communication."
<<
std
::
endl
;
M_communication
=
Communication
::
Ptr
(
new
KeepawayCommunication
()
);
}
}
/*-------------------------------------------------------------------*/
/*!
*/
void
Agent
::
handlePlayerParam
()
{
}
/*-------------------------------------------------------------------*/
/*!
*/
void
Agent
::
handlePlayerType
()
{
}
/*-------------------------------------------------------------------*/
/*!
communication decision.
virtual method in super class
*/
void
Agent
::
communicationImpl
()
{
if
(
M_communication
)
{
M_communication
->
execute
(
this
);
}
}
/*-------------------------------------------------------------------*/
/*!
*/
bool
Agent
::
doPreprocess
()
{
// check tackle expires
// check self position accuracy
// ball search
// check queued intention
// check simultaneous kick
const
WorldModel
&
wm
=
this
->
world
();
dlog
.
addText
(
Logger
::
TEAM
,
__FILE__
": (doPreProcess)"
);
//
// freezed by tackle effect
//
if
(
wm
.
self
().
isFrozen
()
)
{
dlog
.
addText
(
Logger
::
TEAM
,
__FILE__
": tackle wait. expires= %d"
,
wm
.
self
().
tackleExpires
()
);
// face neck to ball
this
->
setViewAction
(
new
View_Tactical
()
);
this
->
setNeckAction
(
new
Neck_TurnToBallOrScan
()
);
return
true
;
}
//
// BeforeKickOff or AfterGoal. jump to the initial position
//
if
(
wm
.
gameMode
().
type
()
==
GameMode
::
BeforeKickOff
||
wm
.
gameMode
().
type
()
==
GameMode
::
AfterGoal_
)
{
dlog
.
addText
(
Logger
::
TEAM
,
__FILE__
": before_kick_off"
);
Vector2D
move_point
=
Strategy
::
i
().
getPosition
(
wm
.
self
().
unum
()
);
Bhv_CustomBeforeKickOff
(
move_point
).
execute
(
this
);
this
->
setViewAction
(
new
View_Tactical
()
);
return
true
;
}
//
// self localization error
//
if
(
!
wm
.
self
().
posValid
()
)
{
dlog
.
addText
(
Logger
::
TEAM
,
__FILE__
": invalid my pos"
);
Bhv_Emergency
().
execute
(
this
);
// includes change view
return
true
;
}
//
// ball localization error
//
const
int
count_thr
=
(
wm
.
self
().
goalie
()
?
10
:
5
);
if
(
wm
.
ball
().
posCount
()
>
count_thr
||
(
wm
.
gameMode
().
type
()
!=
GameMode
::
PlayOn
&&
wm
.
ball
().
seenPosCount
()
>
count_thr
+
10
)
)
{
dlog
.
addText
(
Logger
::
TEAM
,
__FILE__
": search ball"
);
this
->
setViewAction
(
new
View_Tactical
()
);
Bhv_NeckBodyToBall
().
execute
(
this
);
return
true
;
}
//
// set default change view
//
this
->
setViewAction
(
new
View_Tactical
()
);
//
// check shoot chance
//
if
(
doShoot
()
)
{
return
true
;
}
//
// check queued action
//
if
(
this
->
doIntention
()
)
{
dlog
.
addText
(
Logger
::
TEAM
,
__FILE__
": do queued intention"
);
return
true
;
}
//
// check simultaneous kick
//
if
(
doForceKick
()
)
{
return
true
;
}
//
// check pass message
//
if
(
doHeardPassReceive
()
)
{
return
true
;
}
return
false
;
}
/*-------------------------------------------------------------------*/
/*!
*/
bool
Agent
::
doShoot
()
{
const
WorldModel
&
wm
=
this
->
world
();
if
(
wm
.
gameMode
().
type
()
!=
GameMode
::
IndFreeKick_
&&
wm
.
time
().
stopped
()
==
0
&&
wm
.
self
().
isKickable
()
&&
Bhv_StrictCheckShoot
().
execute
(
this
)
)
{
dlog
.
addText
(
Logger
::
TEAM
,
__FILE__
": shooted"
);
// reset intention
this
->
setIntention
(
static_cast
<
SoccerIntention
*
>
(
0
)
);
return
true
;
}
return
false
;
}
/*-------------------------------------------------------------------*/
/*!
*/
bool
Agent
::
doForceKick
()
{
const
WorldModel
&
wm
=
this
->
world
();
if
(
wm
.
gameMode
().
type
()
==
GameMode
::
PlayOn
&&
!
wm
.
self
().
goalie
()
&&
wm
.
self
().
isKickable
()
&&
wm
.
existKickableOpponent
()
)
{
dlog
.
addText
(
Logger
::
TEAM
,
__FILE__
": simultaneous kick"
);
this
->
debugClient
().
addMessage
(
"SimultaneousKick"
);
Vector2D
goal_pos
(
ServerParam
::
i
().
pitchHalfLength
(),
0.0
);
if
(
wm
.
self
().
pos
().
x
>
36.0
&&
wm
.
self
().
pos
().
absY
()
>
10.0
)
{
goal_pos
.
x
=
45.0
;
dlog
.
addText
(
Logger
::
TEAM
,
__FILE__
": simultaneous kick cross type"
);
}
Body_KickOneStep
(
goal_pos
,
ServerParam
::
i
().
ballSpeedMax
()
).
execute
(
this
);
this
->
setNeckAction
(
new
Neck_ScanField
()
);
return
true
;
}
return
false
;
}
/*-------------------------------------------------------------------*/
/*!
*/
bool
Agent
::
doHeardPassReceive
()
{
const
WorldModel
&
wm
=
this
->
world
();
if
(
wm
.
audioMemory
().
passTime
()
!=
wm
.
time
()
||
wm
.
audioMemory
().
pass
().
empty
()
||
wm
.
audioMemory
().
pass
().
front
().
receiver_
!=
wm
.
self
().
unum
()
)
{
return
false
;
}
int
self_min
=
wm
.
interceptTable
()
->
selfReachCycle
();
Vector2D
intercept_pos
=
wm
.
ball
().
inertiaPoint
(
self_min
);
Vector2D
heard_pos
=
wm
.
audioMemory
().
pass
().
front
().
receive_pos_
;
dlog
.
addText
(
Logger
::
TEAM
,
__FILE__
": (doHeardPassReceive) heard_pos(%.2f %.2f) intercept_pos(%.2f %.2f)"
,
heard_pos
.
x
,
heard_pos
.
y
,
intercept_pos
.
x
,
intercept_pos
.
y
);
if
(
!
wm
.
existKickableTeammate
()
&&
wm
.
ball
().
posCount
()
<=
1
&&
wm
.
ball
().
velCount
()
<=
1
&&
self_min
<
20
//&& intercept_pos.dist( heard_pos ) < 3.0 ) //5.0 )
)
{
dlog
.
addText
(
Logger
::
TEAM
,
__FILE__
": (doHeardPassReceive) intercept cycle=%d. intercept"
,
self_min
);
this
->
debugClient
().
addMessage
(
"Comm:Receive:Intercept"
);
Body_Intercept
().
execute
(
this
);
this
->
setNeckAction
(
new
Neck_TurnToBall
()
);
}
else
{
dlog
.
addText
(
Logger
::
TEAM
,
__FILE__
": (doHeardPassReceive) intercept cycle=%d. go to receive point"
,
self_min
);
this
->
debugClient
().
setTarget
(
heard_pos
);
this
->
debugClient
().
addMessage
(
"Comm:Receive:GoTo"
);
Body_GoToPoint
(
heard_pos
,
0.5
,
ServerParam
::
i
().
maxDashPower
()
).
execute
(
this
);
this
->
setNeckAction
(
new
Neck_TurnToBall
()
);
}
this
->
setIntention
(
new
IntentionReceive
(
heard_pos
,
ServerParam
::
i
().
maxDashPower
(),
0.9
,
5
,
wm
.
time
()
)
);
return
true
;
}
/*-------------------------------------------------------------------*/
/*!
*/
FieldEvaluator
::
ConstPtr
Agent
::
getFieldEvaluator
()
const
{
return
M_field_evaluator
;
}
/*-------------------------------------------------------------------*/
/*!
*/
FieldEvaluator
::
ConstPtr
Agent
::
createFieldEvaluator
()
const
{
return
FieldEvaluator
::
ConstPtr
(
new
SampleFieldEvaluator
);
}
/*-------------------------------------------------------------------*/
/*!
*/
#include "actgen_cross.h"
#include "actgen_direct_pass.h"
#include "actgen_self_pass.h"
#include "actgen_strict_check_pass.h"
#include "actgen_short_dribble.h"
#include "actgen_simple_dribble.h"
#include "actgen_shoot.h"
#include "actgen_action_chain_length_filter.h"
ActionGenerator
::
ConstPtr
Agent
::
createActionGenerator
()
const
{
CompositeActionGenerator
*
g
=
new
CompositeActionGenerator
();
//
// shoot
//
g
->
addGenerator
(
new
ActGen_RangeActionChainLengthFilter
(
new
ActGen_Shoot
(),
2
,
ActGen_RangeActionChainLengthFilter
::
MAX
)
);
//
// strict check pass
//
g
->
addGenerator
(
new
ActGen_MaxActionChainLengthFilter
(
new
ActGen_StrictCheckPass
(),
1
)
);
//
// cross
//
g
->
addGenerator
(
new
ActGen_MaxActionChainLengthFilter
(
new
ActGen_Cross
(),
1
)
);
//
// direct pass
//
// g->addGenerator( new ActGen_RangeActionChainLengthFilter
// ( new ActGen_DirectPass(),
// 2, ActGen_RangeActionChainLengthFilter::MAX ) );
//
// short dribble
//
g
->
addGenerator
(
new
ActGen_MaxActionChainLengthFilter
(
new
ActGen_ShortDribble
(),
1
)
);
//
// self pass (long dribble)
//
g
->
addGenerator
(
new
ActGen_MaxActionChainLengthFilter
(
new
ActGen_SelfPass
(),
1
)
);
//
// simple dribble
//
// g->addGenerator( new ActGen_RangeActionChainLengthFilter
// ( new ActGen_SimpleDribble(),
// 2, ActGen_RangeActionChainLengthFilter::MAX ) );
return
ActionGenerator
::
ConstPtr
(
g
);
}
This diff is collapsed.
Click to expand it.
src/agent.h
0 → 100644
View file @
a98beae9
// -*-c++-*-
/*
*Copyright:
Copyright (C) Hidehisa AKIYAMA
This code is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
This code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this code; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*EndCopyright:
*/
/////////////////////////////////////////////////////////////////////
#ifndef AGENT_H
#define AGENT_H
#include "action_generator.h"
#include "field_evaluator.h"
#include "communication.h"
#include <rcsc/player/player_agent.h>
#include <vector>
class
Agent
:
public
rcsc
::
PlayerAgent
{
private:
Communication
::
Ptr
M_communication
;
FieldEvaluator
::
ConstPtr
M_field_evaluator
;
ActionGenerator
::
ConstPtr
M_action_generator
;
public:
Agent
();
virtual
~
Agent
();
protected:
/*!
You can override this method.
But you must call PlayerAgent::initImpl() in this method.
*/
virtual
bool
initImpl
(
rcsc
::
CmdLineParser
&
cmd_parser
);
//! main decision
virtual
void
actionImpl
();
//! communication decision
virtual
void
communicationImpl
();
virtual
void
handleActionStart
();
virtual
void
handleActionEnd
();
virtual
void
handleServerParam
();
virtual
void
handlePlayerParam
();
virtual
void
handlePlayerType
();
virtual
FieldEvaluator
::
ConstPtr
createFieldEvaluator
()
const
;
virtual
ActionGenerator
::
ConstPtr
createActionGenerator
()
const
;
private:
bool
doPreprocess
();
bool
doShoot
();
bool
doForceKick
();
bool
doHeardPassReceive
();
public:
virtual
FieldEvaluator
::
ConstPtr
getFieldEvaluator
()
const
;
};
#endif
This diff is collapsed.
Click to expand it.
src/main_agent.cpp
0 → 100644
View file @
a98beae9
// -*-c++-*-
/*
*Copyright:
Copyright (C) Hidehisa AKIYAMA
This code is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
This code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this code; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*EndCopyright:
*/
/////////////////////////////////////////////////////////////////////
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "agent.h"
#include <rcsc/common/basic_client.h>
#include <iostream>
#include <cstdlib> // exit
#include <cerrno> // errno
#include <cstring> // strerror
#include <csignal> // sigaction
namespace
{
Agent
agent
;
/*-------------------------------------------------------------------*/
void
sig_exit_handle
(
int
)
{
std
::
cerr
<<
"Killed. Exiting..."
<<
std
::
endl
;
agent
.
finalize
();
std
::
exit
(
EXIT_FAILURE
);
}
}
/*-------------------------------------------------------------------*/
int
main
(
int
argc
,
char
**
argv
)
{
struct
sigaction
sig_action
;
sig_action
.
sa_handler
=
&
sig_exit_handle
;
sig_action
.
sa_flags
=
0
;
if
(
sigaction
(
SIGINT
,
&
sig_action
,
NULL
)
!=
0
||
sigaction
(
SIGTERM
,
&
sig_action
,
NULL
)
!=
0
||
sigaction
(
SIGHUP
,
&
sig_action
,
NULL
)
!=
0
)
/*if ( signal(SIGINT, &sigExitHandle) == SIG_ERR
|| signal(SIGTERM, &sigExitHandle) == SIG_ERR
|| signal(SIGHUP, &sigExitHandle) == SIG_ERR )*/
{
std
::
cerr
<<
__FILE__
<<
": "
<<
__LINE__
<<
": could not set signal handler: "
<<
std
::
strerror
(
errno
)
<<
std
::
endl
;
std
::
exit
(
EXIT_FAILURE
);
}
rcsc
::
BasicClient
client
;
if
(
!
agent
.
init
(
&
client
,
argc
,
argv
)
)
{
return
EXIT_FAILURE
;
}
/*
You should add your copyright message here.
*/
// std::cout << "*****************************************************************\n"
// << " This program is modified by <Team Name>\n"
// << " Copyright 20xx. <Your name>.\n"
// << " <Affiliation>\n"
// << " All rights reserved.\n"
// << "*****************************************************************\n"
// << std::flush;
/*
Do NOT remove the following copyright notice!
*/
std
::
cout
<<
"*****************************************************************
\n
"
<<
" This program is based on agent2d created by Hidehisa Akiyama.
\n
"
<<
" Copyright 2006 - 2011. Hidehisa Akiyama and Hiroki Shimora.
\n
"
<<
" All rights reserved.
\n
"
<<
"*****************************************************************
\n
"
<<
std
::
flush
;
client
.
run
(
&
agent
);
return
EXIT_SUCCESS
;
}
This diff is collapsed.
Click to expand it.
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