您好,欢迎来到微智科技网。
搜索
您的当前位置:首页策略

策略

来源:微智科技网
#include \"StdAfx.h\" #include \".\\strategy.h\"

CStrategy::CStrategy(void) {

m_StatePeriod=15; m_TurnYuan=0; }

CStrategy::~CStrategy(void) { }

//以下id及鱼信息、鱼动作信息数组相关,取值说明: //0-7是A队的,8-15是B队的;

//例如,A队的第一条鱼的动作是actions[0],B队的第一条鱼的动作是actions[8]

void CStrategy::BasicActionStop(CFishInfo fish[],CFishAction action[],int id) {

action[id].speed=0; action[id].direction=7; action[id].mode=0;

action[id].state++;

if(action[id].state==m_StatePeriod) { action[id].state=0; m_TurnYuan=0; }

fish[id].SetAction(action[id]); }

void CStrategy::BasicActionGo(CFishInfo fish[],CFishAction action[],int id,int speed,int direction,int mode) {

action[id].speed=speed;

action[id].direction=direction; action[id].mode=mode;

if(m_TurnYuan)//正在执行原始转弯模式什么是“原始转弯模式”??演示

1

{ action[id].state++; if(action[id].state>=m_StatePeriod) { action[id].state=0; m_TurnYuan=0; } } else { if(mode) { action[id].state=0; m_TurnYuan=mode; } else { action[id].state++; if(action[id].state>=m_StatePeriod) action[id].state=0; } }

fish[id].SetAction(action[id]); }

//1VS1 BOOL CStrategy::Strategy0(CFishAction m_action[],CFishInfo m_FishInfo[],CBallInfo &m_goalinfo,CObstaInfo m_obst[],CHANNEL m_Channel[]) {

CPoint f_pt;//鱼的中心点坐标中心点指哪里??

f_pt=m_FishInfo[0].GetCenterPt();//GetCenterPt()返回中心点坐标 double f_dir;//鱼的方向,[-PI,PI]

f_dir=m_FishInfo[0].GetDirection();如何确定方向?? CPoint tempt,tempt0,tempt1,tempt2;

CPoint f_headpt;//point of fish's head f_headpt=m_FishInfo[0].GetHeadPoint();

CPoint b_pt;//球的中心点坐标 b_pt=m_goalinfo.GetBallPt();

2

CPoint g_pt;//球门中心点坐标//distance g_pt=m_Channel[0].center;

double dirfishtoball;

dirfishtoball=this->Angle(f_pt,b_pt); double disfishtoball;

disfishtoball=this->Distance(f_pt,b_pt);为什么不用鱼头坐标?? double dirballtogoal;

dirballtogoal=this->Angle(b_pt,g_pt); double dirgoaltoball;

dirgoaltoball=this->Angle(g_pt,b_pt); dirfishtoball-=f_dir;

dirfishtoball=this->Checkangle(dirfishtoball); double dir=dirfishtoball*180/PI;

double r=9.0;

tempt0.x=b_pt.x-r*cos(dirballtogoal);

tempt0.y=b_pt.y-r*sin(dirballtogoal);//鱼在球左边时的临时目标点。tempt1.x=b_pt.x+r*cos(dirgoaltoball);

tempt1.y=b_pt.y+r*sin(dirgoaltoball);//鱼在球右边时的临时目标点。bool m_right; if(g_pt.x>312) m_right=true; else m_right=false; if(m_right) { if(f_headpt.x3

} else { if(f_pt.y5/6*PI&&f_dir<-5/6*PI) { m_action[0].mode=0; m_action[0].direction=7; } else if(f_dir>-2/3*PI&&f_dirb_pt.y+r)//鱼在球下面 { m_action[0].speed=15; if(f_dir>5/6*PI&&f_dir<-5/6*PI) { m_action[0].mode=0; m_action[0].direction=7; } else if(f_dir>-PI/2&&f_dir<2/3*PI) { m_action[0].mode=1; m_action[0].direction=14; } else { m_action[0].mode=0; m_action[0].direction=f_dir<0?2:12;

4

}

m_FishInfo[0].SetAction(m_action[0]);

}

else//fish is in the same y-axis line with the ball { m_action[0].speed=15; if(f_dir>2/3*PI&&f_dir<-2/3*PI) { m_action[0].mode=1; m_action[0].direction=f_dir>0?0:14; } else { m_action[0].mode=0; m_action[0].direction=7; } m_FishInfo[0].SetAction(m_action[0]); }

}

} else { if(f_headpt.x>b_pt.x+2)//鱼在球左边 { if(disfishtoball<40)//the velosity change easy to approach { m_action[0].mode=0; m_action[0].speed=12; } else { m_action[0].mode=0; m_action[0].speed=15; } Roundp2p1(tempt1,m_action[0],0,m_FishInfo[0]); } else { if(f_pt.y{

5

//m_action[0].mode=0; m_action[0].speed=15; if(f_dir-PI/6) { m_action[0].mode=0; m_action[0].direction=7; } else if(f_dir>PI/2&&f_dir<-PI/3) { m_action[0].mode=1; m_action[0].direction=14; } else { m_action[0].mode=0; m_action[0].direction=f_dir<0?11:3; } }

else if(f_pt.y>b_pt.y+r)//鱼在球下面 { //m_action[0].mode=0; m_action[0].speed=15; if(f_dir-PI/6) { m_action[0].mode=0; m_action[0].direction=7; } else if(f_dir<-PI/2&&f_dir>1/3*PI) { m_action[0].mode=1; m_action[0].direction=0; } else { m_action[0].mode=0; m_action[0].direction=f_dir<0?12:2; } }

else//fish is in the same y-axis line with the ball { //m_action[0].mode=0; m_action[0].speed=15; if(f_dir>PI/4&&f_dir<-PI/4)

6

{ m_action[0].mode=1; m_action[0].direction=f_dir<0?14:0; } else { m_action[0].mode=0; m_action[0].direction=7; } } } }

return TRUE; }

//2VS2 BOOL CStrategy::Strategy1(CFishAction m_FishInfo[],CBallInfo &m_goalinfo,CObstaInfo m_Channel[]) {

//获取鱼的信息

CPoint b_pt;//球的中心点坐标 b_pt=m_goalinfo.GetBallPt();

CPoint g_pt;//球门中心点坐标//distance g_pt=m_Channel[0].center;

double r=9.0;

CPoint f_pt[4];//鱼的中心点坐标 double f_dir[4];//鱼的方向,[-PI,PI] double dirfishtoball[4]; double disfishtoball[4]; double dir[4];

CPoint f_headpt[4]; double dirballtogoal;

dirballtogoal=this->Angle(b_pt,g_pt); double dirgoaltoball;

dirgoaltoball=this->Angle(g_pt,b_pt);

CPoint tempt[4],tempt1[4];

//从左向右顶 if(g_pt.x>312) { for(int i=0;i<=1;i++)

m_action[],CFishInfo

m_obst[],CHANNEL

7

{ 目标点。

f_pt[i]=m_FishInfo[i].GetCenterPt();//GetCenterPt()返回中心点坐标

f_dir[i]=m_FishInfo[i].GetDirection(); f_headpt[i]=m_FishInfo[i].GetHeadPoint(); dirfishtoball[i]=this->Angle(f_pt[i],b_pt); disfishtoball[i]=this->Distance(f_pt[i],b_pt); dirfishtoball[i]-=f_dir[i];

dirfishtoball[i]=this->Checkangle(dirfishtoball[i]); dir[i]=dirfishtoball[i]*180/PI;

tempt[i].x=b_pt.x-9*cos(dirballtogoal);

tempt[i].y=b_pt.y-9*sin(dirballtogoal);//鱼在球左边时的临时目标点。 // tempt1[i].x=b_pt.x+9*cos(dirballtogoal); // tempt1[i].y=b_pt.y-9*sin(dirballtogoal);//鱼在球左边时的临时

if(f_headpt[i].xif(f_pt[i].yif(f_dir[i]>5/6*PI&&f_dir[i]<-5/6*PI) { m_action[i].mode=0;

m_action[i].direction=7;

8

} else if(f_dir[i]>-2/3*PI&&f_dir[i]b_pt.y+r)//鱼在球下面 { m_action[i].speed=15; if(f_dir[i]>5/6*PI&&f_dir[i]<-5/6*PI) { m_action[i].mode=0; m_action[i].direction=7; } else if(f_dir[i]>-PI/2&&f_dir[i]<2/3*PI) { m_action[i].mode=1; m_action[i].direction=14; } else { m_action[i].mode=0; m_action[i].direction=f_dir[i]<0?2:12; } } else//fish is in the same y-axis line with the ball { m_action[i].speed=15; if(f_dir[i]>3/4*PI&&f_dir[i]<-3/4*PI) { m_action[i].mode=1; m_action[i].direction=f_dir>0?0:14; } else {

9

m_action[i].mode=0; m_action[i].direction=7; } } } } } else { for(int i=0;i<=1;i++) { f_pt[i]=m_FishInfo[i].GetCenterPt();//GetCenterPt()返回中心点坐标 f_dir[i]=m_FishInfo[i].GetDirection(); f_headpt[i]=m_FishInfo[i].GetHeadPoint(); dirfishtoball[i]=this->Angle(f_pt[i],b_pt); disfishtoball[i]=this->Distance(f_pt[i],b_pt); dirfishtoball[i]-=f_dir[i]; dirfishtoball[i]=this->Checkangle(dirfishtoball[i]); dir[i]=dirfishtoball[i]*180/PI; double r=9.0; // tempt[i].x=b_pt.x-9*cos(dirballtogoal); // tempt[i].y=b_pt.y-9*sin(dirballtogoal);//鱼在球左边时的临时目标点。 tempt1[i].x=b_pt.x+9*cos(dirgoaltoball); tempt1[i].y=b_pt.y+9*sin(dirgoaltoball);//鱼在球左边时的临时目标点。 if(f_headpt[i].x>b_pt.x+5)//鱼在球左边 { if(disfishtoball[i]<40)//the velosity change easy to approach { m_action[i].mode=0; m_action[i].speed=13; } else { m_action[i].mode=0; m_action[i].speed=15; } Roundp2p1(tempt1[i],m_action[i],i,m_FishInfo[i]);

10

} else { if(f_pt[i].y-PI/6) { m_action[i].mode=0; m_action[i].direction=7; } else if(f_dir[i]>PI/2&&f_dir[i]<-PI/3) { m_action[i].mode=1; m_action[i].direction=14; } else { m_action[i].mode=0; m_action[i].direction=f_dir[i]<0?11:3; } } else if(f_pt[i].y>b_pt.y+r)//鱼在球下面 { m_action[i].speed=15; if(f_dir[i]-PI/6) { m_action[i].mode=0; m_action[i].direction=7; } else if(f_dir[i]<-PI/2&&f_dir[i]>1/3*PI) { m_action[i].mode=1; m_action[i].direction=0; } else { m_action[i].mode=0; m_action[i].direction=f_dir[i]<0?12:2; }

}

else//fish is in the same y-axis line with the ball

11

{ m_action[i].speed=15; if(f_dir[i]>PI/4&&f_dir[i]<-PI/4) { m_action[i].mode=1; m_action[i].direction=f_dir<0?14:0; } else { m_action[i].mode=0; m_action[i].direction=7; } } } }

}

return TRUE; }

//3VS3 BOOL CStrategy::Strategy2(CFishAction m_FishInfo[],CBallInfo &m_goalinfo,CObstaInfo m_Channel[]) {

//获取鱼的信息

CPoint b_pt;//球的中心点坐标 b_pt=m_goalinfo.GetBallPt();

CPoint g_pt;//球门中心点坐标//distance g_pt=m_Channel[0].center;

double r=9.0;

CPoint f_pt[4];//鱼的中心点坐标 double f_dir[4];//鱼的方向,[-PI,PI] double dirfishtoball[4]; double disfishtoball[4]; double dir[4];

CPoint f_headpt[4]; double dirballtogoal;

dirballtogoal=this->Angle(b_pt,g_pt); double dirgoaltoball;

dirgoaltoball=this->Angle(g_pt,b_pt);

CPoint tempt[4],tempt1[4];

m_action[],CFishInfo m_obst[],CHANNEL 12

//从左向右顶 if(g_pt.x>312) { for(int i=0;i<=2;i++) { 目标点。

f_pt[i]=m_FishInfo[i].GetCenterPt();//GetCenterPt()返回中心点坐标 f_dir[i]=m_FishInfo[i].GetDirection(); f_headpt[i]=m_FishInfo[i].GetHeadPoint(); dirfishtoball[i]=this->Angle(f_pt[i],b_pt); disfishtoball[i]=this->Distance(f_pt[i],b_pt); dirfishtoball[i]-=f_dir[i]; dirfishtoball[i]=this->Checkangle(dirfishtoball[i]); dir[i]=dirfishtoball[i]*180/PI; tempt[i].x=b_pt.x-9*cos(dirballtogoal); tempt[i].y=b_pt.y-9*sin(dirballtogoal);//鱼在球左边时的临时目标点。 // tempt1[i].x=b_pt.x+9*cos(dirballtogoal); // tempt1[i].y=b_pt.y-9*sin(dirballtogoal);//鱼在球左边时的临时if(f_headpt[i].x13

m_action[i].speed=15; if(f_dir[i]>5/6*PI&&f_dir[i]<-5/6*PI) { m_action[i].mode=0; m_action[i].direction=7; } else if(f_dir[i]>-2/3*PI&&f_dir[i]b_pt.y+r)//鱼在球下面 { m_action[i].speed=15; if(f_dir[i]>5/6*PI&&f_dir[i]<-5/6*PI) { m_action[i].mode=0; m_action[i].direction=7; } else if(f_dir[i]>-PI/2&&f_dir[i]<2/3*PI) { m_action[i].mode=1; m_action[i].direction=14; } else { m_action[i].mode=0; m_action[i].direction=f_dir[i]<0?2:12; } } else//fish is in the same y-axis line with the ball { m_action[i].speed=15; if(f_dir[i]>3/4*PI&&f_dir[i]<-3/4*PI)

14

{ m_action[i].mode=1; m_action[i].direction=f_dir>0?0:14; } else { m_action[i].mode=0; m_action[i].direction=7; } } } } } else { for(int i=0;i<=2;i++) { f_pt[i]=m_FishInfo[i].GetCenterPt();//GetCenterPt()返回中心点坐标 f_dir[i]=m_FishInfo[i].GetDirection(); f_headpt[i]=m_FishInfo[i].GetHeadPoint(); dirfishtoball[i]=this->Angle(f_pt[i],b_pt); disfishtoball[i]=this->Distance(f_pt[i],b_pt); dirfishtoball[i]-=f_dir[i]; dirfishtoball[i]=this->Checkangle(dirfishtoball[i]); dir[i]=dirfishtoball[i]*180/PI; double r=9.0; // tempt[i].x=b_pt.x-9*cos(dirballtogoal); // tempt[i].y=b_pt.y-9*sin(dirballtogoal);//鱼在球左边时的临时目标点。 tempt1[i].x=b_pt.x+9*cos(dirgoaltoball); tempt1[i].y=b_pt.y+9*sin(dirgoaltoball);//鱼在球左边时的临时目标点。 if(f_headpt[i].x>b_pt.x+5)//鱼在球左边 { if(disfishtoball[i]<40)//the velosity change easy to approach { m_action[i].mode=0; m_action[i].speed=13; }

15

else { m_action[i].mode=0; m_action[i].speed=15; } Roundp2p1(tempt1[i],m_action[i],i,m_FishInfo[i]); } else { if(f_pt[i].y-PI/6) { m_action[i].mode=0; m_action[i].direction=7; } else if(f_dir[i]>PI/2&&f_dir[i]<-PI/3) { m_action[i].mode=1; m_action[i].direction=14; } else { m_action[i].mode=0; m_action[i].direction=f_dir[i]<0?11:3; } } else if(f_pt[i].y>b_pt.y+r)//鱼在球下面 { m_action[i].speed=15; if(f_dir[i]-PI/6) { m_action[i].mode=0; m_action[i].direction=7; } else if(f_dir[i]<-PI/2&&f_dir[i]>1/3*PI) { m_action[i].mode=1; m_action[i].direction=0; } else { m_action[i].mode=0;

16

m_action[i].direction=f_dir[i]<0?12:2; } } else//fish is in the same y-axis line with the ball { m_action[i].speed=15; if(f_dir[i]>PI/4&&f_dir[i]<-PI/4) { m_action[i].mode=1; m_action[i].direction=f_dir<0?14:0; } else { m_action[i].mode=0; m_action[i].direction=7; } } } }

}

return TRUE; }

BOOL CStrategy::Strategy3(CFishAction m_action[],CFishInfo m_FishInfo[],CBallInfo &m_goalinfo,CObstaInfo m_obst[],CHANNEL m_Channel[]) {

CPoint f_pt;//鱼的中心点坐标

f_pt=m_FishInfo[0].GetCenterPt();//GetCenterPt()返回中心点坐标 CPoint tempt,tempt0,tempt1,tempt2,tempt3,tempt4,tempt5; static int flag = 0;

tempt0.x = 100; tempt0.y = 50;

tempt1.x = 530; tempt1.y = 240;

17

tempt2.x = 460; tempt2.y = 400;

tempt3.x = 100; tempt3.y = 200;

double disfishtoaim0;

disfishtoaim0=this->Distance(f_pt,tempt0);

double disfishtoaim1;

disfishtoaim1=this->Distance(f_pt,tempt1);

double disfishtoaim2;

disfishtoaim2=this->Distance(f_pt,tempt2);

double disfishtoaim3;

disfishtoaim3=this->Distance(f_pt,tempt3); if( disfishtoaim3 < 80) {

flag = 3;

//Roundp2p1(tempt0,m_action[0],0,m_FishInfo[0]); } /////////////

if(flag == 3) { m_action[0].speed=12;

Roundp2p1(tempt0,m_action[0],0,m_FishInfo[0]); } /* else {

Roundp2p1(tempt3,m_action[0],0,m_FishInfo[0]); } */ //point0 if(disfishtoaim2 < 50) { flag = 2;

//Roundp2p1(tempt1,m_action[0],0,m_FishInfo[0]); }

18

///////////////// if(flag == 2) { m_action[0].speed=12;

Roundp2p1(tempt1,m_action[0],0,m_FishInfo[0]); } /* else {

Roundp2p1(tempt2,m_action[0],0,m_FishInfo[0]); } */ //point1 if(disfishtoaim0 < 80) { flag = 0;

//Roundp2p1(tempt2,m_action[0],0,m_FishInfo[0]); } //////////////// if(flag == 0) { m_action[0].speed=12; //BasicActionGo(m_FishInfo,m_action,0,12,1,0); Roundp2p1(tempt2,m_action[0],0,m_FishInfo[0]); } /*else {

Roundp2p1(tempt0,m_action[0],0,m_FishInfo[0]); } */ //point2 if(disfishtoaim1 < 50) { flag = 1;

//Roundp2p1(tempt3,m_action[0],0,m_FishInfo[0]); } ///////////// if(flag == 1) {

19

m_action[0].speed=12;

//BasicActionGo(m_FishInfo,m_action,0,12,13,0); Roundp2p1(tempt3,m_action[0],0,m_FishInfo[0]); } /* else { Roundp2p1(tempt1,m_action[0],0,m_FishInfo[0]); } */ //point3

return TRUE; }

BOOL CStrategy::Strategy4(CFishAction m_action[],CFishInfo m_FishInfo[],CBallInfo &m_goalinfo,CObstaInfo m_obst[],CHANNEL m_Channel[]) {

CPoint f_pt;//鱼的中心点坐标

f_pt=m_FishInfo[0].GetCenterPt();//GetCenterPt()返回中心点坐标 double f_dir;//鱼的方向,[-PI,PI] f_dir=m_FishInfo[0].GetDirection(); CPoint tempt,tempt0,tempt1,tempt2;

CPoint f_headpt;//point of fish's head f_headpt=m_FishInfo[0].GetHeadPoint();

CPoint b_pt;//球的中心点坐标 b_pt=m_goalinfo.GetBallPt();

20

CPoint g_pt;//球门中心点坐标//distance g_pt=m_Channel[0].center;

if(f_pt.x> 140 &&f_pt.x<485&&f_dir>-(PI)/2&&f_dir<(PI)/2) { tempt.x=485; tempt.y=295; m_action[0].speed=12; Roundp2p1(tempt,m_action[0],0,m_FishInfo[0]); }

if(f_pt.x>140&&f_pt.x<485&&f_dir>-(PI)/2||f_dir>(PI)/2) { tempt0.x=158; tempt0.y=87; m_action[0].speed=12; Roundp2p1(tempt0,m_action[0],0,m_FishInfo[0]); }

if(f_pt.y <= 177&&f_pt.x <=140) { m_action[0].speed=15; m_action[0].direction=0; m_action[0].mode=0; }

if(f_pt.y > 177&&f_pt.x <=140) { tempt.x=485; tempt.y=295; m_action[0].speed=12; Roundp2p(tempt,m_action[0],0,m_FishInfo[0]); }

if(f_pt.x >=485 && f_pt.y >=295) { m_action[0].speed=15; m_action[0].direction=0; m_action[0].mode=0; }

if(f_pt.x >=485 && f_pt.y <295) { tempt0.x=158; tempt0.y=87; m_action[0].speed=12; Roundp2p(tempt0,m_action[0],0,m_FishInfo[0]);

21

}

/*m_action[0].speed=15; m_action[0].direction=0;

m_action[0].mode=0;*///一直转弯

return TRUE; } ///样 BOOL CStrategy::Strategy5(CFishAction m_action[],CFishInfo m_FishInfo[],CBallInfo &m_goalinfo,CObstaInfo m_obst[],CHANNEL m_Channel[]) {

int x=0,y=0; CPoint f_pt; CPoint b_pt; CPoint g_pt;

CPoint FishHeadPt;

FishHeadPt = m_FishInfo[0].GetHeadPoint();

CPoint goal_pt; double f_dir; double b_r;

f_pt = m_FishInfo[0].GetCenterPt(); b_pt = m_goalinfo.GetBallPt(); g_pt = m_Channel[0].center;

f_dir = m_FishInfo[0].GetDirection(); b_r = m_goalinfo.GetRad();

if((FishHeadPt.x<460)&&(x==0)) { goal_pt.x =498; goal_pt.y =260; Roundp2p(goal_pt,m_action[0],0,m_FishInfo[0]); }

else if((FishHeadPt.x>480)&&(FishHeadPt.y<345)&&(x==0)) { BasicActionGo(m_FishInfo,m_action,0,15,10,0);

22

}

else if((FishHeadPt.x>480)&&(FishHeadPt.y>350)&&(y==0)) { y=1; BasicActionGo(m_FishInfo,m_action,0,15,10,0); }

else if((FishHeadPt.x<500)&&(y==1)) { goal_pt.x =194; goal_pt.y =93; Roundp2p(goal_pt,m_action[0],0,m_FishInfo[0]); }

else { BasicActionGo(m_FishInfo,m_action,0,0,0,0); }

return TRUE; }

BOOL CStrategy::Strategy6(CFishAction m_FishInfo[],CBallInfo &m_goalinfo,CObstaInfo m_Channel[]) {

return TRUE; }

BOOL CStrategy::Strategy7(CFishAction m_FishInfo[],CBallInfo &m_goalinfo,CObstaInfo m_Channel[]) {

return TRUE; }

BOOL CStrategy::Strategy8(CFishAction m_FishInfo[],CBallInfo &m_goalinfo,CObstaInfo m_Channel[]) {

return TRUE; }

BOOL CStrategy::Strategy9(CFishAction m_FishInfo[],CBallInfo &m_goalinfo,CObstaInfo m_Channel[])

m_action[],CFishInfo m_obst[],CHANNEL m_action[],CFishInfo m_obst[],CHANNEL m_action[],CFishInfo m_obst[],CHANNEL m_action[],CFishInfo m_obst[],CHANNEL 23

