LIBRCSC Docs
Documentation for HELIOS's BASE LIBRCSC library for RoboCup 2D Simulation League.
All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
coach_world_model.h
Go to the documentation of this file.
1// -*-c++-*-
2
8/*
9 *Copyright:
10
11 Copyright (C) Hidehisa AKIYAMA
12
13 This code is free software; you can redistribute it and/or
14 modify it under the terms of the GNU Lesser General Public
15 License as published by the Free Software Foundation; either
16 version 3 of the License, or (at your option) any later version.
17
18 This library is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 Lesser General Public License for more details.
22
23 You should have received a copy of the GNU Lesser General Public
24 License along with this library; if not, write to the Free Software
25 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26
27 *EndCopyright:
28 */
29
31
32#ifndef RCSC_COACH_COACH_WORLD_MODEL_H
33#define RCSC_COACH_COACH_WORLD_MODEL_H
34
39#include <rcsc/clang/types.h>
40#include <rcsc/game_mode.h>
41#include <rcsc/game_time.h>
42#include <rcsc/types.h>
43
44#include <iostream>
45#include <string>
46#include <vector>
47#include <list>
48
49namespace rcsc {
50
51class AudioMemory;
52class CoachVisualSensor;
53
59private:
60
62 int M_client_version;
63
64 //
65 // game info
66 //
67
69 GameTime M_time;
71 GameTime M_see_time;
72
74 SideID M_our_side;
75
76 std::string M_our_team_name;
77 std::string M_their_team_name;
78
79 GameTime M_last_set_play_start_time;
80 int M_setplay_count;
81
83 GameMode M_game_mode;
84
85 GameTime M_training_time;
86
88 std::shared_ptr< AudioMemory > M_audio_memory;
89
90 //
91 // objects
92 //
93
94 CoachWorldState::Ptr M_current_state;
95 CoachWorldState::Ptr M_previous_state;
96
97 CoachWorldState::List M_state_list;
98 CoachWorldState::Map M_state_map;
99
100 SideID M_last_kicker_side;
101 int M_last_kicker_unum;
102
103 GameTime M_pass_time;
104 int M_passer_unum;
105 int M_receiver_unum;
106 Vector2D M_pass_start_pos;
107 Vector2D M_pass_receive_pos;
108
109 //
110 // player type management
111 //
112
114 PlayerTypeAnalyzer M_player_type_analyzer;
115
117 std::vector< int > M_available_player_type_id;
118
119 int M_our_substitute_count;
120 int M_their_substitute_count;
121
122 int M_our_player_type_id[11];
123 int M_their_player_type_id[11];
124
126 std::vector< int > M_our_player_type_used_count;
128 std::vector< int > M_their_player_type_used_count;
129
130 //
131 // card information
132 //
133
134 Card M_our_card[11];
135 Card M_their_card[11];
136
137 //
138 // coach language management
139 //
140
141 long M_last_playon_start;
142
143 long M_clang_capacity_update_time;
144 int M_clang_capacity[CLANG_MAX_TYPE]; // the number of available message for each message type
145
146 int M_freeform_allowed_count;
147 int M_freeform_send_count;
148
149 // not used
150 CoachWorldModel( const CoachWorldModel & ) = delete;
151 CoachWorldModel & operator=( const CoachWorldModel & ) = delete;
152
153public:
158
165 void init( const std::string & team_name,
166 const SideID side,
167 const int client_version );
168
174 void setAudioMemory( std::shared_ptr< AudioMemory > memory );
175
180 const AudioMemory & audioMemory() const
181 {
182 return *M_audio_memory;
183 }
184
190
196
197
203 void setTeamName( const SideID side,
204 const std::string & name );
205
212 void changePlayerType( const SideID side,
213 const int unum,
214 const int type );
215
222 void setCard( const SideID side,
223 const int unum,
224 const Card card );
225
231 void updateGameMode( const GameMode & game_mode,
232 const GameTime & current );
233
239 void updateAfterSeeGlobal( const CoachVisualSensor & see_global,
240 const GameTime & current );
241
246 void updateJustBeforeDecision( const GameTime & current );
247
248
253 void updateAll( const rcg::DispInfoT & disp );
254
255private:
256
260 void updateCLangCapacity();
261
266 void updateTeamNames( const CoachVisualSensor & see_global );
267
271 void updatePlayerType();
272
276 void updateLastKicker();
277
281 void updateLastPasser();
282
283 //
284 //
285 //
286
291 void updateGameMode( const rcg::DispInfoT & disp );
292
297 void updateState( const rcg::DispInfoT & disp,
298 const GameTime & current );
299
304 void updateTeamNames( const rcg::DispInfoT & disp );
305
310 void updatePlayerType( const rcg::DispInfoT & disp );
311
316 void updateCard( const rcg::DispInfoT & disp );
317
318public:
319
324 void setTrainingTime( const GameTime & t )
325 {
326 M_training_time = t;
327 }
328
333 void decCLangCapacity( const CLangType type );
334
339
344 int clientVersion() const
345 {
346 return M_client_version;
347 }
348
354 {
355 return M_our_side;
356 }
357
363 {
364 return ( M_our_side == RIGHT ? LEFT : RIGHT );
365 }
366
371 const std::string & ourTeamName() const
372 {
373 return M_our_team_name;
374 }
375
380 const std::string & theirTeamName() const
381 {
382 return M_their_team_name;
383 }
384
389 const std::string & teamNameLeft() const
390 {
391 return ( M_our_side == RIGHT
392 ? M_their_team_name
393 : M_our_team_name );
394 }
395
400 const std::string & teamNameRight() const
401 {
402 return ( M_our_side == RIGHT
403 ? M_our_team_name
404 : M_their_team_name );
405 }
406
411 const GameTime & time() const
412 {
413 return M_time;
414 }
415
420 const GameTime & seeTime() const
421 {
422 return M_see_time;
423 }
424
429 const GameTime & lastSetPlayStartTime() const { return M_last_set_play_start_time; }
430
435 int getSetPlayCount() const { return M_setplay_count; }
436
441 const GameMode & gameMode() const
442 {
443 return M_game_mode;
444 }
445
450 const GameTime & trainingTime() const
451 {
452 return M_training_time;
453 }
454
460 {
461 return *M_current_state;
462 }
463
469 {
470 return M_current_state;
471 }
472
477 const CoachWorldState::List & stateList() const
478 {
479 return M_state_list;
480 }
481
486 const CoachWorldState::Map & stateMap() const
487 {
488 return M_state_map;
489 }
490
497 {
498 if ( time < 0 )
499 {
500 return M_current_state;
501 }
502
503 CoachWorldState::Map::const_iterator it = M_state_map.find( GameTime( time, 0 ) );
504 if ( it == M_state_map.end() )
505 {
507 }
508 return it->second;
509 }
510
517 {
518 if ( time.cycle() < 0 )
519 {
520 return M_current_state;
521 }
522
523 CoachWorldState::Map::const_iterator it = M_state_map.find( time );
524 if ( it == M_state_map.end() )
525 {
527 }
528 return it->second;
529 }
530
535 const CoachBallObject & ball() const
536 {
537 return M_current_state->ball();
538 }
539
545 {
546 return M_current_state->getBallStatus();
547 }
548
554 {
555 return M_current_state->allPlayers();
556 }
557
563 {
564 return ( M_our_side == RIGHT
565 ? M_current_state->opponents()
566 : M_current_state->teammates() );
567 }
568
574 {
575 return ( M_our_side == RIGHT
576 ? M_current_state->teammates()
577 : M_current_state->opponents() );
578 }
579
585 {
586 return M_current_state->teammates();
587 }
588
594 {
595 return M_current_state->opponents();
596 }
597
603 const CoachPlayerObject * teammate( const int unum ) const
604 {
605 return M_current_state->teammate( unum );
606 }
607
613 const CoachPlayerObject * opponent( const int unum ) const
614 {
615 return M_current_state->opponent( unum );
616 }
617
623 {
624 return M_last_kicker_side;
625 }
626
631 int lastKickerUnum() const
632 {
633 return M_last_kicker_unum;
634 }
635
640 const GameTime & passTime() const
641 {
642 return M_pass_time;
643 }
644
649 int passerUnum() const
650 {
651 return M_passer_unum;
652 }
653
658 int receiverUnum() const
659 {
660 return M_receiver_unum;
661 }
662
667 const Vector2D & passStartPos() const
668 {
669 return M_pass_start_pos;
670 }
671
676 const Vector2D & passReceivePos() const
677 {
678 return M_pass_receive_pos;
679 }
680
681 //
682 // player type information
683 //
684
689 const std::vector< int > & availablePlayerTypeId() const
690 {
691 return M_available_player_type_id;
692 }
693
700 bool canSubstitute( const int unum,
701 const int type ) const;
702
707 int substituteCount( const SideID side ) const
708 {
709 return ( M_our_side == side
710 || ( M_our_side == NEUTRAL
711 && side == LEFT )
712 ? M_our_substitute_count
713 : M_their_substitute_count );
714 }
715
721 {
722 return M_our_substitute_count;
723 }
724
730 {
731 return M_their_substitute_count;
732 }
733
734
741 int playerTypeId( const SideID side,
742 const int unum ) const;
743
749 int ourPlayerTypeId( const int unum ) const
750 {
751 return playerTypeId( ourSide(), unum );
752 }
753
759 int theirPlayerTypeId( const int unum ) const
760 {
761 return playerTypeId( theirSide(), unum );
762 }
763
769 const std::vector< int > & playerTypeUsedCount( const SideID side ) const
770 {
771 return ( ourSide() == side
772 || ( ourSide() == NEUTRAL
773 && side == LEFT )
774 ? M_our_player_type_used_count
775 : M_their_player_type_used_count );
776 }
777
782 const std::vector< int > & ourPlayerTypeUsedCount() const
783 {
784 return M_our_player_type_used_count;
785 }
786
791 const std::vector< int > & theirPlayerTypeUsedCount() const
792 {
793 return M_their_player_type_used_count;
794 }
795
796
797 //
798 // card information
799 //
800
807 bool isYellowCarded( const SideID side,
808 const int unum ) const;
809
810
817 bool isRedCarded( const SideID side,
818 const int unum ) const;
819
825 bool isTeammateYellowCarded( const int unum ) const
826 {
827 return isYellowCarded( ourSide(), unum );
828 }
829
835 bool isTeammateRedCarded( const int unum ) const
836 {
837 return isRedCarded( ourSide(), unum );
838 }
839
845 bool isOpponentYellowarded( const int unum ) const
846 {
847 return isYellowCarded( theirSide(), unum );
848 }
849
850
856 bool isOpponentRedCarded( const int unum ) const
857 {
858 return isRedCarded( theirSide(), unum );
859 }
860
861
862 //
863 // coach language info
864 //
865
870 long lastPlayOnStart() const
871 {
872 return M_last_playon_start;
873 }
874
875
881 bool canSendCLang( const CLangType type ) const;
882
883
889 {
890 return M_freeform_allowed_count;
891 }
892
898 {
899 return M_freeform_send_count;
900 }
901
906 bool canSendFreeform() const;
907
908 //
909 // analyzed result
910 //
911
916 double offsideLineXForLeft() const
917 {
918 return ( M_our_side == RIGHT
919 ? M_current_state->theirOffsideLineX()
920 : M_current_state->ourOffsideLineX() );
921 }
922
927 double offsideLineXForRight() const
928 {
929 return ( M_our_side == RIGHT
930 ? M_current_state->ourOffsideLineX()
931 : M_current_state->theirOffsideLineX() );
932 }
933
938 double ourOffsideLineX() const
939 {
940 return M_current_state->ourOffsideLineX();
941 }
942
947 double theirOffsideLineX() const
948 {
949 return M_current_state->theirOffsideLineX();
950 }
951
952
958
964 const CoachPlayerObject * getPlayerNearestTo( const Vector2D & point ) const;
965
971 std::ostream & print( std::ostream & os ) const;
972
973};
974
975}
976
977#endif
clang type definition
CLangType
clang message types
Definition: types.h:41
the memory of heard data
Definition: audio_memory.h:49
ball information for coath/trainer
Definition: coach_ball_object.h:44
player information for coath/trainer
Definition: coach_player_object.h:55
std::vector< const CoachPlayerObject * > Cont
container type of const CoachPlayerObject*
Definition: coach_player_object.h:59
visual sensor for coach/trainer
Definition: coach_visual_sensor.h:49
world world for coach
Definition: coach_world_model.h:58
const std::string & teamNameLeft() const
get left team name
Definition: coach_world_model.h:389
SideID theirSide() const
get opponent team side
Definition: coach_world_model.h:362
const std::vector< int > & theirPlayerTypeUsedCount() const
get their team's container of each player type's used count
Definition: coach_world_model.h:791
const Vector2D & passReceivePos() const
get the last heard pass receive position
Definition: coach_world_model.h:676
const GameTime & passTime() const
get the last heard pass time
Definition: coach_world_model.h:640
CoachWorldState::ConstPtr currentStatePtr() const
get the current state pointer.
Definition: coach_world_model.h:468
const std::string & teamNameRight() const
get right team name
Definition: coach_world_model.h:400
long lastPlayOnStart() const
get the playon period
Definition: coach_world_model.h:870
const std::string & theirTeamName() const
get opponent team name
Definition: coach_world_model.h:380
double ourOffsideLineX() const
get the offside line for our offense situation
Definition: coach_world_model.h:938
CoachWorldState::ConstPtr getState(const GameTime &time) const
get the state pointer at the specified game time
Definition: coach_world_model.h:516
const std::string & ourTeamName() const
get our team name
Definition: coach_world_model.h:371
void incFreeformSendCount()
increment freeform send count
const CoachPlayerObject * getPlayerNearestTo(const Vector2D &point) const
get player pointer nearest to the specified point
bool isYellowCarded(const SideID side, const int unum) const
get yellow card status
int ourPlayerTypeId(const int unum) const
get teammate's player type Id
Definition: coach_world_model.h:749
const CoachWorldState::Map & stateMap() const
get the state map. key: GameTime, value: CoachWorldState::ConstPtr
Definition: coach_world_model.h:486
void setServerParam()
init variables using received server_param information. This method have to be called just after serv...
void changePlayerType(const SideID side, const int unum, const int type)
this method have to be called just after change_player_type message is received.
const GameTime & trainingTime() const
get training start/end time
Definition: coach_world_model.h:450
const Vector2D & passStartPos() const
get the last heard pass start position
Definition: coach_world_model.h:667
void updateAll(const rcg::DispInfoT &disp)
update all information by using display data
bool isTeammateYellowCarded(const int unum) const
get teammate's yellow card status
Definition: coach_world_model.h:825
BallStatus getBallStatus() const
get the current ball position status
Definition: coach_world_model.h:544
const std::vector< int > & ourPlayerTypeUsedCount() const
get our team's container of each player type's used count
Definition: coach_world_model.h:782
const CoachPlayerObject::Cont & teammates() const
get teammate players' pointer
Definition: coach_world_model.h:584
int getSetPlayCount() const
get cycle count that setplay type playmode is keeped
Definition: coach_world_model.h:435
const CoachPlayerObject::Cont & allPlayers() const
get all players
Definition: coach_world_model.h:553
const GameMode & gameMode() const
get latest playmode info
Definition: coach_world_model.h:441
bool isTeammateRedCarded(const int unum) const
get teammate's red card status
Definition: coach_world_model.h:835
SideID lastKickerSide() const
get the estimated last ball kicker's team side
Definition: coach_world_model.h:622
const CoachWorldState & currentState() const
get the current state.
Definition: coach_world_model.h:459
bool canSubstitute(const int unum, const int type) const
check if online coach can substitute the specified teammate
bool canSendFreeform() const
check if coach can sent the freeform message now.
int substituteCount(const SideID side) const
get the number of change_player_type message after kickoff
Definition: coach_world_model.h:707
const CoachPlayerObject * teammate(const int unum) const
get the specified teammate.
Definition: coach_world_model.h:603
void updateGameMode(const GameMode &game_mode, const GameTime &current)
update playmode using heard referee info
const GameTime & seeTime() const
get last see global time
Definition: coach_world_model.h:420
bool canSendCLang(const CLangType type) const
check if the clang message can be sent now.
CoachWorldModel()
init member variables.
SideID ourSide() const
get our team side
Definition: coach_world_model.h:353
const GameTime & lastSetPlayStartTime() const
get last setplay type playmode start time
Definition: coach_world_model.h:429
int receiverUnum() const
get the last heard receiver's uniform number
Definition: coach_world_model.h:658
int ourSubstituteCount() const
get the number of our change_player_type message after kickoff
Definition: coach_world_model.h:720
const std::vector< int > & availablePlayerTypeId() const
get the current available player type id set for player substitution.
Definition: coach_world_model.h:689
int playerTypeId(const SideID side, const int unum) const
get the player type Id
void setCard(const SideID side, const int unum, const Card card)
set player's card status
const GameTime & time() const
get last updated time
Definition: coach_world_model.h:411
bool isOpponentRedCarded(const int unum) const
get opponent's red card status
Definition: coach_world_model.h:856
int freeformSendCount() const
get the freeform message send count
Definition: coach_world_model.h:897
double offsideLineXForLeft() const
get the offside line for left team
Definition: coach_world_model.h:916
int freeformAllowedCount() const
get the allowed freeform message count
Definition: coach_world_model.h:888
const CoachPlayerObject::Cont & playersRight() const
get right players' pointer
Definition: coach_world_model.h:573
int lastKickerUnum() const
get the estimated last ball kicker's uniform number
Definition: coach_world_model.h:631
const AudioMemory & audioMemory() const
get audio memory
Definition: coach_world_model.h:180
const CoachWorldState::List & stateList() const
get the state list.
Definition: coach_world_model.h:477
void decCLangCapacity(const CLangType type)
update clang capacity.
void setTeamName(const SideID side, const std::string &name)
set team name
bool isOpponentYellowarded(const int unum) const
get opponent's yellow card status
Definition: coach_world_model.h:845
void setAudioMemory(std::shared_ptr< AudioMemory > memory)
set new audio memory
void updateJustBeforeDecision(const GameTime &current)
update status using audio info
std::ostream & print(std::ostream &os) const
put all data to the output stream
const std::vector< int > & playerTypeUsedCount(const SideID side) const
get container of each player type's used count
Definition: coach_world_model.h:769
int theirSubstituteCount() const
get the number of their change_player_type message after kickoff
Definition: coach_world_model.h:729
CoachWorldState::ConstPtr getState(const int time) const
get the state pointer at the specified game time
Definition: coach_world_model.h:496
void setPlayerParam()
init variables using received player_param information. This method have to be called just after play...
const CoachPlayerObject * opponent(const int unum) const
get the specified teammate.
Definition: coach_world_model.h:613
bool isRedCarded(const SideID side, const int unum) const
get red card status
double offsideLineXForRight() const
get the offside line for right team
Definition: coach_world_model.h:927
void init(const std::string &team_name, const SideID side, const int client_version)
init by team name, team side, and client version
double theirOffsideLineX() const
get the offside line for their offense situation
Definition: coach_world_model.h:947
const CoachPlayerObject::Cont & playersLeft() const
get left players' pointer
Definition: coach_world_model.h:562
const CoachBallObject & ball() const
get the current ball data
Definition: coach_world_model.h:535
void setTrainingTime(const GameTime &t)
set training start/end time
Definition: coach_world_model.h:324
int theirPlayerTypeId(const int unum) const
get opponent's player type Id
Definition: coach_world_model.h:759
bool existKickablePlayer() const
check if kickable player exists or not
int passerUnum() const
get the last heard passer's uniform nuber
Definition: coach_world_model.h:649
void updateAfterSeeGlobal(const CoachVisualSensor &see_global, const GameTime &current)
update status using analyzed visual info
const CoachPlayerObject::Cont & opponents() const
get opponent players' pointer
Definition: coach_world_model.h:593
int clientVersion() const
get a client protocol version.
Definition: coach_world_model.h:344
a state of coach's internal model
Definition: coach_world_state.h:58
std::shared_ptr< CoachWorldState > Ptr
smart pointer type
Definition: coach_world_state.h:61
std::shared_ptr< const CoachWorldState > ConstPtr
smart const pointer type
Definition: coach_world_state.h:62
playmode(referee info) wrapper class
Definition: game_mode.h:50
game time object
Definition: game_time.h:43
long cycle() const
get normal time value
Definition: game_time.h:74
analyzer for opponent team players' player type
Definition: player_type_analyzer.h:51
2D point vector class
Definition: vector_2d.h:46
ball object class for coach/trainer Header file.
player object class for coach/trainer Header file.
coach/trainer world state class Header File
playmode wrapper Header File
game time depending on RCSSServer2D Header File
player type analyzer class Header File
display information
Definition: types.h:1131
the type definition set for the RCSSServer2D
SideID
side type definition
Definition: types.h:47
Card
card type
Definition: types.h:281
BallStatus
ball position status for coach/trainer
Definition: types.h:260