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

📄 shoottooutplan.cpp

📁 RoboCup 2D 仿真组老牌强队Mersad 2005的完整源代码
💻 CPP
字号:
/* *  Copyright 2002-2005, Mersad Team, Allameh Helli High School (NODET). * *  This program is free software, you can redistribute it and/or modify *  it under the terms of the GNU General Public License as published by *  the Free Software Foundation. * *  This program is distributed in the hope that it will be useful, *  but WITHOUT ANY WARRANTY; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *  GNU Library General Public License for more details. * *  This file is created by: Sassan Haradji * *  Released on Monday 1 August 2005, 10 Mordad 1384 by Mersad RoboCup Team. *  For more information please read README file.*/#include <ShootToOutPlan.h>#include <cmath>#include <Logger.h>#include <Basics.h>#include <HalfLine.h>#include <cassert>using namespace std;using namespace Basics;ShootToOutPlan::ShootToOutPlan(const WorldModel *wm, Form &form,		const Library &library): Plan("ShootToOut", wm, form, library),		finished(false), getVal(false),		bestKickCommand(new KickCommand(AT_SHOOT, 100, 0)){}ShootToOutPlan::~ShootToOutPlan(){}void ShootToOutPlan::decide(){	LOG << "ShootToOutPlan::decide" << endl;	if (!getVal || valSetCycle != wm->getCurCycle())		if (successRate() == 0)		{			LOG << "ShootToOutPlan decide without any shoot." << endl;			assert(0);		}	finished = true;	throw bestKickCommand;}double ShootToOutPlan::successRate(){	if (getVal && valSetCycle == wm->getCurCycle())		return value;	getVal = true;	valSetCycle = wm->getCurCycle();	if (abs(wm->getBody().getPos().getY()) < 10) return(value = 0);	if (!wm->isBallKickable()) return(value = 0);	signed side =			int(abs(wm->getBody().getPos().getY()) / wm->getBody().getPos().getY());	InterceptCalculate shootInterCalc;	shootInterCalc.startSession(1, &wm->getBody());	shootInterCalc.setTmmSlowDashPower(40);	shootInterCalc.setTmmFastDashPower(100);	shootInterCalc.setTmmDirectDashPower(63);	shootInterCalc.setTmmGoalieDirectDashPower(63);	shootInterCalc.setTmmGoalieSeeBallDelay(0);	shootInterCalc.setTmmSeeBallDelay(0);	shootInterCalc.setTmmPosDevRate(0.75);	shootInterCalc.setOppSlowDashPower(10);	shootInterCalc.setOppFastDashPower(50);	shootInterCalc.setOppDirectDashPower(20);	shootInterCalc.setOppSeeBallDelay(2);	shootInterCalc.setOppGoalieDirectDashPower(20);	shootInterCalc.setOppGoalieSeeBallDelay(2);	shootInterCalc.setOppPosDevRate(0.15);	shootInterCalc.updateByWorldModel(wm);	float maxWeight = 0;	for(unsigned i = 0; i < 15; i++)	{		bool cantShoot = false;		float velocity = 4.0;		Ball shootBall = wm->getBall();		KickToPointVelocity *shootKick;		Command *kickCommand = new KickCommand(AT_SHOOT, 100, 0);		Point targetPoint(wm->getBody().getPos().getX() + (signed(i) - 7) * 2, side * 42);		while(!cantShoot)		{			shootKick = new KickToPointVelocity(AT_DEFENSE, targetPoint,					velocity, wm->getBall(), wm->getBody());			delete kickCommand;			kickCommand = shootKick->getCommand();			if (shootKick->isPossible())				break;			else				velocity -= .1;			if (velocity < 2)				cantShoot = true;						}		if (cantShoot) continue;		shootBall.simulateByAction(wm->getBody(), kickCommand);		shootInterCalc.setVirtualBall(shootBall);		shootInterCalc.setKickCycles(1);		shootInterCalc.run();				Point ballPoint;		if (shootInterCalc.existFastestPlayer())			ballPoint = shootInterCalc.getFastestInterPlayer().getInterPoint();		else			ballPoint = shootInterCalc.getVirtualBall().getPos();		Vector ballToTargetVector;		HalfLine ballToTargetHalfLine;		ballToTargetVector.setByPoints(wm->getBall().getPos(), targetPoint);		ballToTargetHalfLine.setByPointDir(wm->getBall().getPos(),				ballToTargetVector.getDirection());		float minDistance = 300;		for (unsigned j = 0; j < FULL_PLAYERS_NUM; j++)			if (wm->getFullPlayer(TID_OPPONENT, j).isValid())				if (ballToTargetHalfLine.getPointDist(						wm->getFullPlayer(TID_OPPONENT, j).getPos()) < minDistance)					minDistance = ballToTargetHalfLine.getPointDist(							wm->getFullPlayer(TID_OPPONENT, j).getPos());		for (unsigned j = 0; j < HALF_PLAYERS_NUM; j++)			if (wm->getHalfPlayer(TID_OPPONENT, j).isValid())				if (ballToTargetHalfLine.getPointDist(						wm->getHalfPlayer(TID_OPPONENT, j).getPos()) < minDistance)					minDistance = ballToTargetHalfLine.getPointDist(							wm->getHalfPlayer(TID_OPPONENT, j).getPos());		if (abs(ballPoint.y) + minDistance / 3 > maxWeight)		{			maxWeight = abs(ballPoint.y) + minDistance / 3;			bestKickCommand =				new KickCommand(*dynamic_cast<KickCommand *>(kickCommand));		}	}	if (maxWeight >= 50) return(value = 1);	if (maxWeight >= 30) return(value = reRate(maxWeight, 30, 50, .1, 1));	if (maxWeight < 15) return 0;	return (value = .05);}bool ShootToOutPlan::isFinished(){	if (wm->isBallKickable()) 		return finished;	return true;}

⌨️ 快捷键说明

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