📄 brain.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. * ***************************************************************************/#include "Brain.h"
#include "Global.h"
#include "Situation.h"
#include "Strategy.h"
#include "Predictor.h"
#include "ActionSystem.h"
#include "SoccerScene.h"
#ifdef WIN32
#define for if(0);else for
#endif
Global global;
Global global_previous[POINT_MAX];
////////////for Strategy
ControlPoint position_cp;
void Brain::AddCommand(SoccerCommand cmd)
{
global.commands[global.nCommand].push_back(cmd);
global.nCommand ++;
}
Brain::Brain(){
m_ThinkList.push_back(&scene_normal);
}
Brain::~Brain(){
}
void Brain::Init(ServerSettings *ss,Situation *st)
{
SS = ss;
ST = st;
SoccerScene::Init(ss, st);
global.wm.mSensationCount = 0;
//////////// init for Strategy
position_cp.GetPositionCP();
}
void Brain::Think()
{
if(global.wm.subCycle!=0)
return ;
ThinkNormal();
}
void Brain::ThinkNormal()
{
reset();
if(ST->isDeadBall()) {
ThinkWhenDeadBall();
} else if (global.wm.myNumber == 1) {
ThinkGoalie();
}else {
ThinkPlaying();
}
//say
if (global.wm.mSensationCount >= 10 && global.wm.pm != PM_BeforeKickOff
&& (global.wm.myNumber == 1 || global.wm.myNumber >= 6 && global.wm.myNumber <= 8)) {
double b[2][3]={0};
int k = 0;
if (global.wm.noball==0) {
b[0][0] = global.wm.ballPos.x, b[0][1] = global.wm.ballPos.y, b[0][2] = global.wm.ballPos.z,
b[1][0] = global.wm.ballVel.x, b[1][1] = global.wm.ballVel.y, b[1][2] = global.wm.ballVel.z;
k = 2;
}
double n[22][3]={0};
int j = 0;
for (int i=0; i<11; i++) {
if (global.wm.noour[i] == 0) {
n[j][0] = i;
n[j][1] = global.wm.ourPos[i].x;
n[j][2] = global.wm.ourPos[i].y;
if (fabs(n[j][1])>60)
n[j][1] = 0;
if (fabs(n[j][2])>40)
n[j][2] = 0;
j++;
}
}
for (int i=0; i<11; i++) {
if (global.wm.noopp[i] == 0) {
n[j][0] = i+11;
n[j][1] = global.wm.oppPos[i].x;
n[j][2] = global.wm.oppPos[i].y;
if (fabs(n[j][1])>60)
n[j][1] = 0;
if (fabs(n[j][2])>40)
n[j][2] = 0;
j++;
}
}
as.say(b, n, k, j);
}
++global.wm.mSensationCount;
}
void Brain::reset()
{
int i;
for(i=0;i<global.nCommand;i++){
global.commands[i].clear();
}
global.nCommand = 0;
ST->updateSituation();
}
void Brain::ThinkGoalie()
{
#ifdef WIN32
ShowCircle(global.wm.nextPos,0.22,"0 255 0 2");
#endif
SoccerCommand cmd1,cmd2;
CommandQueue cmds;
CommandList list;
double y7 = strategy.SBSPPosition(7).y, y8 = strategy.SBSPPosition(8).y;
if (y7 > y8) swap(y7, y8);
if(ST->isBallCatchable()&&global.wm.pm == PM_PlayOn&&
(global.wm.ballVel.mod()>0.3||ST->opp_ITInfo[ST->oppByDist2Ball[0]].dDist2Ball<5
||global.wm.myPos.x<-X(100) + SS->mPenaltyAreaSize-5
||fabs(global.wm.myPos.y) < 7)) {
Vector3 dest(-X(100) + SS->mPenaltyAreaSize - 4, 9, 0);
if (global.wm.myPos.y < 0)
dest.y = -dest.y;
cmd1 = intercept.runTo(dest);
#ifdef WIN32
ShowCircle(dest.x, dest.y, 0.3, "255 255 255 0");
#endif
cmd2=SoccerCommand(CT_CATCH);
for(int i=0;i<20;i++) {
list.clear();
list.push_back(cmd1);
list.push_back(cmd2);
cmds.push_back(list);
}
ActionSystem::AddCommandQueue(cmds);
} else {
AgentStatus a,b;
a.pos=global.wm.nextPos;
a.vel=global.wm.nextVel;
b.pos=global.wm.ballPos;
b.vel=global.wm.ballVel;
b=predictor.predictBallStatusAfterNrCycle(b, 1);
if(ST->isBallKickable()) {
bool res=0;
bool isShoot=0;
double power,theta;
if(res=ST->getPassVel(power, theta, isShoot, 15, -1)) {
if(power>90) {
cmd1 = intercept.runTo(b.pos);
cmd2 = SoccerCommand(CT_KICK,theta,100);
for(int i=0;i<20;i++) {
list.clear();
list.push_back(cmd1);
list.push_back(cmd2);
cmds.push_back(list);
}
ActionSystem::AddCommandQueue(cmds);
} else {
cmd2 = SoccerCommand(CT_KICK,theta,power);
ActionSystem::AddCommand(cmd2);
}
} else {
Vector3 p = ST->getBestPassPoint(40);
as.interceptFastest(cmds,p);
ActionSystem::AddCommandQueue(cmds);
}
} else {
if(ST->shouldIIntercept()) {
if(global.wm.myPos.x<-X(100)-0.22) {
cmd1 =SoccerCommand(CT_CATCH);
cmd2 = intercept.runTo(Vector3(-X(97),0,0));
for(int i=0;i<20;i++){
list.clear();
list.push_back(cmd1);
list.push_back(cmd2);
cmds.push_back(list);
}
} else if(ST->shouldICatchWhenInter()) {
as.interceptForCatchBall(cmds);
} else {
Vector3 p=ST->getBestPassPoint(40);
as.interceptFastest(cmds, p);
}
ActionSystem::AddCommandQueue(cmds);
} else {
Vector3 p;
Vector3 g1(-X(100),SS->mGoalWidth/2.);
Vector3 g2(-X(100),-SS->mGoalWidth/2.);
Angle ang1=(b.pos-g1).ang();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -