📄 worldmodel.cpp
字号:
/*************************************************************************** * 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
#include "worldmodel.h"
#include "Global.h"
#include "ServerSettings.h"
#include "Filter.h"
#include "Predicate.h"
#include <fstream>
using namespace std;
extern string teamName;
extern string sayMsgSign;
extern string oppTeamName;
WorldModel::WorldModel()
{
mFieldLength = 105.0;
mFieldWidth = 68.0;
mFieldHeight = 20.0;
mGoalWidth = 7.32;
mGoalDepth = 2.0;
mGoalHeight = 2.44;
mBorderSize = 4.0f;
// agent parameter
mAgentMass = 75;
mAgentRadius = 0.22;
mAgentMaxSpeed = 10;
// ball parameter
mBallRadius = 0.111;
mBallMass = 0.4;
// team information
mTeamIndex = TI_NONE;
mTeamUnum = 0;
mOppTeamName = "";
ConstructInternal();
}
WorldModel::~WorldModel()
{
}
void
WorldModel::SetupGameStateMap(bool is_my_team_left)
{
mPlayModeMap.clear();
if(is_my_team_left){
mPlayModeMap[STR_PM_BeforeKickOff] = PM_BeforeKickOff;
mPlayModeMap[STR_PM_KickOff_Left] = PM_KickOff_Our;
mPlayModeMap[STR_PM_KickOff_Right] = PM_KickOff_Opp;
mPlayModeMap[STR_PM_PlayOn] = PM_PlayOn;
mPlayModeMap[STR_PM_KickIn_Left] = PM_KickIn_Our;
mPlayModeMap[STR_PM_KickIn_Right] = PM_KickIn_Opp;
mPlayModeMap[STR_PM_Goal_Left] = PM_Goal_Our;
mPlayModeMap[STR_PM_Goal_Right] = PM_Goal_Opp;
mPlayModeMap[STR_PM_GameOver] = PM_GameOver;
mPlayModeMap[STR_PM_CORNER_KICK_LEFT] = PM_CORNER_KICK_Our;
mPlayModeMap[STR_PM_CORNER_KICK_RIGHT] = PM_CORNER_KICK_Opp;
mPlayModeMap[STR_PM_GOAL_KICK_LEFT] = PM_GOAL_KICK_Our;
mPlayModeMap[STR_PM_GOAL_KICK_RIGHT] = PM_GOAL_KICK_Opp;
} else {
mPlayModeMap[STR_PM_BeforeKickOff] = PM_BeforeKickOff;
mPlayModeMap[STR_PM_KickOff_Left] = PM_KickOff_Opp;
mPlayModeMap[STR_PM_KickOff_Right] = PM_KickOff_Our;
mPlayModeMap[STR_PM_PlayOn] = PM_PlayOn;
mPlayModeMap[STR_PM_KickIn_Left] = PM_KickIn_Opp;
mPlayModeMap[STR_PM_KickIn_Right] = PM_KickIn_Our;
mPlayModeMap[STR_PM_Goal_Left] = PM_Goal_Opp;
mPlayModeMap[STR_PM_Goal_Right] = PM_Goal_Our;
mPlayModeMap[STR_PM_GameOver] = PM_GameOver;
mPlayModeMap[STR_PM_CORNER_KICK_LEFT] = PM_CORNER_KICK_Opp;
mPlayModeMap[STR_PM_CORNER_KICK_RIGHT] = PM_CORNER_KICK_Our;
mPlayModeMap[STR_PM_GOAL_KICK_LEFT] = PM_GOAL_KICK_Opp;
mPlayModeMap[STR_PM_GOAL_KICK_RIGHT] = PM_GOAL_KICK_Our;
}
}
void
WorldModel::SetupVisionObjectMap()
{
mVisionObjectMap.clear();
// <ObjectName>+<Id> -> VisionObject
mVisionObjectMap["Flag1_l"] = VO_FLAG1L;
mVisionObjectMap["Flag1_r"] = VO_FLAG1R;
mVisionObjectMap["Flag2_l"] = VO_FLAG2L;
mVisionObjectMap["Flag2_r"] = VO_FLAG2R;
mVisionObjectMap["Goal1_l"] = VO_GOAL1L;
mVisionObjectMap["Goal1_r"] = VO_GOAL1R;
mVisionObjectMap["Goal2_l"] = VO_GOAL2L;
mVisionObjectMap["Goal2_r"] = VO_GOAL2R;
mVisionObjectMap["Ball"] = VO_BALL;
int i;
char str[100];
for(i=0;i<11;i++){
sprintf(str,"Player%s%d",mTeamName.c_str(),i+1);
mVisionObjectMap[str] =(VisionObject)(VO_OUR1 + i);
}
for(i=0;i<11;i++){
sprintf(str,"Player%s%d",mOppTeamName.c_str(),i+1);
mVisionObjectMap[str] =(VisionObject)(VO_OPP1 + i);
}
}
bool
WorldModel::ConstructInternal()
{
SetupGameStateMap(false);
SetupVisionObjectMap();
return true;
}
void
WorldModel::ParseTeamIndex(Predicate& predicate)
{
string team;
if (predicate.GetValue("team", team) == false) {
return;
}
TTeamIndex tt = mTeamIndex;
// parse team index
if (team == "left")
mTeamIndex = TI_LEFT;
else if (team == "right")
mTeamIndex = TI_RIGHT;
else
{
mTeamIndex = TI_NONE;
cout
<< "(WorldModel) received TeamIndex TI_NONE" << endl;
}
if(tt != mTeamIndex){
SetupGameStateMap((bool)(mTeamIndex == TI_LEFT));
}
}
void WorldModel::ParsePlayMode(Predicate& predicate)
{
string mode;
if (predicate.GetValue("playmode", mode) == false) {
}
// parse play mode
TPlayModeMap::iterator iter = mPlayModeMap.find(mode);
if (iter != mPlayModeMap.end()) {
mPlayMode = (TPlayMode)(*iter).second;
} else {
}
}
void WorldModel::ParseGameState(Predicate& predicate)
{
ParseTeamIndex(predicate);
ParsePlayMode(predicate);
predicate.GetValue("FieldLength", mFieldLength);
predicate.GetValue("FieldWidth", mFieldWidth);
predicate.GetValue("FieldHeigth", mFieldHeight);
predicate.GetValue("GoalWidth", mGoalWidth);
predicate.GetValue("GoalDepth", mGoalDepth);
predicate.GetValue("GoalHeight", mGoalHeight);
predicate.GetValue("BorderSize", mBorderSize);
predicate.GetValue("time", mTime);
predicate.GetValue("unum", mTeamUnum);
predicate.GetValue("AgentRadius", mAgentRadius);
predicate.GetValue("AgentMass", mAgentMass);
predicate.GetValue("AgentMaxSpeed", mAgentMaxSpeed);
predicate.GetValue("BallRadius", mBallRadius);
predicate.GetValue("BallMass", mBallMass);
//=========================================
ss.mFieldLength=mFieldLength;
ss.mFieldWidth=mFieldWidth;
ss.mFieldHeight=mFieldHeight;
ss.mGoalWidth=mGoalWidth;
ss.mGoalDepth=mGoalDepth;
ss.mGoalHeight=mGoalHeight;
ss.mBorderSize=mBorderSize;
ss.mBallMass = mBallMass;
strategy.Init(&ss);
// filter.k = 1.0/(-0.4671*mBallMass*mBallMass+0.6130*mBallMass+0.7277);
}
void WorldModel::ParseAgentState(Predicate& predicate)
{
vector <string> AgentState;
predicate.GetValue("pan_tilt",AgentState);
if(AgentState.size()==2)
{
mAgentPanAngle=atof(AgentState[0].data());
mAgentTileAngle=atof(AgentState[1].data());
global.wm.myPanAngle=g_wm->mAgentPanAngle;
global.wm.myTiltAngle=g_wm->mAgentTileAngle;
//cerr<<"panangle"<<mAgentPanAngle<<"tiltangle"<<mAgentTileAngle<<endl;
}
}
void WorldModel::ParseObjectVision(Predicate& predicate)
{
//cerr << "ParseObjectVision() " << predicate << endl;
// clear the vision map --add by zyf
VisionSense vs;
// cerr<<"vs"<<vs.distance<<" "<<vs.phi<<" "<<vs.theta<<endl;
VisionObject vn;
for(int i=0;i<31;i++)
{
vn=(VisionObject) i;
mVisionMap[vn] = vs;
}
/////////////
for (
multimap<string, Predicate>::iterator iter = predicate.child.begin();
iter != predicate.child.end();
++iter
) {
// extract the element as a parameter list
Predicate& pred = iter->second;
if (pred.child.size() < 1) {
continue;
}
// read the object name
string name = pred.name;
if (name == "") {
continue;
}
// try read the 'id' section
string teamname;
if (pred.GetValue("team", teamname)) {
name += teamname;
if(mOppTeamName == "") {
if(teamname != mTeamName) {
mOppTeamName = teamname;
SetupVisionObjectMap();
}
}
}
string strId;
if (pred.GetValue("id", strId))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -