coach_command.h

説明を見る。
00001 // -*-c++-*-
00002 
00008 /*
00009  *Copyright:
00010 
00011  Copyright (C) Hidehisa AKIYAMA
00012 
00013  This code is free software; you can redistribute it and/or
00014  modify it under the terms of the GNU Lesser General Public
00015  License as published by the Free Software Foundation; either
00016  version 2.1 of the License, or (at your option) any later version.
00017 
00018  This library is distributed in the hope that it will be useful,
00019  but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00021  Lesser General Public License for more details.
00022 
00023  You should have received a copy of the GNU Lesser General Public
00024  License along with this library; if not, write to the Free Software
00025  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00026 
00027  *EndCopyright:
00028  */
00029 
00031 
00032 #ifndef RCSC_COACH_COMMAND_H
00033 #define RCSC_COACH_COMMAND_H
00034 
00035 #include <rcsc/types.h>
00036 
00037 #include <string>
00038 #include <vector>
00039 #include <utility>
00040 #include <iostream>
00041 
00042 namespace rcsc {
00043 
00048 class CoachCommand {
00049 public:
00053     enum Type {
00054         INIT,
00055         BYE,
00056 
00057         CHECK_BALL,
00058         LOOK,
00059         TEAM_NAMES,
00060 
00061         EYE,
00062 
00063         CHANGE_PLAYER_TYPE,
00064         CHANGE_PLAYER_TYPES,
00065         SAY,
00066 
00067         TEAM_GRAPHIC,
00068         COMPRESSION,
00069         DONE,
00070 
00071         ILLEGAL
00072     };
00073 
00074     /*
00075     enum CLangType {
00076     CLANG_META,
00077     CLANG_FREE_FORM,
00078     CLANG_INFO,
00079     CLANG_ADVICE,
00080     CLANG_DEFINE,
00081         CLANG_ADVISE,
00082         CLANG_ILLEGAL
00083     };
00084     */
00085 
00086 protected:
00090     CoachCommand()
00091       { }
00092 
00093 public:
00097     virtual
00098     ~CoachCommand()
00099       { }
00100 
00105     virtual
00106     Type type() const = 0;
00107 
00113     virtual
00114     std::ostream & toStr( std::ostream & to ) const = 0;
00115 
00120     virtual
00121     std::string name() const = 0;
00122 };
00123 
00124 
00126 
00139 class CoachInitCommand
00140     : public CoachCommand {
00141 private:
00142     std::string M_team_name; 
00143     double M_version; 
00144     std::string M_coach_name; 
00145 public:
00152     CoachInitCommand( const std::string & team_name,
00153                       const double & version,
00154                       const std::string & coach_name = "" );
00155 
00160     Type type() const
00161       {
00162           return INIT;
00163       }
00164 
00170     std::ostream & toStr( std::ostream & to ) const;
00171 
00176     std::string name() const
00177       {
00178           return std::string( "init" );
00179       }
00180 };
00181 
00183 
00192 class CoachByeCommand
00193     : public CoachCommand {
00194 private:
00195 
00196 public:
00200     CoachByeCommand()
00201       { }
00202 
00207     Type type() const
00208       {
00209           return BYE;
00210       }
00211 
00217     std::ostream & toStr( std::ostream & to ) const;
00218 
00223     std::string name() const
00224       {
00225           return std::string( "bye" );
00226       }
00227 };
00228 
00230 
00243 class CoachCheckBallCommand
00244     : public CoachCommand {
00245 private:
00246 
00247 public:
00251     CoachCheckBallCommand()
00252       { }
00253 
00258     Type type() const
00259       {
00260           return CHECK_BALL;
00261       }
00262 
00268     std::ostream & toStr( std::ostream & to ) const;
00269 
00274     std::string name() const
00275       {
00276           return std::string( "check_ball" );
00277       }
00278 };
00279 
00281 
00292 class CoachLookCommand
00293     : public CoachCommand {
00294 private:
00295 
00296 public:
00300     CoachLookCommand()
00301       { }
00302 
00307     Type type() const
00308       {
00309           return LOOK;
00310       }
00311 
00317     std::ostream & toStr( std::ostream & to ) const;
00318 
00323     std::string name() const
00324       {
00325           return std::string( "look" );
00326       }
00327 };
00328 
00330 
00341 class CoachTeamNamesCommand
00342     : public CoachCommand {
00343 private:
00344 
00345 public:
00349     CoachTeamNamesCommand()
00350       { }
00351 
00356     Type type() const
00357       {
00358           return TEAM_NAMES;
00359       }
00360 
00366     std::ostream & toStr( std::ostream & to ) const;
00367 
00372     std::string name() const
00373       {
00374           return std::string( "team_names" );
00375       }
00376 };
00377 
00379 
00390 class CoachEyeCommand
00391     : public CoachCommand {
00392 private:
00393     bool M_on; 
00394 public:
00399     explicit
00400     CoachEyeCommand( bool on )
00401         : M_on( on )
00402       { }
00403 
00408     Type type() const
00409       {
00410           return EYE;
00411       }
00412 
00418     std::ostream & toStr( std::ostream & to ) const;
00419 
00424     std::string name() const
00425       {
00426           return std::string( "eye" );
00427       }
00428 };
00429 
00431 
00449 class CoachChangePlayerTypeCommand
00450     : public CoachCommand {
00451 private:
00452     int M_unum; 
00453     int M_type; 
00454 public:
00460     CoachChangePlayerTypeCommand( const int unum,
00461                                   const int type )
00462         : M_unum( unum )
00463         , M_type( type )
00464       { }
00465 
00470     Type type() const
00471       {
00472           return CHANGE_PLAYER_TYPE;
00473       }
00474 
00480     std::ostream & toStr( std::ostream & to ) const;
00481 
00486     std::string name() const
00487       {
00488           return std::string( "change_player_type" );
00489       }
00490 };
00491 
00492 
00494 
00512 class CoachChangePlayerTypesCommand
00513     : public CoachCommand {
00514 private:
00516     std::vector< std::pair< int, int > > M_types;
00517 
00518 public:
00524     CoachChangePlayerTypesCommand( const int unum,
00525                                    const int type );
00526 
00532     CoachChangePlayerTypesCommand( const std::vector< std::pair< int, int > >  & types );
00533 
00539     void add( const int unum,
00540               const int type );
00541 
00546     Type type() const
00547       {
00548           return CHANGE_PLAYER_TYPES;
00549       }
00550 
00556     std::ostream & toStr( std::ostream & to ) const;
00557 
00562     std::string name() const
00563       {
00564           return std::string( "change_player_types" );
00565       }
00566 };
00567 
00569 
00583 class CoachSayCommand
00584     : public CoachCommand {
00585 private:
00587     const std::string & M_clang_msg;
00588 public:
00593     explicit
00594     CoachSayCommand( const std::string & clang_msg )
00595         : M_clang_msg( clang_msg )
00596       { }
00597 
00602     Type type() const
00603       {
00604           return SAY;
00605       }
00606 
00612     std::ostream & toStr( std::ostream & to ) const;
00613 
00618     std::string name() const
00619       {
00620           return std::string( "say" );
00621       }
00622 };
00623 
00625 
00640 class CoachTeamGraphicCommand
00641     : public CoachCommand {
00642 private:
00643     unsigned int M_x; 
00644     unsigned int M_y; 
00645     std::vector< std::string > M_xpm_lines; 
00646 
00647 public:
00654     CoachTeamGraphicCommand( const unsigned int x,
00655                              const unsigned int y,
00656                              const std::vector< std::string > & xpm_lines );
00657 
00662     Type type() const
00663       {
00664           return TEAM_GRAPHIC;
00665       }
00666 
00672     std::ostream & toStr( std::ostream & to ) const;
00673 
00678     std::string name() const
00679       {
00680           return std::string( "team_graphic" );
00681       }
00682 };
00683 
00684 
00686 
00698 class CoachCompressionCommand
00699     : public CoachCommand {
00700 private:
00701     int M_level; 
00702 public:
00706     explicit
00707     CoachCompressionCommand( const int level )
00708         : M_level( level )
00709       { }
00710 
00715     Type type() const
00716       {
00717           return COMPRESSION;
00718       }
00719 
00725     std::ostream & toStr( std::ostream & to ) const;
00726 
00731     std::string name() const
00732       {
00733           return std::string( "compression" );
00734       }
00735 };
00736 
00737 
00739 
00748 class CoachDoneCommand
00749     : public CoachCommand {
00750 private:
00751 
00752 public:
00756     CoachDoneCommand()
00757       { }
00758 
00763     Type type() const
00764       {
00765           return DONE;
00766       }
00767 
00773     std::ostream & toStr( std::ostream & to ) const;
00774 
00779     std::string name() const
00780       {
00781           return std::string( "done" );
00782       }
00783 };
00784 
00785 }
00786 
00787 /*
00788 
00789 Online Coach Initialization Command
00790   See rcssserver/src/netif.C : void Stadium::parseOnlineCoachInit
00791       rcssserver/src/field.C : OnlineCoach* Stadium::newCoach
00792 
00793 if illegal command
00794   -> "(error illegal_command_form)"
00795 ----------
00796   Coach's default version is 5.0
00797 
00798 "(init TEAM_NAME (version VERSION))"
00799   if TEAM_NAME and VERSION is illegal
00800     -> "(error no_such_team_or_already_have_coach)"
00801   else
00802     if VERSION >= 6.0
00803       -> "(init l ok)" or "(init r ok)"
00804     else
00805       -> "(init ok)"
00806 
00807   receive parameter info
00808   receive changed players info
00809   receive each player's clang version
00810 
00811     if VERSION >= 7.0
00812       -> "(server_param ...)" "(player_param ...)" "(player_type ...)"x7
00813       -> "(change_player_type UNUM ID)" "(change_player_type UNUM)" "(change_player_type TEAM_NAME UNUM ID)"
00814     if VERSION >= 8.0
00815       -> "(clang (ver PLAYER_SHORT_NAME MIN MAX))"
00816 ----------
00817 
00818 ----------
00819 
00820 ----------
00821 Online Coach Command List
00822   See rcssserver/src/netif.C : void Coach::parse_command(const char *command)l
00823 
00824 if use illegal character for command string
00825   -> "(error illegal_command_form)"
00826 else if illegal command
00827   -> "(error unknown_command)"
00828 
00829 ----------
00830 "(check_ball)" : check ball positional state
00831   -> (ok check_ball BALL_POS_INFO)
00832   BALL_POS_INFO :- "in_field" | "goal_l" | "goal_r" | "out_of_field"
00833 ----------
00834 "(look)" : get all movable objects' positional information
00835   -> "(ok look TIME GOAL_INFO BALL_INFO PLAYER_INFO ...)"
00836 ----------
00837 "(team_names)" : get team name
00838   -> "(ok team_names (team l TEAM_NAME) (team r TEAM_NAME))"
00839 ----------
00840 "(say MESSAGE)" : say advice message (if version > 7.0, it must be CLang.)
00841   if version >= 7.0
00842   {
00843     if MESSAGE cannot be parsed
00844       -> "(error could_not_parse_say)"
00845     else
00846     {
00847       if MESSAGE is MetaType
00848         if MetaType has no left
00849           -> "(error said_too_many_meta_messages)"
00850         else
00851           -> "(ok say)"
00852       else if MESSAGE is FreeFormType
00853         if FreeFormType is enable now
00854           if FreeFormType has no left
00855             -> "(error said_too_many_freeform_messages)"
00856           else
00857             -> "(ok say)"
00858         else
00859           -> "(error cannot_say_freeform_while_playon)"
00860       else if MESSAGE is InfoType
00861         if InfoType has no left
00862           -> "(error said_too_many_info_messages)"
00863         else
00864           -> "(ok say)"
00865       else if MESSAGE is AdviceType
00866         if AdviceType has no left
00867           -> "(error said_too_many_advice_messages)"
00868         else
00869           -> "(ok say)"
00870       else if MESSAGE is DefineType
00871         if DefineType has no left
00872           -> "(error said_too_many_define_messages)"
00873         else
00874           -> "(ok say)"
00875       else if MESSAGE is DeleteType
00876         if DeleteType has no left
00877           -> "(error said_too_many_del_messages)"
00878         else
00879           -> "(ok say)"
00880       else if MESSAGE is RuleType
00881         if RuleType has no left
00882           -> "(error said_too_many_rule_messages)"
00883         else
00884           -> "(ok say)"
00885     }
00886   }
00887   else // version < 7.0, CLang is not supported
00888   {
00889     if playmode is PlayOn
00890       -> "(warning cannot_say_while_playon)"
00891     else if coach's say has no left
00892       -> "(error said_too_many_messages)"
00893     else
00894       if MESSAGE uses illegal charcter or is NULL string
00895         -> "(error illegal_command_form)"
00896       else
00897         -> "(ok say)"
00898   }
00899 ----------
00900 "(bye)" : close connection
00901 ----------
00902 "(eye ONOFF)" : turn on/off to get visual info
00903   if ONOFF is NULL
00904     -> "(error illegal_command_form)"
00905   else if ONOFF_MODE == "on"
00906     -> "(ok eye on)"
00907   else if ONOFF_MODE == "off"
00908     -> "(ok eye off)"
00909   else
00910     -> "(error illegal_command_form)"
00911 ----------
00912 "(change_player_type UNUM PLAYER_TYPE_ID)" : change hetero player type
00913   if playmode is PlayOn
00914     -> "(warning cannot_sub_while_playon)"
00915   else if coach's side is Unknown
00916     -> "(warning no_team_found)"
00917   else if team_subs_count == subsMax
00918     -> "(warning no_subs_left)"
00919   else if UNUM or PLAYER_TYPE_ID has illegal form (eg. NULL string)
00920     -> "(error illegal_command_form)"
00921   else if PLAYER_TYPE_ID is out of range (ID<0 or PlayerTypes<ID)
00922     -> "(error out_of_range_player_type)"
00923   else if UNUM is not match
00924     -> "(warning no_such_player)"
00925   else if player is goalie && PLAYER_TYPE_ID != 0
00926     -> "(warning cannot_change_goalie)"
00927   else if ID != 0 && ID's player count == ptMax() && player's id != ID
00928     -> "(warning max_of_that_type_on_field)"
00929   else
00930     -> "(ok change_player_type UNUM PLAYER_TYPE_ID)\n
00931 ----------
00932 "(done)" : thinking end nortification for sync mode
00933 ----------
00934 "(compression LEVEL)" : set zlib compression level
00935   if LEVEL is NULL string
00936     -> "(error illegal_command_form)"
00937   else if not HAVE_LIBZ
00938     -> "(warning compression_unsupported)"
00939   else if (LEVEL < 0 || 9 < LEVEL)
00940     -> "(error illegal_command_form)"
00941   else
00942     -> "(ok compression LEVEL)"
00943 ----------
00944 "(team_graphic (X Y "XPMLINE" ... "XPMLINE"))" : change team graphic on rcssmonitor
00945   if playmode is not BeforeKickOff
00946     -> "warning only_before_kick_off"
00947   else if X or Y is illegal (eg. NULL string)
00948     -> "(error illegal_command_form)"
00949   else if (X >= 32 || Y = 8)
00950     -> "(warning invalid_tile_location)"
00951   else if (xpm's width != 8 || xpm's height != 8)
00952     -> "(warning invalid_tile_size)"
00953   else
00954     -> "(ok team_graphic X Y)"
00955 ----------
00956 */
00957 
00958 
00959 #endif

librcscに対してThu May 1 15:41:20 2008に生成されました。  doxygen 1.5.0