{

return TRUE; //不知返回什么意思... }

BOOL CStrategy::Strategy10(CFishAction m_FishInfo[],CBallInfo &m_goalinfo,CObstaInfo m_Channel[]) {

return TRUE; }

BOOL CStrategy::Strategy11(CFishAction m_FishInfo[],CBallInfo &m_goalinfo,CObstaInfo m_Channel[]) {

return TRUE; }

BOOL CStrategy::Strategy12(CFishAction m_FishInfo[],CBallInfo &m_goalinfo,CObstaInfo m_Channel[]) {

return TRUE; }

BOOL CStrategy::Strategy13(CFishAction m_FishInfo[],CBallInfo &m_goalinfo,CObstaInfo m_Channel[]) {

return TRUE; }

BOOL CStrategy::Strategy14(CFishAction m_FishInfo[],CBallInfo &m_goalinfo,CObstaInfo m_Channel[]) {

return TRUE; }

BOOL CStrategy::Strategy15(CFishAction m_FishInfo[],CBallInfo &m_goalinfo,CObstaInfo m_Channel[]) {

return TRUE; }

DOUBLE CStrategy::Distance(CPoint point,CPoint aimer) {

double a;

m_action[],CFishInfo m_obst[],CHANNEL m_action[],CFishInfo m_obst[],CHANNEL m_action[],CFishInfo m_obst[],CHANNEL m_action[],CFishInfo m_obst[],CHANNEL m_action[],CFishInfo m_obst[],CHANNEL m_action[],CFishInfo m_obst[],CHANNEL 24

a=sqrt((double)(point.x-aimer.x)*(point.x-aimer.x)+(double)(point.y-aimer.y)*(point.y-aimer.y)); return a; }

DOUBLE CStrategy::Checkangle(double dir)//////////////////////////把dir换算成[-pi~pi]之间的数 {

if(dir>PI) dir-=2*PI; else if(dir<-PI) dir+=2*PI; return dir; }

void CStrategy::Roundp2p(CPoint aimpt,CFishAction &action,int fishID,CFishInfo m_FishInfo) {

CPoint FishPt;// 鱼中心的位置 double FishDir;// 鱼头的方向 CPoint FishHeadPt;//鱼头的位置 CPoint LastFishPt;

CPoint FishRotatePt;//鱼的转动位置 CPoint FishTailPt;//鱼尾巴的位置

CPoint GoalPt1, GoalPt2;//临时目标点,GoalPt2没有用到 CPoint Pt1, Pt2, Pt3, Pt4;

//CPoint f_headpt;//point of fish's head //f_headpt=m_FishInfo[0].GetHeadPoint();

double dir1=0; double dir0; double dist0; double dist1=0; double dir2=0;

double dist2=0;//临时用到的方向和距离

CPoint centerpt1,centerpt2;//作为鱼要绕的中心来用 CPoint centerpt3,centerpt4,centerpt5,centerpt6; CPoint centerpt0,centerpt00; double dis1,dis2; dis1=0; dis2=0;

double radius;///需要游动的半径,可以随意的设置. FishPt=m_FishInfo.GetCenterPt(); FishDir=m_FishInfo.GetDirection(); dist1=Distance(FishPt,aimpt); dir1=Angle(FishPt,aimpt);

25

dir1-=FishDir;

dir1=Checkangle(dir1)*180/PI; action.speed=15;

m_FishInfo.SetAction(action); if(dist1>100) { if(dir1>-5&&dir1<5) action.direction=7; else if(dir1<-5&&dir1>-10) action.direction=5; else if(dir1<-10&&dir1>-30) action.direction=4; else if(dir1<-30&&dir1>-50) action.direction=2; else if(dir1<-50&&dir1>-70) action.direction=1; else if(dir1<-70&&dir1>-90) action.direction=0; else if(dir1<-90) action.direction=0; else if(dir1>5&&dir1<10) action.direction=9; else if(dir1>10&&dir1<20) action.direction=10; else if(dir1>20&&dir1<40) action.direction=12; else if(dir1>40&&dir1<50) action.direction=12; else if(dir1>50&&dir1<80) action.direction=14; else if(dir1>80&&dir1<90) action.direction=14; else action.direction=14; }

else { if(dir1>-5&&dir1<5) action.direction=7; else if(dir1<-5&&dir1>-20) action.direction=4; else if(dir1<-20&&dir1>-40) action.direction=1;

26

else if(dir1<-40&&dir1>-60) action.direction=0; else if(dir1<-60&&dir1>-70) action.direction=0; else if(dir1<-70&&dir1>-90) action.direction=0; else if(dir1<-120) action.direction=0; else if(dir1>5&&dir1<20) action.direction=10; else if(dir1>20&&dir1<30) action.direction=12; else if(dir1>30&&dir1<50) action.direction=13; else if(dir1>50&&dir1<70) action.direction=14; else if(dir1>70&&dir1<90) action.direction=14; else if(dir1<120) action.direction=14; else action.direction=14;

}

m_FishInfo.SetAction(action); }

void CStrategy::con2tempt(CPoint aimpt,CFishAction m_action[],CFishInfo m_FishInfo[])//游到一个临时点后退出 { //获取鱼的信息

CPoint f_pt;//鱼的中心点坐标

f_pt=m_FishInfo[0].GetCenterPt();//GetCenterPt()返回中心点坐标 double f_dir;//鱼的方向,[-PI,PI] f_dir=m_FishInfo[0].GetDirection();

//获取球的信息

//CPoint b_pt;//球的中心点坐标 //b_pt=m_goalinfo.GetBallPt(); //int b_r;

//b_r=m_goalinfo.GetRad();

//获取球门信息

//CPoint g_pt;//球门中心点坐标//distance //g_pt=m_Channel[0].center;

27

//int g_w;//球门宽度

//g_w=m_Channel[0].width;

CPoint f_headpt;//point of fish's head f_headpt=m_FishInfo[0].GetHeadPoint();

double disheadtoaimpt;

disheadtoaimpt=this->Distance(f_headpt,aimpt);

bool tem=true;

if(tem) { Roundp2p(aimpt,m_action[0],0,m_FishInfo[0]); if(disheadtoaimpt<10) tem=false; } }

double CStrategy::Angle(CPoint point,CPoint aimer) {

double a;

a=atan2((double)(aimer.y-point.y),(double)(aimer.x-point.x)); return a;

//return point.x; }

void CStrategy::Point2point(CPoint aimpt,CFishAction &action, CFishInfo m_FishInfo) {

CPoint FishPt;// 鱼中心的位置 double FishDir;// 鱼头的方向 CPoint FishHeadPt;//鱼头的位置 CPoint LastFishPt;

CPoint FishRotatePt;//鱼的转动位置 CPoint FishTailPt;//鱼尾巴的位置

CPoint GoalPt1, GoalPt2;//临时目标点,GoalPt2没有用到 CPoint Pt1, Pt2, Pt3, Pt4; double dir1=0; double dir0; double dist0; double dist1=0; double dir2=0;

int fishID, 28

double dist2=0;//临时用到的方向和距离

CPoint centerpt1,centerpt2;//作为鱼要绕的中心来用 CPoint centerpt3,centerpt4,centerpt5,centerpt6; CPoint centerpt0,centerpt00; double dis1,dis2; dis1=0; dis2=0;

double radius;///需要游动的半径,可以随意的设置. FishPt=m_FishInfo.GetCenterPt(); FishDir=m_FishInfo.GetDirection(); dist1=Distance(FishPt,aimpt); dir1=Angle(FishPt,aimpt); dir1-=FishDir;

dir1=Checkangle(dir1)*180/PI; action.speed=15; if(dir1>-5&&dir1<5) action.direction=7; else if(dir1<-5&&dir1>-10) action.direction=5;

else if(dir1<-10&&dir1>-30) action.direction=4;

else if(dir1<-30&&dir1>-50) action.direction=2;

else if(dir1<-50&&dir1>-70) action.direction=1;

else if(dir1<-70&&dir1>-90) action.direction=0; else if(dir1<-90) action.direction=0; else if(dir1>5&&dir1<10) action.direction=9; else if(dir1>10&&dir1<20) action.direction=10; else if(dir1>20&&dir1<40) action.direction=12; else if(dir1>40&&dir1<50) action.direction=12; else if(dir1>50&&dir1<80) action.direction=14; else if(dir1>80&&dir1<90) action.direction=14; else action.direction=14;

}

29

30

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- 7swz.com 版权所有 赣ICP备2024042798号-8

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务