📄 worldmodel.cpp
字号:
for (unsigned i = 0; i < HALF_PLAYERS_NUM; i++) if (getHalfPlayer(TID_TEAMMATE, i).isValid() && getHalfPlayer(TID_TEAMMATE, i).isGoalie()) return halfPlayers[TID_TEAMMATE][i]; return NULL;}const Player *WorldModel::getOppGoalie() const{ for (unsigned i = 0; i < FULL_PLAYERS_NUM; i++) if (getFullPlayer(TID_OPPONENT, i).isValid() && getFullPlayer(TID_OPPONENT, i).isGoalie()) return fullPlayers[TID_OPPONENT][i]; for (unsigned i = 0; i < HALF_PLAYERS_NUM; i++) if (getHalfPlayer(TID_OPPONENT, i).isValid() && getHalfPlayer(TID_OPPONENT, i).isGoalie()) return halfPlayers[TID_OPPONENT][i]; return NULL;}Point WorldModel::getOppDefenseMedium() const{ Point mid(0, 0); int counter = 0; for (unsigned i = 0; i < FULL_PLAYERS_NUM; i++) if (fullPlayers[TID_OPPONENT][i]->isValid() && !fullPlayers[TID_OPPONENT][i]->isGoalie()) { mid.y += fullPlayers[TID_OPPONENT][i]->getPos().getY(); mid.x += fullPlayers[TID_OPPONENT][i]->getPos().getX(); counter++; } for (unsigned i = 0; i < HALF_PLAYERS_NUM; i++) if (halfPlayers[TID_OPPONENT][i]->isValid() && !halfPlayers[TID_OPPONENT][i]->isGoalie()) { mid.y += halfPlayers[TID_OPPONENT][i]->getPos().getY(); mid.x += halfPlayers[TID_OPPONENT][i]->getPos().getX(); counter++; } counter = (counter)?counter:1; mid.y /= counter; mid.x /= counter; return mid;}Point WorldModel::getOppDefenseYMin() const{ Point yMin(0, 100); for (unsigned i = 0; i < FULL_PLAYERS_NUM; i++) if (fullPlayers[TID_OPPONENT][i]->isValid() && !fullPlayers[TID_OPPONENT][i]->isGoalie()) if (fullPlayers[TID_OPPONENT][i]->getPos().getY() < yMin.y) { yMin.y = fullPlayers[TID_OPPONENT][i]->getPos().getY(); yMin.x = fullPlayers[TID_OPPONENT][i]->getPos().getX(); } for (unsigned i = 0; i < HALF_PLAYERS_NUM; i++) if (halfPlayers[TID_OPPONENT][i]->isValid() && !halfPlayers[TID_OPPONENT][i]->isGoalie()) if (halfPlayers[TID_OPPONENT][i]->getPos().getY() < yMin.y) { yMin.y = halfPlayers[TID_OPPONENT][i]->getPos().getY(); yMin.x = halfPlayers[TID_OPPONENT][i]->getPos().getX(); } return yMin;}Point WorldModel::getOppDefenseYMax() const{ Point yMax(0, -100); for (unsigned i = 0; i < FULL_PLAYERS_NUM; i++) if (fullPlayers[TID_OPPONENT][i]->isValid() && !fullPlayers[TID_OPPONENT][i]->isGoalie()) if (fullPlayers[TID_OPPONENT][i]->getPos().getY() > yMax.y) { yMax.y = fullPlayers[TID_OPPONENT][i]->getPos().getY(); yMax.x = fullPlayers[TID_OPPONENT][i]->getPos().getX(); } for (unsigned i = 0; i < HALF_PLAYERS_NUM; i++) if (halfPlayers[TID_OPPONENT][i]->isValid() && !halfPlayers[TID_OPPONENT][i]->isGoalie()) if (halfPlayers[TID_OPPONENT][i]->getPos().getY() > yMax.y) { yMax.y = halfPlayers[TID_OPPONENT][i]->getPos().getY(); yMax.x = halfPlayers[TID_OPPONENT][i]->getPos().getX(); } return yMax;}float WorldModel::getSecurityStatus(const Player &player, float oval_a, float oval_b) const{ float securityStatus = 100000; float tmpSecurityStatus = 0; if (!player.isValid()) return 0; for (unsigned i = 0; i < FULL_PLAYERS_NUM; i++) if (fullPlayers[TID_OPPONENT][i]->isValid()) { float oppPlayerX = fullPlayers[TID_OPPONENT][i]->getPos().getX() - player.getPos().getX(); float oppPlayerY = fullPlayers[TID_OPPONENT][i]->getPos().getY() - player.getPos().getY(); tmpSecurityStatus = abs(2 * oval_b * oppPlayerX * oppPlayerY * sqrt(abs( 1 / (oval_a * oppPlayerY) + 1 / (oval_b * oppPlayerX)))); if (abs(oppPlayerX) < .05) tmpSecurityStatus = abs(2 * (oval_b / oval_a) * oppPlayerY); if (abs(oppPlayerY) < .05) tmpSecurityStatus = abs(2 * oppPlayerX); if (tmpSecurityStatus < securityStatus) securityStatus = tmpSecurityStatus; } for (unsigned i = 0; i < HALF_PLAYERS_NUM; i++) if (halfPlayers[TID_OPPONENT][i]->isValid()) { float oppPlayerX = halfPlayers[TID_OPPONENT][i]->getPos().getX() - player.getPos().getX(); float oppPlayerY = halfPlayers[TID_OPPONENT][i]->getPos().getY() - player.getPos().getY(); tmpSecurityStatus = abs(2 * oval_b * oppPlayerX * oppPlayerY * sqrt(1 / (oval_a * oppPlayerY) + 1 / (oval_a * oppPlayerX))); if (abs(oppPlayerX) < .05) tmpSecurityStatus = abs(2 * (oval_b / oval_a) * oppPlayerY); if (abs(oppPlayerY) < .05) tmpSecurityStatus = abs(2 * oppPlayerX); if (tmpSecurityStatus < securityStatus) securityStatus = tmpSecurityStatus; } return securityStatus;}float WorldModel::getPathSecurityStatus(const Player &srcPlayer, const Point trgPoint, float forwardRate) const{ float minAngleSecurity = 100000; Vector meToTRGPoint; meToTRGPoint.setByPoints(srcPlayer.getPos(), trgPoint); float trgDirection = absoluteAngle(meToTRGPoint.getDirection()); for (unsigned i = 0; i < FULL_PLAYERS_NUM; i++) if (fullPlayers[TID_OPPONENT][i]->isValid()) { Vector meToTmpOpp; meToTmpOpp.setByPoints(srcPlayer.getPos(), fullPlayers[TID_OPPONENT][i]->getPos()); if (meToTmpOpp.getMagnitude() <= meToTRGPoint.getMagnitude() + 1) { float tmpAngle = absoluteAngle(abs(trgDirection - absoluteAngle(meToTmpOpp.getDirection()))); float tmpAngleSecurity = DEG2RAD * tmpAngle; if ((trgDirection > meToTmpOpp.getDirection() && normalizeAngle(trgDirection) >= 0) || (trgDirection < meToTmpOpp.getDirection() && normalizeAngle(trgDirection) <= 0)) tmpAngleSecurity = DEG2RAD * tmpAngle + (forwardRate - 1) * DEG2RAD * tmpAngle * (sin(DEG2RAD * tmpAngle) + 1); if (tmpAngleSecurity < minAngleSecurity) minAngleSecurity = tmpAngleSecurity; } } for (unsigned i = 0; i < HALF_PLAYERS_NUM; i++) if (halfPlayers[TID_OPPONENT][i]->isValid()) { Vector meToTmpOpp; meToTmpOpp.setByPoints(srcPlayer.getPos(), halfPlayers[TID_OPPONENT][i]->getPos()); if (meToTmpOpp.getMagnitude() >= meToTRGPoint.getMagnitude() + 4) { float tmpAngle = absoluteAngle(trgDirection - meToTmpOpp.getDirection()); float tmpAngleSecurity = DEG2RAD * tmpAngle; if ((trgDirection > meToTmpOpp.getDirection() && normalizeAngle(trgDirection) >= 0) || (trgDirection < meToTmpOpp.getDirection() && normalizeAngle(trgDirection) <= 0)) tmpAngleSecurity = DEG2RAD * tmpAngle + (forwardRate - 1) * DEG2RAD * tmpAngle * (sin(DEG2RAD * tmpAngle) + 1); if (tmpAngleSecurity < minAngleSecurity) minAngleSecurity = tmpAngleSecurity; } } return minAngleSecurity;}void WorldModel::parseHear(const SExpression &exp){ float hearDir; unsigned hearCycle; unsigned senderNum; SExpAtomic *at; SExpression *exp2; resetHearedVarsBeforeHear(); at = dynamic_cast<SExpAtomic *>(exp[1]); assert(at); hearCycle = at->asInt(); hearedPlanInfo = ""; at = dynamic_cast<SExpAtomic *>(exp[2]); assert(at); if (at->toString() == "referee") { parseRefereeHear(exp); refereeHearTime = curTime; } else if (at->toString().substr(0, 12) == "online_coach") { if ((fieldSide == SI_LEFT && at->toString().substr(13, 4) == "left") || (fieldSide == SI_RIGHT && at->toString().substr(13, 5) == "right")) { // teammate coach. exp2 = dynamic_cast<SExpression *>(exp[3]); assert(exp2); parseTeammateCoachHear(*exp2); } else { // opponent coach. } } else if (at->toString() == "self") { at = dynamic_cast<SExpAtomic *>(exp[3]); assert(at); selfHear(at->toString()); } else // a player has said that. { at = dynamic_cast<SExpAtomic *>(exp[2]); assert(at); hearDir = at->asInt(); at = dynamic_cast<SExpAtomic *>(exp[3]); assert(at); if (at->toString() == "our") { at = dynamic_cast<SExpAtomic *>(exp[4]); assert(at); senderNum = at->asInt(); at = dynamic_cast<SExpAtomic *>(exp[5]); assert(at); teammateHear(hearDir, senderNum, at->toString()); } else { assert(at->toString() == "opp"); at = dynamic_cast<SExpAtomic *>(exp[4]); assert(at); opponentHear(hearDir, at->toString()); } }}void WorldModel::parseRefereeHear(const SExpression &exp){ SExpAtomic *at; at = dynamic_cast<SExpAtomic *>(exp[3]); assert(at); playModeRemainCycle = 0; // normal PlayModes if (at->toString() == "before_kick_off") playMode = PM_BEFORE_KICK_OFF; else if (at->toString() == "play_on") { playMode = PM_PLAY_ON; virtualPlayMode = VPM_NONE; playOnStartCycle = curTime; } else if (at->toString() == "kick_off_l") { if (fieldSide == SI_LEFT) playMode = PM_KICK_OFF; else playMode = PM_KICK_OFF_OPP; playModeRemainCycle = 200; ball->updateByHear(0, 0, 0, 0, *body); } else if (at->toString() == "kick_off_r") { if (fieldSide == SI_RIGHT) playMode = PM_KICK_OFF; else playMode = PM_KICK_OFF_OPP; playModeRemainCycle = 200; ball->updateByHear(0, 0, 0, 0, *body); } else if (at->toString() == "free_kick_l") { if (fieldSide == SI_LEFT) playMode = PM_FREE_KICK; else playMode = PM_FREE_KICK_OPP; playModeRemainCycle = 200; } else if (at->toString() == "free_kick_r") { if (fieldSide == SI_RIGHT) playMode = PM_FREE_KICK; else playMode = PM_FREE_KICK_OPP; playModeRemainCycle = 200; } else if (at->toString() == "indirect_free_kick_l") { if (fieldSide == SI_LEFT) { playMode = PM_FREE_KICK; virtualPlayMode = VPM_INDIRECT_FREE_KICK; } else { playMode = PM_FREE_KICK_OPP; virtualPlayMode = VPM_INDIRECT_FREE_KICK_OPP; } playModeRemainCycle = 200; } else if (at->toString() == "indirect_free_kick_r") { if (fieldSide == SI_RIGHT) { playMode = PM_FREE_KICK; virtualPlayMode = VPM_INDIRECT_FREE_KICK; } else { playMode = PM_FREE_KICK_OPP; virtualPlayMode = VPM_INDIRECT_FREE_KICK_OPP; } playModeRemainCycle = 200; } else if (at->toString() == "kick_in_l") { if (fieldSide == SI_LEFT) playMode = PM_KICK_IN; else playMode = PM_KICK_IN_OPP; playModeRemainCycle = 200; } else if (at->toString() == "kick_in_r") { if (fieldSide == SI_RIGHT) playMode = PM_KICK_IN; else playMode = PM_KICK_IN_OPP; playModeRemainCycle = 200; } else if (at->toString() == "offside_l") { if (fieldSide == SI_LEFT) playMode = PM_OFFSIDE; else playMode = PM_OFFSIDE_OPP; playModeRemainCycle = 30; } else if (at->toString() == "offside_r") { if (fieldSide == SI_RIGHT) playMode = PM_OFFSIDE; else playMode = PM_OFFSIDE_OPP; playModeRemainCycle = 30; } else if (at->toString() == "goal_kick_l") { if (fieldSide == SI_LEFT) playMode = PM_GOAL_KICK; else playMode = PM_GOAL_KICK_OPP; virtualPlayMode = VPM_NONE; playModeRemainCycle = 200; } else if (at->toString() == "goal_kick_r") { if (fieldSide == SI_RIGHT) playMode = PM_GOAL_KICK; else playMode = PM_GOAL_KICK_OPP; virtualPlayMode = VPM_NONE; playModeRemainCycle = 200; } else if (at->toString() == "corner_kick_l") { if (fieldSide == SI_LEFT) playMode = PM_CORNER_KICK; else playMode = PM_CORNER_KICK_OPP; playModeRemainCycle = 200; } else if (at->toString() == "corner_kick_r") { if (fieldSide == SI_RIGHT) playMode = PM_CORNER_KICK; else playMode = PM_CORNER_KICK_OPP; playModeRemainCycle = 200; } else if (at->toString() == "free_kick_fault_l") { if (fieldSide == SI_LEFT) playMode = PM_FREE_KICK_FAULT; else playMode = PM_FREE_KICK_FAULT_OPP; playModeRemainCycle = 30; } else if (at->toString() == "free_kick_fault_r") { if (fieldSide == SI_RIGHT) playMode = PM_FREE_KICK_FAULT; else playMode = PM_FREE_KICK_FAULT_OPP; playModeRemainCycle = 30; } else if (at->toString() == "catch_fault_l") { if (fieldSide == SI_LEFT) playMode = PM_CATCH_FAULT; else playM
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -