⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 goalstraightposplan.cpp

📁 2006年世界杯足球赛2D仿真组第16名的源代码。在此代码上随便改改
💻 CPP
📖 第 1 页 / 共 2 页
字号:
				alpha = 0.0;				goalieDist = 0.0;		}						Point homePoint = library.positioning.getHomePoint(wm->getBody().getUniNum());		if (isInPlayers(wm->getBody().getUniNum(), "AB"))			homePoint.y *= config["GoalStraightPos"]["BasicGeometry"]["ABYFactor"].asFloat();		if (homePoint.y > 30)			homePoint.y = 30;		if (homePoint.y < -30)			homePoint.y = -30;		float realDFH = calcPoint.getDistance(homePoint);		float distFromHome = 0.0;		if (realDFH > 5.0) {			distFromHome = exp(realDFH - 5.0) /				 config["GoalStraightPos"]["Factors"]["StabilityPower"].asFloat();		}#ifdef LOG_INDIVIDUAL_POINT		LOG << " g:" << goalieDist << " alpha:" << alpha;#endif		float sigmaM = 0.0;		for (int i =0 ; i <  FULL_PLAYERS_NUM; ++i)				if (wm->getFullPlayer(TID_OPPONENT, i).isValid()) {						if (calcPoint.getDistance(wm->getFullPlayer(TID_OPPONENT, i).getPos().asPoint()) < 								config["GoalStraightPos"]["Factors"]["SemiMarkArea"].asFloat()) {								sigmaM -= 1/(calcPoint.getDistance(wm->getFullPlayer(TID_OPPONENT, i).getPos().asPoint())+1.0);						}						if (wm->getMarkers().find(wm->getFullPlayer(TID_OPPONENT, i).getUniNum())								!= wm->getMarkers().end()) {#ifdef LOG_INDIVIDUAL_POINT								LOG << "cmp.. " <<										wm->getFullPlayer(TID_OPPONENT, i).getUniNum()										<< ".. ";#endif								sigmaM -= config["GoalStraightPos"]["Factors"]["MarkedPlayersExtra"].asFloat() *										1/(calcPoint.getDistance(wm->getFullPlayer(TID_OPPONENT, i).getPos().asPoint())+1.0);						}				}		for (int i =0 ; i <  HALF_PLAYERS_NUM; ++i)				if (wm->getHalfPlayer(TID_OPPONENT, i).isValid()) {						if (calcPoint.getDistance(wm->getHalfPlayer(TID_OPPONENT, i).getPos().asPoint()) < 								config["GoalStraightPos"]["Factors"]["SemiMarkArea"].asFloat()) {								sigmaM -= 1/(calcPoint.getDistance(wm->getHalfPlayer(TID_OPPONENT, i).getPos().asPoint())+1.0);						}						if (wm->getMarkers().find(wm->getHalfPlayer(TID_OPPONENT, i).getUniNum())								!= wm->getMarkers().end()) {#ifdef LOG_INDIVIDUAL_POINT								LOG << "chmplayer.... " <<										wm->getHalfPlayer(TID_OPPONENT, i).getUniNum()										<< endl;#endif								sigmaM -= config["GoalStraightPos"]["Factors"]["MarkedPlayersExtra"].asFloat() *										1/(calcPoint.getDistance(wm->getHalfPlayer(TID_OPPONENT, i).getPos().asPoint())+1.0);						}				}#ifdef LOG_INDIVIDUAL_POINT		LOG << " sigmaM " << sigmaM << " dfHome " << distFromHome << endl;#endif		float value = 				config["GoalStraightPos"]["Factors"]["Alpha"].asFloat() *alpha  + 				config["GoalStraightPos"]["Factors"]["GoalieDist"].asFloat()*goalieDist + 				config["GoalStraightPos"]["Factors"]["SigmaM"].asFloat()*sigmaM +				config["GoalStraightPos"]["Factors"]["Stability"].asFloat() * distFromHome;		return value;					}								float GoalStraightPosPlan::calculatePath(Vector moveVector, int numPoints,										 float decay){	Body pathPlayer(wm->getBody());	Command *pathCommand;	Point targetPoint;	float weight, decayMultiplier;	int i;	weight = 0;	float value;	float oppOffsideX;	decayMultiplier = 1;	oppOffsideX = wm->getOppOffsideLine(true);		for (i = 0; i < numPoints; i++) {						targetPoint= pathPlayer.getPos() + moveVector;						if ( (abs(targetPoint.x) > 52.5) || (abs(targetPoint.y) > 34)) {					LOG << "skipping out.." << endl;					continue;			}			LOG << "s1.7:" << i << endl;			if (targetPoint.x > oppOffsideX) {					LOG << "offside... giving minus weight" << endl;					weight += config["GoalStraightPos"]["Factors"]["OffsideWeight"].asFloat()									* decayMultiplier;			}						pathCommand = PreciseGotoPoint(AT_NONE,targetPoint, 0.5, pathPlayer, true, 5).getCommand();			pathPlayer.simulateByAction(pathCommand);			pathPlayer.simulateByDynamics();			oppOffsideX += 0.5; // <--== BARRASI			delete pathCommand;			value = getValueForPoint(pathPlayer.getPos()); 			LOG << "GoalStraightPosPlan:CP mv=" << moveVector <<					" point=" << pathPlayer.getPos() << " value=" << value << endl;			weight += value * decayMultiplier;			decayMultiplier *= decay;	}	LOG << "GoalStraightPosPlan:W " << weight << endl;	return weight;}VectorGoalStraightPosPlan::getBestVectorInFreeArea() {	int pathPoints = config["GoalStraightPos"]["BasicGeometry"]["PathPoints"].asInt();	float pathDecay = config["GoalStraightPos"]["BasicGeometry"]["PathDecay"].asFloat();    LOG << "calculating required and sufficient parameters...." << endl;		Point bestPoint;		vector <Vector> directionVector;		Vector tempVector;		if (isAngleOK(wm->getBody().getBodyDir())) {			tempVector.setAsPolar(2, wm->getBody().getBodyDir()); // go forward			directionVector.push_back(tempVector);			}		if (isAngleOK(wm->getBody().getBodyDir() + 180)) {			tempVector.setAsPolar(2, wm->getBody().getBodyDir() + 180); // go backward			directionVector.push_back(tempVector);			}		if (isAngleOK(wm->getBody().getBodyDir()) + 30) {			tempVector.setAsPolar(2, wm->getBody().getBodyDir() + 30); // go +30			directionVector.push_back(tempVector);			}		if (isAngleOK(wm->getBody().getBodyDir()) + 30 + 180) {			tempVector.setAsPolar(2, wm->getBody().getBodyDir() + 30 + 180); // go +30			directionVector.push_back(tempVector);			}		if (isAngleOK(wm->getBody().getBodyDir()) - 30) {			tempVector.setAsPolar(2, wm->getBody().getBodyDir() - 30); // go -30			directionVector.push_back(tempVector);			}		if (isAngleOK(wm->getBody().getBodyDir()) - 30 + 180) {			tempVector.setAsPolar(2, wm->getBody().getBodyDir() - 30 + 180); // go -30 backward			directionVector.push_back(tempVector);			}		tempVector.setAsCartesian(0, 0); // wait here		directionVector.push_back(tempVector);					float maxWeight = -10000.0;		int maxer = 0;		// checking moving paths...		for (unsigned i =0 ; i < directionVector.size(); ++i) {				float newWeight = calculatePath(directionVector[i], pathPoints, pathDecay);				LOG << "GoalStraightPosPlan:direction[" << i << "].angle=" << directionVector[i].getDirection()					 << " weight=" << 						newWeight << endl;				if (newWeight >= maxWeight) {						maxWeight = newWeight;						maxer = i;				}		}		LOG << "Best Value: " << maxWeight << endl;		LOG << "I say: " << directionVector[maxer] << " [" << maxer << "]" << " angle:" <<			 directionVector[maxer].getDirection() << endl;		return directionVector[maxer];}doubleGoalStraightPosPlan::successRate(){    return 1.0;}boolGoalStraightPosPlan ::isFinished(){    if (!isInPlayers(wm->getBody().getUniNum(), "234"))        return true;	if (wm->getBallStatus() == BS_KICKABLE_OPP ||		wm->getBallStatus() == BS_FREE_BALL ||		wm->getBallStatus() == BS_FREE_BALL_OPP)		return true;    if (!wm->isBallKickable() &&        library.gwSelection == WOBS_OFFENSE)        return false;    return true;}boolGoalStraightPosPlan::isInPenaltyArea(const Point & p) const{    return ((abs(p.y) <= 20) && (p.x >= 36.2));}floatGoalStraightPosPlan::getProperAngle(float angle1, float angle2) const{		return abs(normalizeAngle(angle1-angle2));}voidGoalStraightPosPlan::turnToGoal(){	TurnToAngle a(AT_OFFENSE, 0, wm->getBody());	throw a.getCommand();}boolGoalStraightPosPlan::isAngleOK(float angle) const {	angle = getProperAngle(angle, 0);	if (angle > PATH_ABS_ANGLE && angle < (180 - PATH_ABS_ANGLE))		return false;	else		return true;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -