1、机器人足球代码1汇编足球机器人程序代码 /应用程序模板 #include /判断自身与球的方位是否危险bool AzimuthDanger() double ballX = getBallX(); double myX = getX(); double radius = getBallRadius()+getRadius(); if(getAttack()0 & myX+radius*2ballX) return true; if(getAttack()0 & myX-radius*20 & getBallX()getCourtWidth()/2) | (getAttack()getCourt
2、Width()/2) ) if(getBallY()getCourtHeight()/2)&(getY()getBallY()return true; if(getBallY()getCourtHeight()/2)&(getY()0 & getBallHeading()PI/2 & getBallHeading()PI*3/2) if(goalMin50*tan(getBallHeading() + b)return true; else return false;else if(getAttack()=0 & getBallHeading()PI/2 | getBallHeading()3
3、*PI/2) if(goalMintan(getBallHeading()*(getCourtWidth() - 50) + b & tan(getBallHeading()*(getCourtWidth() - 50) + bgoalMax) return true; else return false;else return false;/预测足球在times个单位时间后的位置void Next(int times, double* nextX, double* nextY)double velocity = getBallVelocity();double heading = getBa
4、llHeading();double acc = -getBallNegativeAcceleration();*nextX = getBallX();*nextY = getBallY();for (int i = 0; i 0) velocity = fmax(0, velocity+acc); else if (velocity 0) velocity = fmin(0, velocity -acc); / 撞墙检测 if (*nextX) getCourtWidth() heading = PI - heading; modifyInCourt(nextX, nextY, getBal
5、lRadius(); if (*nextY) getCourtHeight() heading = -heading; modifyInCourt(nextX, nextY, getBallRadius(); / 跌代计算球的运行线路,计算未来的击球点void OptimumPosition(double* hitedX ,double* hitedY ) *hitedX = getBallX(); *hitedY = getBallY(); for (int i = 0; i 200; i+) double nextX, nextY; Next(i, &nextX, &nextY); if
6、(distance(nextX, nextY, getX(), getY() 0? 1:0; struct Bot bot; getBotById(id, &bot); return bot.x;double getBotY() int id = getAttack()0? 1:0; struct Bot bot; getBotById(id, &bot); return bot.y;double getBotVelocity() int id = getAttack()0? 1:0; struct Bot bot; getBotById(id, &bot); return bot.moveV
7、elocity;bool BotBallBotDistance()double MDistance = distance(getX(), getY(), getBallX(), getBallY();double DDistance = distance(getBotX(), getBotY(), getBallX(), getBallY();if(MDistancegetMaxMoveVelocity()/2) ? Rn=1.1 : Rn=0.93; double MDDistance = distance(getX(), getY(), getBotX(), getBotY(); /争球
8、if(getBallVelocity() getMaxMoveVelocity()/2 & MDDistance=getBallRadius()*2+getRadius()*2 & (getX()=getBotX() | getY()=getBotY() Rn=0.1; if(getBotVelocity()=0) Rn=0.93;/R越小,抢劫能力就越强,R越大,防守能力越强double R =(getBallRadius() + getRadius()*Rn);double tangentX1, tangentX2, tangentY1, tangentY2; double bestHit
9、X, bestHitY; double distanceToTarget = distance(targetX, targetY, getX(), getY();if(distanceToTargetR) setMoveToward(targetX, targetY, getMaxMoveVelocity();return;double tangentBearing = acos(R/distanceToTarget);double ballToMeHeading = heading(ballX, ballY, getX(), getY();nextPoint(ballX, ballY, ba
10、llToMeHeading + tangentBearing,R,&tangentX1, &tangentY1);nextPoint(ballX, ballY,ballToMeHeading - tangentBearing,R,&tangentX2, &tangentY2);nextPoint(ballX, ballY,heading(targetX, targetY, ballX, ballY),R,&bestHitX, &bestHitY);modifyInCourt(&tangentX1, &tangentY1, getRadius();modifyInCourt(&tangentX2
11、, &tangentY2, getRadius();modifyInCourt(&bestHitX, &bestHitY, getRadius();double xx=0;double yy=0;if (distance(getX(), getY(), bestHitX, bestHitY) distance(getX(), getY(), tangentX1, tangentY1) xx=bestHitX; yy=bestHitY;else if (distance(bestHitX, bestHitY, tangentX1, tangentY1) (getBallRadius()+getR
12、adius()*3 | getX()0 ? getBallRadius()-getRadius() : getRadius()-getBallRadius(); yy = MIN(getCourtHeight()-jj, yy); yy = MAX(jj, yy); /抄近路拦截 double MDistance = distance(getX(), getY(), getBallX(), getBallY(); double DDistance = distance(getBotX(), getBotY(), getBallX(), getBallY(); if(DDistancegetMo
13、veVelocity()/2) int fx; if(getBallY()getCourtHeight()/2)fx=1; else fx=-1; yy+=fx*getBallRadius()*2; /沿对门边路滚动时的防范措施 if(getBallHeading()=PI/2 | getBallHeading()=3*PI/2) double bx=getAttack()0 ? getCourtWidth()-getBallRadius() : getBallRadius(); if(getBallX()=bx & getBallVelocity()getMaxMoveVelocity()*
14、2/3) double jj=getBallRadius(); xx=getAttack()0? xx-jj : xx+jj; setMoveToward(xx, yy, getMaxMoveVelocity();void ShootGoal() /射门 double targetX = getOpponentGoalCenterX(); double targetY = getOpponentGoalCenterY(); Shoot(targetX, targetY); void ShootAttack() /带球射门 波浪式进攻 double targetX= getAttack()0 ?
15、 getBallX()*2 : getBallX()/2; double targetY=0; if( (getAttack()0 & getBallX()getCourtWidth()*3/5) | (getAttack()getCourtWidth()*2/5) ) if(getY()getBallY()targetY=getCourtHeight(); if(getBallY()0 & myXballX+Radius) | (getAttack()0 & myXgetBallY() targetY=0; else targetY=getCourtHeight(); Shoot(targe
16、tX, targetY); /预测防守void ForecastGuard()double x = getAttack() 0 ? getBallX()/2 : getCourtWidth()-(getCourtWidth()-getBallX()/2;double y = getBallY();for(int i=0; i0&nextX=x) | (getAttack()=x) y = nextY; break; /将y坐标限制在球门的范围内y = MIN(getCourtHeight() / 2 + getGoalWidth() / 2, y);y = MAX(getCourtHeight
17、() / 2 - getGoalWidth() / 2, y);setMoveTo(x, y);void myGuard() double x = getAttack()0 ? getBallX()/2 : getCourtWidth()-(getCourtWidth()-getBallX()/2; double y = getBallY(); y = MIN(getCourtHeight()/2+getGoalWidth()/2, y); y = MAX(getCourtHeight()/2-getGoalWidth()/2, y); setMoveTo(x, y);/全力防守void Go
18、AllOutGuard()double x = getAttack()0 ? getBallX()/2 : getCourtWidth()-(getCourtWidth()-getBallX()/2;double y = getBallY();y = MIN(getCourtHeight()/2+getGoalWidth()/2+getRadius()*2*2, y);y = MAX(getCourtHeight()/2-getGoalWidth()/2-getRadius()*2*2, y);setMoveTo(x, y);/防守反击void Guard()double Radius = g
19、etBallRadius()*2 + getRadius()*2;double Distance = distance(getX(), getY(), getBallX(), getBallY();if(DistanceRadius*10) myGuard(); else GoAllOutGuard();if(!AzimuthDanger()ShootAttack();return; /方位安全时攻击if(isHitBall() & !AzimuthDanger() & getBallVelocity()getMoveVelocity()/4) ShootAttack();return;if(
20、BotBallBotDistance()ShootGoal(); /如果自己离球的距离小于敌人则进攻/判断进攻还是防守void AttackOrGuard() if(AzimuthDanger() & getBallVelocity()0)Guard();return; if(JudgeDanger() & getBallVelocity()getMaxMoveVelocity()/2)Guard();return; ShootAttack();/进攻门前争球void GuardConfrontEachOther() double Radius = getRadius()+getBallRad
21、ius()/2; double xx=getAttack()0 ? Radius : getCourtWidth()-Radius; double MaxY = getCourtHeight() / 2 + getGoalWidth() / 2 + getRadius()*4; double MinY = getCourtHeight() / 2 - getGoalWidth() / 2 - getRadius()*4; if(getBallVelocity()getMaxMoveVelocity()/2) if (getAttack()0 & getX()MaxY | getY()MinY) setMoveToward(getBall
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1