00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00048 #include "Player.h"
00049 #include "ArsToolbox.h"
00050 #include "SoccerTypes.h"
00051 #include <Math.h>
00052 #include <stdio.h>
00053
00054
00055 #define LOG_SITUATIONS
00056
00057
00058 SoccerCommand Player::kickToScore( ){
00059 SoccerCommand soc(CMD_ILLEGAL);
00061
00063
00064 double goalWidth = SS->getGoalWidth();
00065 double a = goalWidth * 0.5;
00066 int samples = 100;
00067
00068 const int IN_Y_GOALIE = 0;
00069 const int IN_ME_TO_GOALIE = 1;
00070 const int OUT_Y_DIRECTION = 0;
00071
00072 const int BRANKAR_VLAVO = 0;
00073 const int BRANKAR_TROCHU_VLAVO = 1;
00074 const int BRANKAR_TROCHU_VPRAVO = 2;
00075 const int BRANKAR_VPRAVO = 3;
00076
00077 const int NALAVO_OD_BRANKARA = 0;
00078 const int BRANKAR_PREDOMNOU = 1;
00079 const int NAPRAVO_OD_BRANKARA = 2;
00080
00081 const int KOPNI_EX_VLAVO = 0;
00082 const int KOPNI_VLAVO = 1;
00083 const int KOPNI_VPRAVO = 2;
00084 const int KOPNI_EX_VPRAVO = 3;
00085
00086 cFuzzyObj * fz = new cFuzzyObj();
00087 fz->SetSamples(samples);
00088
00089 fz->AddInput(-a, a);
00090 fz->AddInput(-a, a);
00091 fz->AddOutput(-a, a);
00092
00093 fz->AddInputMF(IN_Y_GOALIE, FZ_LEFT, -0.75*a, -0.4*a);
00094 fz->AddInputMF(IN_Y_GOALIE, FZ_TRAPEZOID, -0.6*a, -0.3*a, -0.03*a, 0.0*a);
00095 fz->AddInputMF(IN_Y_GOALIE, FZ_TRAPEZOID, 0.0*a, 0.03*a, 0.3*a, 0.6*a);
00096 fz->AddInputMF(IN_Y_GOALIE, FZ_RIGHT, 0.4*a, 0.75*a);
00097
00098 fz->AddInputMF(IN_ME_TO_GOALIE, FZ_LEFT, -0.9*a, -0.2*a);
00099 fz->AddInputMF(IN_ME_TO_GOALIE, FZ_TRAPEZOID, -0.3*a, -0.2*a, 0.2*a, 0.3*a);
00100 fz->AddInputMF(IN_ME_TO_GOALIE, FZ_RIGHT, 0.2*a, 0.9*a);
00101
00102
00103 fz->AddOutputMF(OUT_Y_DIRECTION, FZ_TRIANGLE, -a, -0.9*a, -0.8*a);
00104 fz->AddOutputMF(OUT_Y_DIRECTION, FZ_TRAPEZOID, -0.9*a, -0.8*a, -0.6*a, -0.4*a);
00105 fz->AddOutputMF(OUT_Y_DIRECTION, FZ_TRAPEZOID, 0.4*a, 0.6*a, 0.8*a, 0.9*a);
00106 fz->AddOutputMF(OUT_Y_DIRECTION, FZ_TRIANGLE, 0.8*a, 0.9*a, a);
00107
00108 fz->AddRule(OUT_Y_DIRECTION, BRANKAR_VLAVO, NALAVO_OD_BRANKARA , KOPNI_EX_VLAVO);
00109 fz->AddRule(OUT_Y_DIRECTION, BRANKAR_VLAVO, BRANKAR_PREDOMNOU , KOPNI_VPRAVO);
00110 fz->AddRule(OUT_Y_DIRECTION, BRANKAR_VLAVO, NAPRAVO_OD_BRANKARA, KOPNI_VPRAVO);
00111
00112 fz->AddRule(OUT_Y_DIRECTION, BRANKAR_TROCHU_VLAVO, NALAVO_OD_BRANKARA , KOPNI_EX_VLAVO);
00113 fz->AddRule(OUT_Y_DIRECTION, BRANKAR_TROCHU_VLAVO, BRANKAR_PREDOMNOU , KOPNI_EX_VPRAVO);
00114 fz->AddRule(OUT_Y_DIRECTION, BRANKAR_TROCHU_VLAVO, NAPRAVO_OD_BRANKARA , KOPNI_VPRAVO);
00115
00116 fz->AddRule(OUT_Y_DIRECTION, BRANKAR_TROCHU_VPRAVO, NALAVO_OD_BRANKARA , KOPNI_VLAVO);
00117 fz->AddRule(OUT_Y_DIRECTION, BRANKAR_TROCHU_VPRAVO, BRANKAR_PREDOMNOU , KOPNI_EX_VLAVO);
00118 fz->AddRule(OUT_Y_DIRECTION, BRANKAR_TROCHU_VPRAVO, NAPRAVO_OD_BRANKARA , KOPNI_EX_VPRAVO);
00119
00120 fz->AddRule(OUT_Y_DIRECTION, BRANKAR_VPRAVO, NALAVO_OD_BRANKARA , KOPNI_VLAVO);
00121 fz->AddRule(OUT_Y_DIRECTION, BRANKAR_VPRAVO, BRANKAR_PREDOMNOU , KOPNI_VLAVO);
00122 fz->AddRule(OUT_Y_DIRECTION, BRANKAR_VPRAVO, NAPRAVO_OD_BRANKARA , KOPNI_EX_VPRAVO);
00123
00124
00125 VecPosition gp = WM->getGlobalPosition(OBJECT_OPPONENT_GOALIE);
00126 double opp_goalie_position = gp.getY();
00127 if(opp_goalie_position < -a) {
00128 opp_goalie_position = -a;
00129 }
00130 if(opp_goalie_position > a) {
00131 opp_goalie_position = a;
00132 }
00133
00134 VecPosition myPos = WM->getAgentGlobalPosition();
00135 VecPosition diff = myPos - gp;
00136 double my_rel_pos = diff.getY();
00137
00138 if(my_rel_pos<0) {
00139 if(my_rel_pos < -a) {
00140 my_rel_pos = -a;
00141 }
00142 }
00143 else {
00144 if(my_rel_pos > a) {
00145 my_rel_pos = a;
00146 }
00147 }
00148
00149 double y_direction = fz->CountResult(OUT_Y_DIRECTION, DFZ_CENTROID, OPS_ZADEH, opp_goalie_position, my_rel_pos);
00150 delete fz;
00151
00153
00155
00156 VecPosition posGoal( PITCH_LENGTH/2.0, y_direction );
00157 soc = kickTo( posGoal, SS->getBallSpeedMax() );
00158
00159 ACT->putCommandInQueue( soc );
00160 ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) );
00161 Log.log( 100, "kick ball" );
00162 return soc;
00163 }
00164
00165 SoccerCommand Player::kickToDrible( ) {
00166 SoccerCommand soc(CMD_ILLEGAL);
00167 Log.log(100, "Kicking to drible");
00168
00169 VecPosition posGoal( PITCH_LENGTH/2.0,
00170 (-1 + 2*(WM->getCurrentCycle()%2)) * 0.4 * SS->getGoalWidth() );
00171 soc = kickTo( posGoal, SS->getBallSpeedMax() / 30 );
00172
00173 ACT->putCommandInQueue( soc );
00174 ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) );
00175 Log.log( 100, "kick ball" );
00176 }
00177
00178
00192 double Player::passToFitness(double from1X, double from1Y, double to1X, double to1Y, double pX, double pY, double toX, double toY, double r) {
00193
00194
00195
00196 double dist = VecPosition::pointsDistance(from1X, from1Y, toX, toY);
00197 double fdist1 = (30 * dist / RAY_LENGTH);
00198 double fdist2 = (ArsToolbox::linePointDistance(
00199 from1X,
00200 from1Y,
00201 to1X,
00202 to1Y,
00203 pX,
00204 pY
00205 ) / (r + 1.0) + 1.0);
00206 double f = fdist1 / fdist2;
00207 if (dist > 20)
00208 f -= 2 * (RAY_LENGTH - dist) / RAY_LENGTH;
00209
00210 return ArsToolbox::trim(f, 0, 12);
00211 }
00212
00226 double Player::passToTeammateFitness(double from1X, double from1Y, double to1X, double to1Y, double pX, double pY, double toX, double toY, double r) {
00227 double f1 = ArsToolbox::trim(
00228 1.3 * passToFitness(
00229 from1X,
00230 from1Y,
00231 to1X,
00232 to1Y,
00233 pX,
00234 pY,
00235 toX,
00236 toY,
00237 r
00238 ), 0, 12);
00239
00240
00241 double f2 =
00242 (toX - from1X >= 0 ? 0.5 : -1.5)
00243 +
00244 ArsToolbox::trim(
00245 2 * (toX - from1X)
00246 /
00247 ArsToolbox::trim(
00248 PITCH_LENGTH - goalMiddle.getDistanceTo(toX, toY),
00249 0.1,
00250 PITCH_LENGTH),
00251 -4,
00252 2
00253 );
00254
00255 return ArsToolbox::trim(f1 + f2, 0, 12);
00256 }
00257
00271 double Player::passToOpponentFitness(double from1X, double from1Y, double to1X, double to1Y, double pX, double pY, double toX, double toY, double r) {
00272 return 0.7 * passToFitness(
00273 from1X,
00274 from1Y,
00275 to1X,
00276 to1Y,
00277 pX,
00278 pY,
00279 toX,
00280 toY,
00281 r
00282 ) + 3.0;
00283 }
00284
00285 bool Player::isPassBlocked(ObjectT oPlayer, AngRad ang) {
00286 }
00287
00288 double Player::leadingPass(ObjectT oPlayer, AngRad ang) {
00289
00290 }
00291
00308 double Player::passTo( AngRad angle, ObjectT oPlayer, VecPosition
00309 *pos, double dConfThr) {
00310 VecPosition vec1 = WM->getAgentGlobalPosition();
00311 double x, y;
00312 double nx, ny, nd;
00313 double fit, tfit = -12, ofit = 0;
00314 int iIndex;
00315 double p1x, p1y, p2x, p2y;
00316 VecPosition posObj(0, 0);
00317 double dDist;
00318 double r;
00319
00320
00321 ArsToolbox::createLineTo(vec1.getX(), vec1.getY(), angle, RAY_LENGTH, &x, &y);
00322 nx = 0;
00323 ny = 0;
00324 nd = RAY_LENGTH;
00325
00326
00327 for( ObjectT o = WM->iterateObjectStart( iIndex, OBJECT_SET_TEAMMATES_NO_GOALIE, dConfThr);
00328 o != OBJECT_ILLEGAL;
00329 o = WM->iterateObjectNext ( iIndex, OBJECT_SET_TEAMMATES_NO_GOALIE, dConfThr) )
00330 {
00331
00332 posObj = WM->getGlobalPosition( o );
00333 dDist = posObj.getDistanceTo( vec1 );
00334
00335
00336 r = getInterestRadius(dDist);
00337
00338
00339 if (dDist > 1 && ArsToolbox::circleLineIntersection(
00340 vec1.getX(),
00341 vec1.getY(),
00342 x,
00343 y,
00344 posObj.getX(),
00345 posObj.getY(),
00346 r,
00347 &p1x,
00348 &p1y,
00349 &p2x,
00350 &p2y) > 0)
00351 {
00352
00353 fit = passToTeammateFitness(
00354 vec1.getX(),
00355 vec1.getY(),
00356 x,
00357 y,
00358 posObj.getX(),
00359 posObj.getY(),
00360 p2x,
00361 p2y,
00362 r
00363 );
00364
00365 if (fit > tfit) {
00366 tfit = fit;
00367 nx = p2x;
00368 ny = p2y;
00369 nd = dDist;
00370 }
00371
00372 #ifdef LOG_SITUATIONS
00373
00374 log->addObject(LOG_PLAYER_TEAM, posObj.getX(),posObj.getY());
00375 log->addObject(LOG_CIRCLE, posObj.getX(), posObj.getY(), r);
00376 #endif
00377 }
00378 }
00379 WM->iterateObjectDone( iIndex );
00380
00381
00382 for( ObjectT o = WM->iterateObjectStart( iIndex, OBJECT_SET_OPPONENTS, dConfThr );
00383 o != OBJECT_ILLEGAL;
00384 o = WM->iterateObjectNext ( iIndex, OBJECT_SET_OPPONENTS, dConfThr ) )
00385 {
00386 posObj = WM->getGlobalPosition( o );
00387 dDist = posObj.getDistanceTo( vec1 );
00388 r = getInterestRadius(dDist);
00389
00390
00391 if ((dDist < nd + 8.0) && ArsToolbox::circleLineIntersection(
00392 vec1.getX(),
00393 vec1.getY(),
00394 x,
00395 y,
00396 posObj.getX(),
00397 posObj.getX(),
00398 r,
00399 &p1x,
00400 &p1y,
00401 &p2x,
00402 &p2y) > 0)
00403 {
00404 fit = passToOpponentFitness(
00405 vec1.getX(),
00406 vec1.getY(),
00407 x,
00408 y,
00409 posObj.getX(),
00410 posObj.getY(),
00411 p1x,
00412 p1y,
00413 r
00414 );
00415
00416 if (fit > ofit)
00417 ofit = fit;
00418 #ifdef LOG_SITUATIONS
00419
00420 log->addObject(LOG_PLAYER_OTHER, posObj.getX(), posObj.getY());
00421 log->addObject(LOG_CIRCLE, posObj.getX(), posObj.getY(), r);
00422 #endif
00423 }
00424 }
00425 WM->iterateObjectDone( iIndex );
00426
00427 if (pos != NULL) {
00428 pos->setX(nx);
00429 pos->setY(ny);
00430 }
00431
00432 #ifdef LOG_SITUATIONS
00433
00434 log->addObject(LOG_PLAYER_OTHER, posObj.getX(), posObj.getY());
00435 log->addObject(LOG_LINE, vec1.getX(), vec1.getY(), nx, ny, "white", ArsToolbox::trim(tfit - ofit, 0, 12));
00436 #endif
00437
00438 return ArsToolbox::trim(tfit - ofit, 0, 12);
00439 }
00440
00451 SoccerCommand Player::circleKickToPass(double* dFitness ) {
00452 VecPosition vec1 = WM->getAgentGlobalPosition();
00453 VecPosition pos(0, 0), tpos(0, 0);
00454 double tfit, fit = -12;
00455
00456
00457 for (int i = 0; i < KICK_RAYS_NR; i++) {
00458 tfit = passTo(
00459 (2.0 * M_PI * KICK_RAYS_NR) / (i + 1),
00460 OBJECT_SELECT_PLAYER,
00461 &tpos
00462 );
00463 if (tfit > fit) {
00464 fit = tfit;
00465 pos.setX(tpos.getX());
00466 pos.setY(tpos.getY());
00467 }
00468 }
00469
00470
00471 double speed = ArsToolbox::trim(pos.getDistanceTo(vec1)/50 * SS->getBallSpeedMax(), 0, SS->getBallSpeedMax());
00472
00473
00474 SoccerCommand soc(CMD_ILLEGAL);
00475 soc = kickTo( pos, speed );
00476 #ifdef LOG_SITUATIONS
00477
00478 log->addObject(LOG_PLAYER_ACTIVE, vec1.getX(), vec1.getY());
00479 log->addObject(LOG_LINE, vec1.getX(), vec1.getY(), pos.getX(), pos.getY(), "Yellow");
00480 #endif
00481
00482 if (dFitness != NULL)
00483 *dFitness = fit;
00484
00485 return soc;
00486 }
00487
00495 SoccerCommand Player::kickToPass(double* dFitness){
00496 SoccerCommand soc(CMD_ILLEGAL);
00497
00498 #ifdef LOG_SITUATIONS
00499 log->situationBegin("Prihravka", WM->getCurrentCycle());
00500 #endif
00501
00502 soc = circleKickToPass(dFitness);
00503
00504 #ifdef LOG_SITUATIONS
00505 log->situationEnd();
00506 #endif
00507 return soc;
00508 }
00509
00512 SoccerCommand Player::kickToPlay() {
00513 SoccerCommand soc(CMD_ILLEGAL);
00514 double speed;
00515 double dis;
00516 ObjectT obj;
00517
00518 obj = WM->getClosestRelativeInSet(OBJECT_SET_TEAMMATES_NO_GOALIE, &dis, 2.0, NULL);
00519
00520
00521 if (obj == OBJECT_ILLEGAL){
00522 kickToScore();
00523 } else {
00524 VecPosition vec1 = WM->getGlobalPosition(obj);
00525 speed = SS->getBallSpeedMax() * 0.5;
00526 soc = kickTo(vec1, speed);
00527 ACT->putCommandInQueue( soc );
00528 ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) );
00529 }
00530 return soc;
00531 }
00532
00543 SoccerCommand Player::deMeer5( )
00544 {
00545
00546 SoccerCommand soc(CMD_ILLEGAL);
00547 VecPosition posAgent = WM->getAgentGlobalPosition();
00548 VecPosition posBall = WM->getBallPos();
00549 int iTmp;
00550
00551 if( WM->isBeforeKickOff( ) )
00552 {
00553 if( WM->isKickOffUs( ) && WM->getPlayerNumber() == 9 )
00554 {
00555 if( WM->isBallKickable() )
00556 {
00557 VecPosition posGoal( PITCH_LENGTH/2.0,
00558 (-1 + 2*(WM->getCurrentCycle()%2)) *
00559 0.4 * SS->getGoalWidth() );
00560
00561 soc = kickToPass();
00562 Log.log( 100, "take kick off" );
00563 }
00564 else
00565 {
00566 soc = intercept( false );
00567 Log.log( 100, "move to ball to take kick-off" );
00568 }
00569 ACT->putCommandInQueue( soc );
00570 ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) );
00571 return soc;
00572 }
00573 if( formations->getFormation() != FT_INITIAL ||
00574 posAgent.getDistanceTo( WM->getStrategicPosition() ) > 2.0 )
00575 {
00576 formations->setFormation( FT_INITIAL );
00577 ACT->putCommandInQueue( soc=teleportToPos( WM->getStrategicPosition() ));
00578 }
00579 else
00580 {
00581 ACT->putCommandInQueue( soc=turnBodyToPoint( VecPosition( 0, 0 ), 0 ) );
00582 ACT->putCommandInQueue( alignNeckWithBody( ) );
00583 }
00584 }
00585
00586 else if(WM->isDeadBallUs() && !WM->isGoalKickUs()) {
00587 if(WM->isBallKickable()) {
00588 soc = kickToPlay();
00589
00590 }
00591 else if(WM->getFastestInSetTo( OBJECT_SET_TEAMMATES, OBJECT_BALL, &iTmp)
00592 == WM->getAgentObjectType()) {
00593
00594
00595 soc = moveToPos(posBall, PS->getPlayerWhenToTurnAngle());
00596 if( soc.commandType == CMD_DASH &&
00597 WM->getAgentStamina().getStamina() <
00598 SS->getRecoverDecThr()*SS->getStaminaMax()+200 )
00599 {
00600 soc.dPower = 30.0 * WM->getAgentStamina().getRecovery();
00601 ACT->putCommandInQueue( soc );
00602 ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) );
00603 }
00604 else
00605 {
00606 ACT->putCommandInQueue( soc );
00607 ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) );
00608 }
00609 return soc;
00610 }
00611
00612
00613
00614
00615 else {
00616 ACT->putCommandInQueue( soc = turnAround());
00617 ACT->putCommandInQueue( alignNeckWithBody( ) );
00618 }
00619 }
00620 else if(WM->isDeadBallThem()) {
00621 ACT->putCommandInQueue( soc = turnAround());
00622 ACT->putCommandInQueue( alignNeckWithBody( ) );
00623 }
00624 else
00625 {
00626
00627 formations->setFormation( FT_433_OFFENSIVE );
00628 soc.commandType = CMD_ILLEGAL;
00629
00630 double distance = posAgent.getDistanceTo(posBall);
00631
00632
00633 SoccerCommand sc = adjustView(distance);
00634 if(sc.commandType != CMD_ILLEGAL) {
00635 ACT->putCommandInQueue(sc);
00636 }
00637
00638 if( WM->getConfidence( OBJECT_BALL ) < PS->getBallConfThr() )
00639 {
00640 ACT->putCommandInQueue( soc = searchBall() );
00641 ACT->putCommandInQueue( alignNeckWithBody( ) );
00642 }
00643 else if( WM->isBallKickable())
00644 {
00645
00646
00647
00648 if( canDribbleWithBall() != 0 &&
00649 posAgent.getDistanceTo(goalMiddle) >= (PITCH_LENGTH / 7.5) )
00650 {
00651 soc = handleWithBall();
00652 ACT->putCommandInQueue( soc );
00653 ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) );
00654 }
00655
00656 else
00657 {
00658
00659
00660 if (posAgent.getDistanceTo(goalMiddle) <= (PITCH_LENGTH / 3.0))
00661 {
00662 Log.log(100, "kopem...");
00663 soc = kickToScore();
00664 }
00665
00666 else
00667 {
00668 Log.log(100, "prihravam...");
00669 double fit = 0;
00670 soc = kickToPass(&fit);
00671
00672
00673 if (fit < 5 && posAgent.getDistanceTo(goalMiddle) >= (PITCH_LENGTH / 4))
00674 soc = kickToScore();
00675 }
00676 ACT->putCommandInQueue( soc );
00677 ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) );
00678 }
00679 }
00680 else if( WM->getFastestInSetTo( OBJECT_SET_TEAMMATES, OBJECT_BALL, &iTmp )
00681 == WM->getAgentObjectType() && !WM->isDeadBallThem() )
00682 {
00683 Log.log( 100, "I am fastest to ball; can get there in %d cycles", iTmp );
00684 soc = intercept( false );
00685
00686 if( soc.commandType == CMD_DASH &&
00687 WM->getAgentStamina().getStamina() <
00688 SS->getRecoverDecThr()*SS->getStaminaMax()+200 )
00689 {
00690 soc.dPower = 30.0 * WM->getAgentStamina().getRecovery();
00691
00692
00693 }
00694 else
00695 {
00696
00697
00698 }
00699
00700
00701
00702 ACT->putCommandInQueue( soc );
00703 oscillateView(soc);
00704
00705 }
00706 else if( posAgent.getDistanceTo(WM->getStrategicPosition()) >
00707 1.5 + fabs(posAgent.getX()-posBall.getX())/10.0)
00708
00709 {
00710 if( WM->getAgentStamina().getStamina() >
00711 SS->getRecoverDecThr()*SS->getStaminaMax()+800 )
00712 {
00713 soc = moveToPos(WM->getStrategicPosition(),
00714 PS->getPlayerWhenToTurnAngle());
00715 ACT->putCommandInQueue( soc );
00716
00717 oscillateView(soc);
00718 }
00719 else
00720 {
00721 ACT->putCommandInQueue( soc = turnBodyToObject( OBJECT_BALL ) );
00722
00723 oscillateView(soc);
00724 }
00725 }
00726 else if( fabs( WM->getRelativeAngle( OBJECT_BALL ) ) > 1.0 )
00727 {
00728 ACT->putCommandInQueue( soc = turnBodyToObject( OBJECT_BALL ) );
00729 ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) );
00730 }
00731 else
00732 ACT->putCommandInQueue( SoccerCommand(CMD_TURNNECK,0.0) );
00733 }
00734 return soc;
00735 }
00736
00743 SoccerCommand Player::deMeer5_goalie( )
00744 {
00745 int i;
00746 SoccerCommand soc;
00747 VecPosition posAgent = WM->getAgentGlobalPosition();
00748 AngDeg angBody = WM->getAgentGlobalBodyAngle();
00749
00750
00751 static const VecPosition posLeftTop( -PITCH_LENGTH/2.0 +
00752 0.7*PENALTY_AREA_LENGTH, -PENALTY_AREA_WIDTH/4.0 );
00753 static const VecPosition posRightTop( -PITCH_LENGTH/2.0 +
00754 0.7*PENALTY_AREA_LENGTH, +PENALTY_AREA_WIDTH/4.0 );
00755
00756
00757 static Line lineFront = Line::makeLineFromTwoPoints(posLeftTop,posRightTop);
00758 static Line lineLeft = Line::makeLineFromTwoPoints(
00759 VecPosition( -50.0, posLeftTop.getY()), posLeftTop );
00760 static Line lineRight = Line::makeLineFromTwoPoints(
00761 VecPosition( -50.0, posRightTop.getY()),posRightTop );
00762
00763
00764 double distance = posAgent.getDistanceTo( WM->getBallPos() );
00765
00766
00767 SoccerCommand sc = adjustView( distance , 20, 50);
00768 if(sc.commandType != CMD_ILLEGAL) {
00769 ACT->putCommandInQueue(sc);
00770 }
00771
00772 if( WM->isBeforeKickOff( ) )
00773 {
00774 if( formations->getFormation() != FT_INITIAL ||
00775 posAgent.getDistanceTo( WM->getStrategicPosition() ) > 2.0 )
00776 {
00777 formations->setFormation( FT_INITIAL );
00778 ACT->putCommandInQueue( soc=teleportToPos(WM->getStrategicPosition()) );
00779 }
00780 else
00781 {
00782 ACT->putCommandInQueue( soc = turnBodyToPoint( VecPosition( 0, 0 ), 0 ));
00783 ACT->putCommandInQueue( alignNeckWithBody( ) );
00784 }
00785 return soc;
00786 }
00787
00788 if( WM->getConfidence( OBJECT_BALL ) < PS->getBallConfThr() )
00789 {
00790 ACT->putCommandInQueue( searchBall() );
00791 ACT->putCommandInQueue( alignNeckWithBody( ) );
00792 }
00793 else if( WM->getPlayMode() == PM_PLAY_ON || WM->isFreeKickThem() ||
00794 WM->isCornerKickThem() )
00795 {
00796 if( WM->isBallCatchable() )
00797 {
00798 ACT->putCommandInQueue( soc = catchBall() );
00799 ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) );
00800 }
00801 else if( WM->isBallKickable() )
00802 {
00803
00804 soc = kickToPass( );
00805 ACT->putCommandInQueue( soc );
00806 ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) );
00807 }
00808 else if( WM->isInOwnPenaltyArea( getInterceptionPointBall( &i, true ) ) &&
00809 WM->getFastestInSetTo( OBJECT_SET_PLAYERS, OBJECT_BALL, &i ) ==
00810 WM->getAgentObjectType() )
00811 {
00812 ACT->putCommandInQueue( soc = intercept( true ) );
00813 ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) );
00814 }
00815 else
00816 {
00817
00818
00819
00820 if(
00821 ((WM->getAgentGlobalPosition() - WM->getGlobalPosition( OBJECT_BALL )).getMagnitude() < 8 )
00822
00823 )
00824 {
00825 int cyc;
00826 ObjectT oponent = WM->getFastestInSetTo( OBJECT_SET_OPPONENTS, OBJECT_BALL, &cyc);
00827
00828 if((oponent != OBJECT_ILLEGAL) && (cyc <= 1))
00829 {
00830 ACT->putCommandInQueue( dashToPoint( WM->getGlobalPosition( oponent ), 1 ));
00831 }
00832 }
00833 else {
00834
00835
00836
00837
00838
00839
00840
00841
00842
00843
00844
00845
00846
00847
00848
00849
00850
00851 VecPosition posMyGoal = ( WM->getSide() == SIDE_LEFT )
00852 ? SoccerTypes::getGlobalPositionFlag(OBJECT_GOAL_L, SIDE_LEFT )
00853 : SoccerTypes::getGlobalPositionFlag(OBJECT_GOAL_R, SIDE_RIGHT);
00854 Line lineBall = Line::makeLineFromTwoPoints( WM->getBallPos(),posMyGoal);
00855
00856
00857 VecPosition posIntersect = lineFront.getIntersection( lineBall );
00858
00859
00860 if (posIntersect.isRightOf( posRightTop ) )
00861 posIntersect = lineRight.getIntersection( lineBall );
00862 else if (posIntersect.isLeftOf( posLeftTop ) )
00863 posIntersect = lineLeft.getIntersection( lineBall );
00864
00865 if( posIntersect.getX() < -49.0 )
00866 posIntersect.setX( -49.0 );
00867
00868
00869 if( posIntersect.getDistanceTo( WM->getAgentGlobalPosition() ) > 0.5 )
00870 {
00871 soc = moveToPos( posIntersect, PS->getPlayerWhenToTurnAngle() );
00872 ACT->putCommandInQueue( soc );
00873 ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) );
00874 }
00875 else
00876 {
00877 ACT->putCommandInQueue( soc = turnBodyToObject( OBJECT_BALL ) );
00878 ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) );
00879 }
00880 }
00881 }
00882 }
00883 else if( WM->isFreeKickUs() == true || WM->isGoalKickUs() == true )
00884 {
00885 if( WM->isBallKickable() )
00886 {
00887 if( WM->getTimeSinceLastCatch() == 25 && WM->isFreeKickUs() )
00888 {
00889
00890 if( WM->getNrInSetInCircle( OBJECT_SET_OPPONENTS,
00891 Circle(posRightTop, 15.0 )) <
00892 WM->getNrInSetInCircle( OBJECT_SET_OPPONENTS,
00893 Circle(posLeftTop, 15.0 )) )
00894 soc.makeCommand( CMD_MOVE,posRightTop.getX(),posRightTop.getY(),0.0);
00895 else
00896 soc.makeCommand( CMD_MOVE,posLeftTop.getX(), posLeftTop.getY(), 0.0);
00897 ACT->putCommandInQueue( soc );
00898 }
00899 else if( WM->getTimeSinceLastCatch() > 28 )
00900 {
00901
00902 soc = kickToPass( );
00903 ACT->putCommandInQueue( soc );
00904 }
00905 else if( WM->getTimeSinceLastCatch() < 25 )
00906 {
00907 VecPosition posSide( 0.0, posAgent.getY() );
00908 if( fabs( (posSide - posAgent).getDirection() - angBody) > 10 )
00909 {
00910 soc = turnBodyToPoint( posSide );
00911 ACT->putCommandInQueue( soc );
00912 }
00913 ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) );
00914 }
00915 }
00916 else if( WM->isGoalKickUs() )
00917 {
00918 ACT->putCommandInQueue( soc = intercept( true ) );
00919 ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) );
00920 }
00921 else
00922 ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) );
00923 }
00924 else
00925 {
00926 ACT->putCommandInQueue( soc = turnBodyToObject( OBJECT_BALL ) );
00927 ACT->putCommandInQueue( turnNeckToObject( OBJECT_BALL, soc ) );
00928 }
00929 return soc;
00930 }