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

📄 handleball.cpp

📁 robocup源代码2001年清华机器人源代码
💻 CPP
字号:
/***********************************************************************
  This module is designed to do strategy decision when ball is kickable.
  Possible actions are collected, evaluated and enrolled here.
  Much of hand-coded evaluation is removed that we think do no help to the following researchers.
***************************************************************************/
/*
    Copyright (C) 2001  Tsinghuaeolus

    Authors : ChenJiang, YaoJinyi, CaiYunpeng, Lishi

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library 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
    Lesser General Public License for more details.

	If you make any changes or have any comments we would appreciate a 
	message to yjy01@mails.tsinghua.edu.cn.
*/
#include "handleball.h"
#include "global.h"

/*********************   Handle Ball *******************************/
bool Handleball::Tryhandle(){
	if(!Handlable())
		return false;
	DoLog(LOG_HANDLEBALL, "handleball");

	dribblable = true;
	passable = motion.SmartPass();
	shootable = motion.SmartShoot();	

	B_evaluate();			//prepare work
	return DoHandleballDecision();				//enroll actions
}

bool Handleball::Handlable(){
	if(!ball.kickable())
		handleable = false; 
	else{
		if(!handleable) startime = situation.CurrentTime;
		handleable = true;
	}
	return handleable;
} 

void Handleball::B_evaluate(){	
}

/*	inner-module competence	*/
bool Handleball::DoShootDecision(){
	return motion.GetBestShoot(logshoot);
}

bool Handleball::DoPassDecision(){
/* pass-module competition */
	float maxpriority = -1.0f, priority;
	for(int i = 0; i < motion.num_passinfo; i++){
		priority = GetPassPriority(motion.passinfo[i]);
		DoLog(LOG_HANDLEBALL, "priority %.2f", priority);
		if(priority > maxpriority){
			maxpriority = priority;
			logpass = motion.passinfo[i];
		}
	}
	return (maxpriority > 0);
}

bool Handleball::DoDribbleDecision(){
	float dribble_angle, priority;
	float maxpriority = 0.0f;
	for(int i = 0; i < CP_totaldirs; i++){
		dribble_angle = NormalizeAngle(ball.TheirGoalAngle() + (float)i * 360 / CP_totaldirs);
		if (motion.CanDribble(dribble_angle))
		{
			priority = GetDribblePriority(dribble_angle);
			if(priority > maxpriority){
				maxpriority = priority;
				logdribble = dribble_angle;
			}
		}
	}
	return maxpriority > 0.0f;
}

bool Handleball::DoHandleballDecision(){
	Command command;
/* inner-module competition */
	if(shootable)	shootable = DoShootDecision();
	if(passable)	passable = DoPassDecision();
	if(dribblable)	dribblable = DoDribbleDecision();
/* inter-module competition */
	Evaluate();

	if(shootable){
		mediator.enroll(shootcommand, Action_shoot, shoot_priority);
	}

	if(passable){
			KT_Res passok = motion.pass(logpass,command);
			mediator.enroll(command, Action_pass, pass_priority);
			mediator.PassOut.data = (passok == KT_success);
	}

	if(dribblable){
		motion.DoDribble(logdribble, dribble_priority);
	}
	if(!dribblable){
		float hold_priority = 0.1f;
		motion.holdball(command);
		mediator.enroll(command, Action_holdball, hold_priority);
	}

	PrioredCommand bestaction;
	mediator.Getbestaction(bestaction);
	if(startime == situation.CurrentTime){
		action_times = 1;
	}else{
		if(lastaction != bestaction.GetActionType())
			action_times = 1;
		else
			action_times ++;
	}
	lastaction = bestaction.GetActionType();
	if(lastaction == Action_none){
		DoLog(LOG_HANDLEBALL, "(no action) (passable %d p %.2f) (dribblable %d p%.2f) (shootable %d p %.2f)" 
			,passable, pass_priority, dribblable, dribble_priority, shootable, shoot_priority);
	}
	DoLog(LOG_HANDLEBALL, "controlball since %d, this action lasts %d",startime, action_times);

	return lastaction != Action_none;
}

void Handleball::Evaluate(){
}

float Handleball::GetShootPriority(ShootInfo& shoot){
	return 1.0f;
}

float Handleball::GetDribblePriority(AngleDeg angle){
	return 1.0f;
}

float Handleball::GetPassPriority(PassInfo& passinf){
	return 1.0f;
}

bool Handleball::WaitPassLook(){
	if(handleable && lastaction == Action_passwait)
		return true;
	else 
		return false;
}

⌨️ 快捷键说明

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