player_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_PLAYER_COMMAND_H
00033 #define RCSC_PLAYER_COMMAND_H
00034 
00035 #include <rcsc/player/view_mode.h>
00036 #include <rcsc/geom/vector_2d.h>
00037 #include <rcsc/geom/angle_deg.h>
00038 
00039 #include <string>
00040 #include <iostream>
00041 #include <cmath>
00042 
00043 namespace rcsc {
00044 
00049 class PlayerCommand {
00050 public:
00054     enum Type {
00055         // connection commands
00056         INIT, 
00057         RECONNECT, 
00058         BYE, 
00059         // base commands
00060         MOVE,
00061         DASH,
00062         TURN,
00063         KICK,
00064         CATCH,
00065         TACKLE,
00066         // support commands
00067         TURN_NECK,
00068         CHANGE_VIEW,
00069         SAY,
00070         POINTTO,
00071         ATTENTIONTO,
00072         // mode change commands
00073         CLANG,
00074         EAR,
00075         // other commands
00076         SENSE_BODY,
00077         SCORE,
00078         COMPRESSION,
00079         // synch_mode command
00080         DONE,
00081 
00082         ILLEGAL
00083     };
00084 
00085 protected:
00089     PlayerCommand()
00090       { }
00091 
00092 public:
00096     virtual
00097     ~PlayerCommand()
00098       { }
00099 
00104     virtual
00105     Type type() const = 0;
00106 
00112     virtual
00113     std::ostream & toStr( std::ostream & to ) const = 0;
00114 
00119     virtual
00120     std::string name() const = 0;
00121 };
00122 
00123 
00125 
00136 class PlayerInitCommand
00137     : public PlayerCommand {
00138 private:
00139     std::string M_team_name; 
00140     double M_version; 
00141     bool M_goalie; 
00142 public:
00149     explicit
00150     PlayerInitCommand( const std::string & team_name,
00151                        const double & version = 3.0,
00152                        const bool goalie = false );
00153 
00158     Type type() const
00159       {
00160           return INIT;
00161       }
00162 
00168     std::ostream & toStr( std::ostream & to ) const;
00169 
00174     std::string name() const
00175       {
00176           return std::string( "init" );
00177       }
00178 };
00179 
00180 
00182 
00193 class PlayerReconnectCommand
00194     : public PlayerCommand {
00195 private:
00196     std::string M_team_name; 
00197     int M_unum; 
00198 public:
00204     PlayerReconnectCommand( const std::string & team_name,
00205                             const int unum );
00206 
00211     Type type() const
00212       {
00213           return RECONNECT;
00214       }
00215 
00221     std::ostream & toStr( std::ostream & to ) const;
00222 
00227     std::string name() const
00228       {
00229           return std::string( "reconnect" );
00230       }
00231 };
00232 
00233 
00235 
00244 class PlayerByeCommand
00245     : public PlayerCommand {
00246 private:
00247 
00248 public:
00252     PlayerByeCommand();
00253 
00258     Type type() const
00259       {
00260           return BYE;
00261       }
00262 
00268     std::ostream & toStr( std::ostream & to ) const;
00269 
00274     std::string name() const
00275       {
00276           return std::string( "bye" );
00277       }
00278 };
00279 
00283 
00287 class PlayerBodyCommand
00288     : public PlayerCommand {
00289 protected:
00293     PlayerBodyCommand()
00294       { }
00295 
00296 public:
00300     virtual
00301     ~PlayerBodyCommand()
00302       { }
00303 
00308     virtual
00309     Type type() const = 0;
00310 
00316     virtual
00317     std::ostream & toStr( std::ostream & to ) const = 0;
00318 
00323     virtual
00324     std::string name() const = 0;
00325 
00326 
00331     virtual
00332     Vector2D movePos() const
00333       {
00334           return Vector2D::INVALIDATED;
00335       }
00336 
00341     virtual
00342     double dashPower() const
00343       {
00344           return 0.0;
00345       }
00346 
00351     virtual
00352     double turnMoment() const
00353       {
00354           return 0.0;
00355       }
00356 
00361     virtual
00362     double kickPower() const
00363       {
00364           return 0.0;
00365       }
00366 
00371     virtual
00372     double kickDir() const
00373       {
00374           return 0.0;
00375       }
00376 
00381     virtual
00382     double catchDir() const
00383       {
00384           return 0.0;
00385       }
00386 
00391     virtual
00392     double tacklePower() const
00393       {
00394           return 0.0;
00395       }
00396 };
00397 
00401 
00411 class PlayerMoveCommand
00412     : public PlayerBodyCommand {
00413 private:
00414     double M_x; 
00415     double M_y; 
00416 public:
00422     PlayerMoveCommand( const double & x,
00423                        const double & y )
00424         : M_x( x )
00425         , M_y( y )
00426       { }
00427 
00432     Type type() const
00433       {
00434           return MOVE;
00435       }
00436 
00442     std::ostream & toStr( std::ostream & to ) const;
00443 
00448     std::string name() const
00449       {
00450           return std::string( "move" );
00451       }
00452 
00457     Vector2D movePos() const
00458       {
00459           return Vector2D( M_x, M_y );
00460       }
00461 
00462 };
00463 
00465 
00474 class PlayerDashCommand
00475     : public PlayerBodyCommand {
00476 private:
00477     double M_power; 
00478 public:
00483     explicit
00484     PlayerDashCommand( const double & power )
00485         : M_power( power )
00486       { }
00487 
00492     Type type() const
00493       {
00494           return DASH;
00495       }
00496 
00502     std::ostream & toStr( std::ostream & to ) const;
00503 
00508     std::string name() const
00509       {
00510           return std::string( "dash" );
00511       }
00512 
00517     double dashPower() const
00518       {
00519           return M_power;
00520       }
00521 };
00522 
00524 
00533 class PlayerTurnCommand
00534     : public PlayerBodyCommand {
00535 private:
00536     double M_moment; 
00537 public:
00542     explicit
00543     PlayerTurnCommand( const double & moment )
00544         : M_moment( moment )
00545       { }
00546 
00551     Type type() const
00552       {
00553           return TURN;
00554       }
00555 
00561     std::ostream & toStr( std::ostream & to ) const;
00562 
00567     std::string name() const
00568       {
00569           return std::string( "turn" );
00570       }
00571 
00576     double turnMoment() const
00577       {
00578           return M_moment;
00579       }
00580 };
00581 
00582 
00584 
00593 class PlayerKickCommand
00594     : public PlayerBodyCommand {
00595 private:
00596     double M_power; 
00597     double M_dir; 
00598 public:
00604     PlayerKickCommand( const double & power,
00605                        const double & dir )
00606         : M_power( power )
00607         , M_dir( dir )
00608       { }
00609 
00614     Type type() const
00615       {
00616           return KICK;
00617       }
00618 
00624     std::ostream & toStr( std::ostream & to ) const;
00625 
00630     std::string name() const
00631       {
00632           return std::string( "kick" );
00633       }
00634 
00639     double kickPower() const
00640       {
00641           return M_power;
00642       }
00643 
00648     double kickDir() const
00649       {
00650           return M_dir;
00651       }
00652 };
00653 
00655 
00664 class PlayerCatchCommand
00665     : public PlayerBodyCommand {
00666 private:
00667     double M_dir; 
00668 public:
00673     explicit
00674     PlayerCatchCommand( const double & rel_dir )
00675         : M_dir( rel_dir )
00676       { }
00677 
00682     Type type() const
00683       {
00684           return CATCH;
00685       }
00686 
00692     std::ostream & toStr( std::ostream & to ) const;
00693 
00698     std::string name() const
00699       {
00700           return std::string( "catch" );
00701       }
00702 
00707     double catchDir() const
00708       {
00709           return M_dir;
00710       }
00711 };
00712 
00714 
00723 class PlayerTackleCommand
00724     : public PlayerBodyCommand {
00725 private:
00726     double M_power_or_dir; 
00727 public:
00732     explicit
00733     PlayerTackleCommand( const double & power_or_dir )
00734         : M_power_or_dir( power_or_dir )
00735       { }
00736 
00741     Type type() const
00742       {
00743           return TACKLE;
00744       }
00745 
00751     std::ostream & toStr( std::ostream & to ) const;
00752 
00757     std::string name() const
00758       {
00759           return std::string( "tackle" );
00760       }
00761 
00766     virtual
00767     double tacklePowerOrDir() const
00768       {
00769           return M_power_or_dir;
00770       }
00771 };
00772 
00776 
00780 class PlayerSupportCommand
00781     : public PlayerCommand {
00782 protected:
00786     PlayerSupportCommand()
00787       { }
00788 
00789 public:
00793     virtual
00794     ~PlayerSupportCommand()
00795       { }
00796 
00801     virtual
00802     Type type() const = 0;
00803 
00809     virtual
00810     std::ostream & toStr( std::ostream & to ) const = 0;
00811 
00816     virtual
00817     std::string name() const = 0;
00818 };
00819 
00823 
00832 class PlayerTurnNeckCommand
00833     : public PlayerSupportCommand {
00834 private:
00835     double M_moment; 
00836 public:
00841     explicit
00842     PlayerTurnNeckCommand( const double & moment )
00843         : M_moment( moment )
00844       { }
00845 
00850     Type type() const
00851       {
00852           return TURN_NECK;
00853       }
00854 
00860     std::ostream & toStr( std::ostream & to ) const;
00861 
00866     std::string name() const
00867       {
00868           return std::string( "turn_neck" );
00869       }
00870 
00875     const
00876     double & moment() const
00877       {
00878           return M_moment;
00879       }
00880 };
00881 
00883 
00895 class PlayerChangeViewCommand
00896     : public PlayerSupportCommand {
00897 private:
00898     ViewWidth M_width; 
00899     ViewQuality M_quality; 
00900     double M_version; 
00901 public:
00908     PlayerChangeViewCommand( const ViewWidth & w,
00909                              const ViewQuality & q,
00910                              const double & version = 8.0 )
00911         : M_width( w )
00912         , M_quality( q )
00913         , M_version( version )
00914       { }
00915 
00920     Type type() const
00921       {
00922           return CHANGE_VIEW;
00923       }
00924 
00930     std::ostream & toStr( std::ostream & to ) const;
00931 
00936     std::string name() const
00937       {
00938           return std::string( "change_view" );
00939       }
00940 
00945     const
00946     ViewWidth & width() const
00947       {
00948           return M_width;
00949       }
00950 
00955     const
00956     ViewQuality & quality() const
00957       {
00958           return M_quality;
00959       }
00960 };
00961 
00963 
00973 class PlayerSayCommand
00974     : public PlayerSupportCommand {
00975 private:
00976     std::string M_message; 
00977     double M_version; 
00978 public:
00979 
00984     explicit
00985     PlayerSayCommand( const double & version )
00986         : M_version( version )
00987       { }
00988 
00994     PlayerSayCommand( const char * msg,
00995                       const double & version )
00996         : M_message( msg )
00997         , M_version( version )
00998       { }
01004     PlayerSayCommand( const std::string & msg,
01005                       const double & version )
01006         : M_message( msg )
01007         , M_version( version )
01008       { }
01009 
01014     Type type() const
01015       {
01016           return SAY;
01017       }
01018 
01024     std::ostream & toStr( std::ostream & to ) const;
01025 
01030     std::string name() const
01031       {
01032           return std::string( "say" );
01033       }
01034 
01039     void assign( const std::string & msg )
01040       {
01041           M_message = msg;
01042       }
01043 
01048     void append( const std::string & msg )
01049       {
01050           M_message += msg;
01051       }
01052 
01057     const
01058     std::string & message() const
01059       {
01060           return M_message;
01061       }
01062 
01063 };
01064 
01066 
01076 class PlayerPointtoCommand
01077     : public PlayerSupportCommand {
01078 private:
01079     bool M_on; 
01080     double M_dist; 
01081     double M_dir; 
01082 public:
01086     PlayerPointtoCommand()
01087         : M_on( false )
01088         , M_dist( 0.0 )
01089         , M_dir( 0.0 )
01090       { }
01091 
01097     PlayerPointtoCommand( const double & dist,
01098                           const double & rel_dir )
01099         : M_on( true )
01100         , M_dist( dist )
01101         , M_dir( rel_dir )
01102       { }
01103 
01108     Type type() const
01109       {
01110           return POINTTO;
01111       }
01112 
01118     std::ostream & toStr( std::ostream & to ) const;
01119 
01124     std::string name() const
01125       {
01126           return std::string( "pointto" );
01127       }
01128 
01129 
01134     bool pointtoOn() const
01135       {
01136           return M_on;
01137       }
01138 
01143     const
01144     double & pointtoDist() const
01145       {
01146           return M_dist;
01147       }
01148 
01153     const
01154     double & pointtoDir() const
01155       {
01156           return M_dist;
01157       }
01158 };
01159 
01161 
01173 class PlayerAttentiontoCommand
01174     : public PlayerSupportCommand {
01175 public:
01179     enum SideType {
01180         OUR,
01181         OPP,
01182         NONE,
01183     };
01184 
01185 private:
01186     SideType M_side; 
01187     int M_number; 
01188 public:
01192     PlayerAttentiontoCommand()
01193         : M_side( NONE )
01194         , M_number( 0 )
01195       { }
01196 
01202     PlayerAttentiontoCommand( const SideType side,
01203                               const int unum )
01204         : M_side( side )
01205         , M_number( unum )
01206       { }
01207 
01212     Type type() const
01213       {
01214           return ATTENTIONTO;
01215       }
01216 
01222     std::ostream & toStr( std::ostream & to ) const;
01223 
01228     std::string name() const
01229       {
01230           return std::string( "attentionto" );
01231       }
01232 
01237     bool isOn() const
01238       {
01239           return M_side != NONE;
01240       }
01241 
01246     SideType side() const
01247       {
01248           return M_side;
01249       }
01250 
01255     int number() const
01256       {
01257           return M_number;
01258       }
01259 };
01260 
01262 
01273 class PlayerCLangCommand
01274     : public PlayerSupportCommand {
01275 private:
01276     int M_min; 
01277     int M_max; 
01278 public:
01284     PlayerCLangCommand( const int min_version,
01285                         const int max_version )
01286         : M_min( min_version )
01287         , M_max( max_version )
01288       { }
01289 
01294     Type type() const
01295       {
01296           return CLANG;
01297       }
01298 
01304     std::ostream & toStr( std::ostream & to ) const;
01305 
01310     std::string name() const
01311       {
01312           return std::string( "clang" );
01313       }
01314 
01319     int minVer() const
01320       {
01321           return M_min;
01322       }
01323 
01328     int maxVer() const
01329       {
01330           return M_max;
01331       }
01332 };
01333 
01335 
01360 class PlayerEarCommand
01361     : public PlayerSupportCommand {
01362 public:
01366     enum OnOffType {
01367         ON,
01368         OFF,
01369     };
01373     enum SideType {
01374         OUR,
01375         OPP,
01376     };
01380     enum ModeType {
01381         COMPLETE,
01382         PARTIAL,
01383         ALL,
01384     };
01385 
01386 private:
01387     OnOffType M_onoff; 
01388     SideType M_side; 
01389     ModeType M_mode; 
01390 public:
01396     PlayerEarCommand( const OnOffType onoff,
01397                       const SideType side )
01398         : M_onoff( onoff )
01399         , M_side( side )
01400         , M_mode( ALL )
01401       { }
01402 
01409     PlayerEarCommand( const OnOffType onoff,
01410                       const SideType side,
01411                       const ModeType mode )
01412         : M_onoff( onoff )
01413         , M_side( side )
01414         , M_mode( mode )
01415       { }
01416 
01421     Type type() const
01422       {
01423           return EAR;
01424       }
01425 
01431     std::ostream & toStr( std::ostream & to ) const;
01432 
01437     std::string name() const
01438       {
01439           return std::string( "ear" );
01440       }
01441 
01442 
01447     OnOffType onOff() const
01448       {
01449           return M_onoff;
01450       }
01451 
01456     SideType side() const
01457       {
01458           return M_side;
01459       }
01460 
01465     ModeType mode() const
01466       {
01467           return M_mode;
01468       }
01469 
01470 };
01471 
01473 
01484 class PlayerSenseBodyCommand
01485     : public PlayerSupportCommand {
01486 private:
01487 
01488 public:
01492     PlayerSenseBodyCommand()
01493       { }
01494 
01499     Type type() const
01500       {
01501           return SENSE_BODY;
01502       }
01503 
01509     std::ostream & toStr( std::ostream & to ) const;
01510 
01515     std::string name() const
01516       {
01517           return std::string( "sense_body" );
01518       }
01519 };
01520 
01522 
01534 class PlayerScoreCommand
01535     : public PlayerSupportCommand {
01536 private:
01537 
01538 public:
01542     PlayerScoreCommand()
01543       { }
01544 
01549     Type type() const
01550       {
01551           return SCORE;
01552       }
01553 
01559     std::ostream & toStr( std::ostream & to ) const;
01560 
01565     std::string name() const
01566       {
01567           return std::string( "score" );
01568       }
01569 };
01570 
01572 
01584 class PlayerCompressionCommand
01585     : public PlayerSupportCommand {
01586 private:
01587     int M_level; 
01588 public:
01593     explicit
01594     PlayerCompressionCommand( const int level )
01595         : M_level( level )
01596       { }
01597 
01602     Type type() const
01603       {
01604           return COMPRESSION;
01605       }
01606 
01612     std::ostream & toStr( std::ostream & to ) const;
01613 
01618     std::string name() const
01619       {
01620           return std::string( "compression" );
01621       }
01622 
01627     int level() const
01628       {
01629           return M_level;
01630       }
01631 };
01632 
01633 
01635 
01644 class PlayerDoneCommand
01645     : public PlayerSupportCommand {
01646 private:
01647 
01648 public:
01652     PlayerDoneCommand()
01653       { }
01654 
01659     Type type() const
01660       {
01661           return DONE;
01662       }
01663 
01669     std::ostream & toStr( std::ostream & to ) const;
01670 
01675     std::string name() const
01676       {
01677           return std::string( "done" );
01678       }
01679 };
01680 
01681 }
01682 
01683 /*
01684 
01685 init,
01686 "(init <teamname>)"
01687 "(init <teamname> (version <ver>))"
01688 "(init <teamname> (version <ver>) (goalie))"
01689 
01690 bye,
01691 "(bye)"
01692 
01693 
01694 
01695 move,
01696 "(move <x> <y>)"
01697 "(move (<x> <y>))"
01698 
01699 dash,
01700 "(dash <power>)"
01701 
01702 turn,
01703 "(turn <moment>)"
01704 
01705 kick,
01706 "(kick <power> <dir>)"
01707 
01708 catch,
01709 "(catch <dir>)"
01710 
01711 tackle,
01712 "(tackle <power>)"
01713 
01714 
01715 
01716 turn_neck,
01717 "(turn_neck <moment>)"
01718 
01719 change_view,
01720 "(change_view <width> <qual>)"
01721 <width> :- narrow | normal | wide
01722 <qual> :- high | low
01723 
01724 say,
01725 "(say <message>)"
01726 "(say "<message>")" <--- in server 8+, to use the double quatation is recommended
01727 
01728 pointto,
01729 "(pointto <dist> <dir>)"
01730 "(pointto off)"
01731 
01732 attentionto,
01733 "(attentionto <side> <number>)"
01734 "(attentionto off)"
01735 side :- our | opp | l | left | r | right | TEAMNAME
01736 <--- server check the string in this order
01737 
01738 clang,
01739 "(clang (ver <min> <max>))"
01740 
01741 ear,
01742 "(ear <flag> <side> <mode>)"
01743 "(ear <flag> <mode>)"
01744 "(ear <flag> <side>)"
01745 "(ear <flag>)"
01746 <flag> :- on | off
01747 <side> :- our | opp | left | l | right | r | TEAMNAME
01748 <mode> :- partial | p | complete | c
01749 
01750 
01751 sense_body,
01752 "(sense_body)"
01753 
01754 score,
01755 "(score)"
01756 
01757 compression,
01758 "(compression <level>)"
01759 <level> :- [0-9]
01760 
01761 done,
01762 "(done)"
01763 
01764 
01765 
01766 */
01767 
01768 #endif

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