📄 worldmodel.cpp
字号:
{ float xDistance = 0; float yDistance = 0; if (point.x < -52.5) xDistance = -point.x - 52.5; else if (point.x > 52.5) xDistance = +point.x - 52.5; if (point.y < -34) yDistance = -point.y - 34; else if (point.y > 34) yDistance = +point.y - 34; return hypot(xDistance, yDistance);}bool WorldModel::isOppBallShooted(const Ball &theBall) const{ Point interceptGoalLine, interceptGoal; if (theBall.getVel().getX() == 0) return 0; float delatX = -52.5 - theBall.getPos().getX(); float delatY = (theBall.getVel().getY() * delatX) / theBall.getVel().getX(); float delatX2 = -52.5 - theBall.getPos().getX(); float delatY2 = (theBall.getVel().getY() * delatX) / theBall.getVel().getX(); interceptGoalLine.x = theBall.getPos().getX() + delatX; interceptGoalLine.y = theBall.getPos().getY() + delatY; interceptGoal.x = theBall.getPos().getX() + delatX2; interceptGoal.y = theBall.getPos().getY() + delatY2; if (fabs(interceptGoal.y) > 8.5) return 0; Ball simBall; simBall = theBall; while (simBall.getVel().getMagnitude() > .4) simBall.simulateByDynamics(getBody());/////////////////////// float standardX = GoalieXHome; // This part must retype (GoalieXHome ?)!!! float standardX = -51; if (theBall.getPos().getX() < standardX) standardX = -52.5; if (simBall.getPos().getX() < standardX) return true; return false;}bool WorldModel::isOppBallShootedToTir(const Ball &theBall, float upYTirPoint, float downYTirPoint, Point &shootIntercept) const{ Point interceptGoalLine, interceptGoal; if (theBall.getVel().getX() == 0) return 0; float deltaX = -52.5 - theBall.getPos().getX(); float deltaY = (theBall.getVel().getY() * deltaX) / theBall.getVel().getX(); float deltaX2 = -52.5 - theBall.getPos().getX(); float deltaY2 = (theBall.getVel().getY() * deltaX) / theBall.getVel().getX(); interceptGoalLine.x = theBall.getPos().getX() + deltaX; interceptGoalLine.y = theBall.getPos().getY() + deltaY; interceptGoal.x = theBall.getPos().getX() + deltaX2; interceptGoal.y = theBall.getPos().getY() + deltaY2; if (interceptGoal.y < (downYTirPoint - 1) || interceptGoal.y > (upYTirPoint + 1)) return 0; Ball simBall; simBall = theBall; while(simBall.getVel().getMagnitude() > .4) simBall.simulateByDynamics(getBody()); float standardX = -51.5; if (theBall.getPos().getX() < standardX) standardX = -52.5; if (simBall.getPos().getX() < standardX) { shootIntercept = interceptGoal; return 1; } return 0;}float WorldModel::getTmmDefenseLine() const{ float min = 0xFFFF; for (unsigned i = 1; i <= 5; i++) if (fullPlayers[TID_TEAMMATE][i - 1]->isValid()) min = fmin(min, fullPlayers[TID_TEAMMATE][i - 1]->getPos().getX()); if (fullPlayers[TID_TEAMMATE][8 - 1]->isValid()) min = fmin(min, fullPlayers[TID_TEAMMATE][8 - 1]->getPos().getX()); if (min == 0xFFFF) return -52.5; return min;}const Player &WorldModel::getNearestTmmToPoint(const Point & point) const{ register int i; int nearestPlayer = -1; for (i = 0; i < FULL_PLAYERS_NUM; i++) if (getFullPlayer(TID_TEAMMATE, i).isValid()) { if (nearestPlayer == -1) nearestPlayer = i; else if (point.getDistance(getFullPlayer(TID_TEAMMATE, i).getPos().asPoint()) < point.getDistance(getFullPlayer(TID_TEAMMATE, nearestPlayer).getPos().asPoint())) nearestPlayer = i; } if (nearestPlayer == -1) return getBody(); else return getFullPlayer(TID_TEAMMATE, nearestPlayer);}const Player* WorldModel::getNearestTmmToPointFromList(const Point & point, std::string players, std::string blackPlayers) const{ register int i; int nearestPlayer = -1; for (i = 0; i < FULL_PLAYERS_NUM; i++) if (getFullPlayer(TID_TEAMMATE, i).isValid() && isInPlayers(getFullPlayer(TID_TEAMMATE, i).getUniNum(), players.c_str()) && !isInPlayers(getFullPlayer(TID_TEAMMATE, i).getUniNum(), blackPlayers.c_str())) { if (nearestPlayer == -1) nearestPlayer = i; else if (point.getDistance(getFullPlayer(TID_TEAMMATE, i).getPos().asPoint()) < point.getDistance(getFullPlayer(TID_TEAMMATE, nearestPlayer).getPos().asPoint())) nearestPlayer = i; } if (nearestPlayer == -1) return NULL; else return fullPlayers[TID_TEAMMATE][nearestPlayer];}const Player &WorldModel::getNearestTmmToBall() const{ return getNearestTmmToPoint(getBall().getPos().asPoint());}const Player *WorldModel::getNearestOppToBall() const{ register int i; int nearestPlayer = -1; for (i = 0; i < FULL_PLAYERS_NUM; i++) if (getFullPlayer(TID_OPPONENT, i).isValid()) { if (nearestPlayer == -1) nearestPlayer = i; else if (getFullPlayer(TID_OPPONENT, i).getDistance(getBall()) < getFullPlayer(TID_OPPONENT, nearestPlayer).getDistance(getBall())) nearestPlayer = i; } if (nearestPlayer == -1) return NULL; else return &getFullPlayer(TID_TEAMMATE, nearestPlayer);}bool WorldModel::isPlayerInOurField(const Player &player){ if (player.getPos().getX() <= 0) return true; return false;}bool WorldModel::isPlayerInOppField(const Player &player){ if (player.getPos().getX() > 0) return true; return false;}bool WorldModel::isPlayerInOurShootArea(const Player &player){ if (player.getPos().getX() < -20 && player.getPos().getY() < 25 && player.getPos().getY() > -25 ) return true; return false;}bool WorldModel::isPlayerInOppShootArea(const Player &player){ if (player.getPos().getX() > 30 && player.getPos().getY() < 25 && player.getPos().getY() > -25 ) return true; return false;}float WorldModel::getOppOffsideLine(bool isBallFlag) const{ float offsideLine; unsigned i; bool isGoalieInList = false; for (int i = 0; i < FULL_PLAYERS_NUM; i++) if (getFullPlayer(TID_OPPONENT,i).isValid() && getFullPlayer(TID_OPPONENT,i).isGoalie()) isGoalieInList = true; for (int i = 0; i < HALF_PLAYERS_NUM; i++) if (getHalfPlayer(TID_OPPONENT,i).isValid() && getHalfPlayer(TID_OPPONENT,i).isGoalie()) isGoalieInList = true; if (isGoalieInList) { offsideLine = -0xFFFF; for (i = 0; i < FULL_PLAYERS_NUM; i++) if (getFullPlayer(TID_OPPONENT,i).isValid() && getFullPlayer(TID_OPPONENT,i).getPos().getX() > offsideLine && !getFullPlayer(TID_OPPONENT,i).isGoalie()) offsideLine = getFullPlayer(TID_OPPONENT,i).getPos().getX(); for (i = 0; i < HALF_PLAYERS_NUM; i++) if (getHalfPlayer(TID_OPPONENT,i).isValid() && getHalfPlayer(TID_OPPONENT,i).getPos().getX() > offsideLine && !getHalfPlayer(TID_OPPONENT,i).isGoalie()) offsideLine = getHalfPlayer(TID_OPPONENT,i).getPos().getX(); } else { float firstMaxX = -0xFFFF, secMaxX = -0xFFFF; for (i = 0; i < FULL_PLAYERS_NUM; i++) if (getFullPlayer(TID_OPPONENT,i).isValid() && getFullPlayer(TID_OPPONENT,i).getPos().getX() > secMaxX) { secMaxX = getFullPlayer(TID_OPPONENT,i).getPos().getX(); if (secMaxX > firstMaxX) swap(firstMaxX, secMaxX); } for (i = 0; i < HALF_PLAYERS_NUM; i++) if (getHalfPlayer(TID_OPPONENT,i).isValid() && getHalfPlayer(TID_OPPONENT,i).getPos().getX() > secMaxX) { secMaxX = getHalfPlayer(TID_OPPONENT,i).getPos().getX(); if (secMaxX > firstMaxX) swap(firstMaxX, secMaxX); } offsideLine = secMaxX; } if (isBallFlag) if (offsideLine < getBall().getPos().getX()) offsideLine = getBall().getPos().getX(); if (offsideLine < 0) offsideLine = 0; return offsideLine;}float WorldModel::getOppLocalOffLine() const{ // BE EXTREMELY CAREFULL. // This function DO NOT pay attention to the goalie and do not pay // attention to ball X and nehative offside lines (!) in calculating // local offside line. // NOT TO USE FOR POSITIONING. // It is specialized for breaking offside line. // This maybe return -0xFFFF.// bool isGoalieInList = false; /* for (int i = 0; i < FULL_PLAYERS_NUM; i++) if (getFullPlayer(TID_OPPONENT,i).isValid() && getFullPlayer(TID_OPPONENT,i).isGoalie()) isGoalieInList = true; for (int i = 0; i < HALF_PLAYERS_NUM; i++) if (getHalfPlayer(TID_OPPONENT,i).isValid() && getHalfPlayer(TID_OPPONENT,i).isGoalie()) isGoalieInList = true;*/// if (isGoalieInList)// { float offsideLine = -0xFFFF; for (int i = 0; i < FULL_PLAYERS_NUM; i++) if (getFullPlayer(TID_OPPONENT,i).isValid() && getFullPlayer(TID_OPPONENT,i).getPos().getX() > offsideLine && !getFullPlayer(TID_OPPONENT,i).isGoalie() && (fabs(getFullPlayer(TID_OPPONENT,i).getPos().getY() - getBall().getPos().getY()) < OPP_OFFLINE_LOCAL_Y && fabs(getFullPlayer(TID_OPPONENT,i).getPos().getX() - getBall().getPos().getX()) < OPP_OFFLINE_LOCAL_X)) offsideLine = getFullPlayer(TID_OPPONENT,i).getPos().getX(); for (int i = 0; i < HALF_PLAYERS_NUM; i++) if (getHalfPlayer(TID_OPPONENT,i).isValid() && getHalfPlayer(TID_OPPONENT,i).getPos().getX() > offsideLine && !getHalfPlayer(TID_OPPONENT,i).isGoalie() && (fabs(getHalfPlayer(TID_OPPONENT,i).getPos().getY() - getBall().getPos().getY()) < OPP_OFFLINE_LOCAL_Y && fabs(getHalfPlayer(TID_OPPONENT,i).getPos().getX() - getBall().getPos().getX()) < OPP_OFFLINE_LOCAL_X)) offsideLine = getHalfPlayer(TID_OPPONENT,i).getPos().getX();/* } else { float firstMaxX = -0xFFFF, secMaxX = -0xFFFF; for (i = 0; i < FULL_PLAYERS_NUM; i++) if (getFullPlayer(TID_OPPONENT,i).isValid() && getFullPlayer(TID_OPPONENT,i).getPos().getX() > secMaxX) { secMaxX = getFullPlayer(TID_OPPONENT,i).getPos().getX(); if (secMaxX > firstMaxX) swap(firstMaxX, secMaxX); } for (i = 0; i < HALF_PLAYERS_NUM; i++) if (getHalfPlayer(TID_OPPONENT,i).isValid() && getHalfPlayer(TID_OPPONENT,i).getPos().getX() > secMaxX) { secMaxX = getHalfPlayer(TID_OPPONENT,i).getPos().getX(); if (secMaxX > firstMaxX) swap(firstMaxX, secMaxX); } offsideLine = secMaxX; } if (isBallFlag) if (offsideLine < getBall().getPos().getX()) offsideLine = getBall().getPos().getX(); if (offsideLine < 0) offsideLine = 0;*/ return offsideLine;}float WorldModel::getTmmOffsideLine(bool isBallFlag) const{ float offsideLine; unsigned i; bool isGoalieInList = false; for (int i = 0; i < FULL_PLAYERS_NUM; i++) if (getFullPlayer(TID_TEAMMATE,i).isValid() && getFullPlayer(TID_TEAMMATE,i).isGoalie()) isGoalieInList = true; for (int i = 0; i < HALF_PLAYERS_NUM; i++) if (getHalfPlayer(TID_TEAMMATE,i).isValid() && getHalfPlayer(TID_TEAMMATE,i).isGoalie()) isGoalieInList = true; if (isGoalieInList) { offsideLine = 0xFFFF; for (i = 0; i < FULL_PLAYERS_NUM; i++) if (getFullPlayer(TID_TEAMMATE,i).isValid() && getFullPlayer(TID_TEAMMATE,i).getPos().getX() < offsideLine && !getFullPlayer(TID_TEAMMATE,i).isGoalie()) offsideLine = getFullPlayer(TID_TEAMMATE,i).getPos().getX(); for (i = 0; i < HALF_PLAYERS_NUM; i++) if (getHalfPlayer(TID_TEAMMATE,i).isValid() && getHalfPlayer(TID_TEAMMATE,i).getPos().getX() < offsideLine && !getHalfPlayer(TID_TEAMMATE,i).isGoalie()) offsideLine = getHalfPlayer(TID_TEAMMATE,i).getPos().getX(); } else { float firstMaxX = 0xFFFF, secMaxX = 0xFFFF; for (i = 0; i < FULL_PLAYERS_NUM; i++) if (getFullPlayer(TID_TEAMMATE,i).isValid() && getFullPlayer(TID_TEAMMATE,i).getPos().getX() < secMaxX) { secMaxX = getFullPlayer(TID_TEAMMATE,i).getPos().getX(); if (secMaxX < firstMaxX) swap(firstMaxX, secMaxX); } for (i = 0; i < HALF_PLAYERS_NUM; i++) if (getHalfPlayer(TID_TEAMMATE,i).isValid() && getHalfPlayer(TID_TEAMMATE,i).getPos().getX() < secMaxX) { secMaxX = getHalfPlayer(TID_TEAMMATE,i).getPos().getX(); if (secMaxX < firstMaxX) swap(firstMaxX, secMaxX); } offsideLine = secMaxX; } if (isBallFlag) if (offsideLine > getBall().getPos().getX()) offsideLine = getBall().getPos().getX(); if (offsideLine > 0) offsideLine = 0; return offsideLine;}int WorldModel::getOppPlayersBeforeLine(float lineX) const{ int counter = 0; register int i; for (i = 0; i < FULL_PLAYERS_NUM; i++) if (getFullPlayer(TID_OPPONENT,i).isValid() && getFullPlayer(TID_OPPONENT,i).getPos().getX() <= lineX) { if (!getFullPlayer(TID_OPPONENT,i).isGoalie()) counter++; else counter += 3; } for (i = 0; i < HALF_PLAYERS_NUM; i++) if (getHalfPlayer(TID_OPPONENT,i).isValid() && getHalfPlayer(TID_OPPONENT,i).getPos().getX() <= lineX) { if (!getHalfPlayer(TID_OPPONENT,i).isGoalie()) counter++; else counter += 3; } return counter;}int WorldModel::getOppPlayersBetweenLines(float line1X, float line2X) const{ return getOppPlayersBeforeLine(line2X) - getOppPlayersBeforeLine(line1X);}const Player *WorldModel::getTmmGoalie() const{ for (unsigned i = 0; i < FULL_PLAYERS_NUM; i++) if (getFullPlayer(TID_TEAMMATE, i).isValid() && getFullPlayer(TID_TEAMMATE, i).isGoalie()) return fullPlayers[TID_TEAMMATE][i];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -