⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 worldmodel.h

📁 浙江大学 RoboCup3D 2006 源代码
💻 H
字号:
/*************************************************************************** *   Copyright (C) 2004 - 2006 by ZJUBase                                  *
 *                                National Lab of Industrial Control Tech. * *                                Zhejiang University, China               * *                                                                         * *   Achievements of ZJUBase in RoboCup Soccer 3D Simulation League:       *
 *    In RoboCup championship,                                             *
 *      - June 2006 - 3rd place in RoboCup 2006, Bremen, Germany (lost     * *        the semi-final with a coin toss)                                 *
 *      - July 2005 - 3rd place in RoboCup 2005, Osaka, Japan (share the   * *        3rd place with team Caspian)                                     *
 *    In RoboCup local events,                                             *
 *      - April 2006 - 2nd place in RoboCup Iran Open 2006, Tehran, Iran   * *        (lost the final with a coin toss)                                *
 *      - December 2005 - 2nd place in AI Games 2005, Isfahan, Iran        *
 *      - July 2005 - champion in China Robot Competition 2005, Changzhou, * *        China                                                            *
 *      - October 2004 - champion in China Soccer Robot Competition 2004,  * *        Guangzhou, China                                                 *
*                                                                         * *   Team members:                                                         *
 *    Currently the team leader is,                                        * *           Hao JIANG (jianghao@iipc.zju.edu.cn; riveria@gmail.com)       *
 *    In the next season, the leader will be                               * *           Yifeng ZHANG (yfzhang@iipc.zju.edu.cn)                        *
 *    ZJUBase 3D agent is created by                                       * *           Dijun LUO (djluo@iipc.zju.edu.cn)                             *
 *    All the members who has ever contributed:                            * *           Jun JIANG                                                     *
 *           Xinfeng DU (xfdu@iipc.zju.edu.cn)                             *
 *           Yang ZHOU (yzhou@iipc.zju.edu.cn)                             *
 *           Zhipeng YANG                                                  *
 *           Xiang FAN                                                     *
 *                                                                         *
 *   Team Manager:                                                          *
 *      Ms. Rong XIONG (rxiong@iipc.zju.edu.cn)                            *
 *                                                                         *
 *   If you met any problems or you have something to discuss about        * *   ZJUBase. Please feel free to contact us through EMails given below.   * *                                                                         * *   This program 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 2 of the License, or     * *   (at your option) any later version.                                   * *                                                                         * *   This program 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 program; if not, write to the                         * *   Free Software Foundation, Inc.,                                       * *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             * ***************************************************************************/#ifndef WIN32

#ifndef WORLDMODEL_H
#define WORLDMODEL_H

#include <string>
#include <map>
#include "soccertypes.h"
#include "Utils.h"
#include "Strategy.h"
#include "Predicate.h"

class WorldModel {
public:
	Strategy strategy;
	struct VisionSense {
        /** distance perceptor to object */
        double distance;

        /** theta is the angle in the X-Y (horizontal) plane */
        double theta;

        /** phi is the latitude angle */
        double phi;

        VisionSense() : distance(0), theta(0), phi(0) {};
	};

    enum VisionObject {
        VO_BALL   = 0,
        VO_FLAG1L = 1,
        VO_FLAG1R = 2,
        VO_FLAG2L = 3,
        VO_FLAG2R = 4,
        VO_GOAL1L = 5,
        VO_GOAL1R = 6,
        VO_GOAL2L = 7,
        VO_GOAL2R = 8,
        VO_OUR1 = 9,
        VO_OUR2 = 10,
        VO_OUR3 = 11,
        VO_OUR4 =12,
        VO_OUR5 =13,
        VO_OUR6 = 14,
        VO_OUR7 = 15,
        VO_OUR8 = 16,
        VO_OUR9 = 17,
        VO_OUR10 = 18,
        VO_OUR11 = 19,
        VO_OPP1 = 20,
        VO_OPP2 = 21,
        VO_OPP3 = 22,
        VO_OPP4 =23,
        VO_OPP5 =24,
        VO_OPP6 = 25,
        VO_OPP7 = 26,
        VO_OPP8 = 27,
        VO_OPP9 = 28,
        VO_OPP10 = 29,
        VO_OPP11 = 30
    };

public:

    void SetupVisionObjectMap();
    WorldModel();
    virtual ~WorldModel();

    /** parses a message received from the server */
    bool Parse(const std::string& message);

    /** returns the polar coordinates of the requested object */
    VisionSense GetVisionSense(VisionObject obj);

    /** returns the global cartesian coordinates of the sensed
        object */
    Vector3 GetPosition(VisionSense sense);

    /** returns the coordinates of the requested object */
    Vector3 GetObjectPosition(VisionObject obj);

    /** returns the current PlayMode */
    TPlayMode GetPlayMode();

    /** given an object position in polar coordinates and distance,
        CalcDriveVec returns a cartesian normalized vector that can be
        passed to the drive effector to reach this position.
    */
    Vector3 GetDriveVec(const WorldModel::VisionSense& vision);

    /** returns the players calculated position */
    Vector3 GetMyPosition();

    /** returns the players team index */
    TTeamIndex GetMyTeam();
    double GetFieldWidth() { return mFieldWidth; }
    double GetFieldLength() { return mFieldLength; }
    double GetAgentRadius() { return mAgentRadius; }
    double GetBallRadius() { return mBallRadius; }
    double GetMinimalKickDistance();
    int GetTeamUnum();
    void SetTeamName(std::string name);  
    std::string GetTeamName();             
    std::string GetOppTeamName();

protected:

    virtual bool ConstructInternal();
    void CalcPlayerPosition();
    void ParseObjectVision(Predicate& predicate);
    void ParseGameState(Predicate& predicate);
    void ParseAgentState(Predicate &predicate); //after RestrictedVisionPerceptor
    void ParseVision(Predicate& predicate);
	void ParseHear(Predicate& predicate);
	double parseFromHear(const string& str);
    void ParsePlayMode(Predicate& predicate);
    void ParseTeamIndex(Predicate& predicate);
    void SetupGameStateMap(bool is_my_team_left);

protected:
    // mapping from gamestate string to TPlayMode
    typedef std::map<std::string, TPlayMode> TPlayModeMap;
    TPlayModeMap mPlayModeMap;

    // mapping from vision object to VisionSense
    typedef std::map<VisionObject, VisionSense> TVisionMap;
    TVisionMap mVisionMap;

    // mapping from <ObjectName>+<ID> to VisionObject
    typedef std::map<std::string, VisionObject> TVisionObjectMap;
    TVisionObjectMap mVisionObjectMap;
    void SetOppTeamName(std::string name);

public:
    // soccer variables
    double mFieldLength;
    double mFieldWidth;
    double mFieldHeight;
    double mGoalWidth;
    double mGoalDepth;
    double mGoalHeight;
    double mBorderSize;

    // agent parameter
    double mAgentMass;
    double mAgentRadius;
    double mAgentMaxSpeed;
    double mAgentPanAngle;       //after RestrictedVisionPerceptor
    double mAgentTileAngle;

    // ball parameter
    double mBallRadius;
    double mBallMass;

    // team information
    TTeamIndex mTeamIndex;
    unsigned int mTeamUnum;
    std::string mTeamName;
    std::string mOppTeamName;

    // game state information
    double mTime;
    TPlayMode mPlayMode;

    // the players position
    Vector3 mMyPos;
};

extern WorldModel* g_wm;

#endif // WORLDMODEL_H

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -