C++ "multiple definition of .. first defined here 錯誤的修改
今天將Helios有關程式碼摳到我們的底層時,發現不少地方出現 "multiple definition of .. first defined here 錯誤。這個檔案的.h和.cpp檔案在下面。以及修改方法:
============================h檔案===============================
#ifndef HELIOS_BHV_DANGER_AREA_TACKLE_H
#define HELIOS_BHV_DANGER_AREA_TACKLE_H
#include <rcsc/player/soccer_action.h>
class Bhv_DangerAreaTackle
: public rcsc::SoccerBehavior {
private:
const double M_min_probability;
public:
Bhv_DangerAreaTackle( const double & min_prob = 0.85 )
: M_min_probability( min_prob )
{ }
bool execute( rcsc::PlayerAgent * agent );
private:
bool clearGoal( rcsc::PlayerAgent * agent ); //修改為bool clearGoal(
rcsc::PlayerAgent * agent )const;
bool executeOld( rcsc::PlayerAgent * agent ); //修改為bool executeOld(
rcsc::PlayerAgent * agent )const;
bool executeV12( rcsc::PlayerAgent * agent ); //修改為 bool
executeV12( rcsc::PlayerAgent * agent )const;
};
#endif
============================cpp檔案===============================
#include "bhv_danger_area_tackle.h"
#include <rcsc/action/neck_turn_to_ball_or_scan.h>
#include <rcsc/player/player_agent.h>
#include <rcsc/player/intercept_table.h>
#include <rcsc/player/debug_client.h>
#include <rcsc/common/logger.h>
#include <rcsc/common/server_param.h>
#include <rcsc/geom/line_2d.h>
#include <rcsc/geom/ray_2d.h>
/*-------------------------------------------------------------------*/
/*!
*/
bool
Bhv_DangerAreaTackle::execute( rcsc::PlayerAgent * agent )
{
// static rcsc::GameTime s_last_execute_time( 0, 0 );
rcsc::dlog.addText( rcsc::Logger::TEAM,
__FILE__": Bhv_DangerAreaTackle" );
const rcsc::WorldModel & wm = agent->world();
// if ( s_last_execute_time == wm.time() )
// {
// rcsc::dlog.addText( rcsc::Logger::TEAM,
// __FILE__": called several times" );
// return false;
// }
// s_last_execute_time = wm.time();
if ( clearGoal( agent ) )
{
return true;
}
if ( wm.self().tackleProbability() < M_min_probability )
{
rcsc::dlog.addText( rcsc::Logger::TEAM,
__FILE__": failed. low tackle_prob=%.2f < %.2f",
wm.self().tackleProbability(),
M_min_probability );
return false;
}
const int self_min = wm.interceptTable()->selfReachCycle();
const int mate_min = wm.interceptTable()->teammateReachCycle();
const int opp_min = wm.interceptTable()->opponentReachCycle();
bool ball_shall_be_in_our_goal = false;
//
// check where the ball shall be gone without tackle
//
#if 0
ball_shall_be_in_our_goal = false;
rcsc::dlog.addText( rcsc::Logger::TEAM,
__FILE__": ball_shall_be_in_our_goal unchecked" );
#else
const double goal_half_width = rcsc::ServerParam::i().goalHalfWidth();
const rcsc::Vector2D goal_center = rcsc::ServerParam::i().ourTeamGoalPos();
const rcsc::Vector2D goal_left_post( goal_center.x, +goal_half_width );
const rcsc::Vector2D goal_right_post( goal_center.x, -goal_half_width );
bool is_shoot_ball = ( ( (goal_left_post - wm.ball().pos() ).th()
- wm.ball().vel().th() ).degree() < 0
&& ( ( goal_right_post - wm.ball().pos() ).th()
- wm.ball().vel().th() ).degree() > 0 );
const int self_reach_cycle = wm.interceptTable()->selfReachCycle();
if ( is_shoot_ball
&& wm.ball().inertiaPoint( self_reach_cycle ).x
<= rcsc::ServerParam::i().ourTeamGoalLineX() )
{
ball_shall_be_in_our_goal = true;
}
rcsc::dlog.addText( rcsc::Logger::TEAM,
__FILE__": ball_shall_be_in_our_goal = %s",
( ball_shall_be_in_our_goal ? "true" : "false" ) );
#endif
if ( wm.existKickableOpponent()
|| ball_shall_be_in_our_goal
|| ( opp_min < self_min
&& opp_min < mate_min ) )
{
}
else
{
rcsc::dlog.addText( rcsc::Logger::TEAM,
__FILE__": failed. not necessary." );
return false;
}
//
// v11 or older
//
if ( agent->config().version() < 12.0 )
{
return executeOld( agent );
}
else
{
return executeV12( agent );
}
return false;
}
/*-------------------------------------------------------------------*/
/*!
*/
bool
Bhv_DangerAreaTackle::clearGoal( rcsc::PlayerAgent * agent ) //加上const
{
const rcsc::WorldModel & wm = agent->world();
if ( wm.self().tackleProbability() <= 0.0 )
{
return false;
}
const rcsc::ServerParam & param = rcsc::ServerParam::i();
const int self_min = wm.interceptTable()->selfReachCycle();
const rcsc::Vector2D self_trap_pos = wm.ball().inertiaPoint( self_min );
if ( self_trap_pos.x > - param.pitchHalfLength() + 0.5 )
{
return false;
}
//
// cannot intercept the ball in the field
//
rcsc::dlog.addText( rcsc::Logger::TEAM,
__FILE__": my trap pos(%.1f %.1f) < pitch.x",
self_trap_pos.x, self_trap_pos.y );
const rcsc::Ray2D ball_ray( wm.ball().pos(), wm.ball().vel().th() );
const rcsc::Line2D goal_line( rcsc::Vector2D( - param.pitchHalfLength(), 10.0 ),
rcsc::Vector2D( - param.pitchHalfLength(), -10.0 ) );
const rcsc::Vector2D intersect = ball_ray.intersection( goal_line );
if ( ! intersect.valid()
|| intersect.absY() > param.goalHalfWidth() + 0.5 )
{
return false;
}
//
// ball is moving to our goal
//
rcsc::dlog.addText( rcsc::Logger::TEAM,
__FILE__": ball is moving to our goal" );
if ( agent->config().version() < 12.0 )
{
double tackle_power = ( wm.self().body().abs() > 90.0
? param.maxTacklePower()
: - param.maxBackTacklePower() );
rcsc::dlog.addText( rcsc::Logger::TEAM,
__FILE__": clear goal" );
agent->debugClient().addMessage( "tackleClearOld%.0f", tackle_power );
agent->doTackle( tackle_power );
agent->setNeckAction( new rcsc::Neck_TurnToBallOrScan() );
return true;
}
//
// search best angle
//
const rcsc::Line2D line_c( rcsc::Vector2D( -param.pitchHalfLength(), 0.0 ),
rcsc::Vector2D( 0.0, 0.0 ) );
const rcsc::Line2D line_l( rcsc::Vector2D( -param.pitchHalfLength(), -param.goalHalfWidth() ),
rcsc::Vector2D( 0.0, -param.goalHalfWidth() ) );
const rcsc::Line2D line_r( rcsc::Vector2D( -param.pitchHalfLength(), -param.goalHalfWidth() ),
rcsc::Vector2D( 0.0, -param.goalHalfWidth() ) );
const rcsc::AngleDeg ball_rel_angle
= wm.ball().angleFromSelf() - wm.self().body();
const double tackle_rate
= ( param.tacklePowerRate()
* ( 1.0 - 0.5 * ( ball_rel_angle.abs() / 180.0 ) ) );
rcsc::AngleDeg best_angle = 0.0;
double max_speed = -1.0;
for ( double a = -180.0; a < 180.0; a += 10.0 )
{
rcsc::AngleDeg target_rel_angle = a - wm.self().body().degree();
double eff_power = param.maxBackTacklePower()
+ ( ( param.maxTacklePower() - param.maxBackTacklePower() )
* ( 1.0 - target_rel_angle.abs() / 180.0 ) );
eff_power *= tackle_rate;
rcsc::Vector2D vel = wm.ball().vel()
+ rcsc::Vector2D::polar2vector( eff_power, rcsc::AngleDeg( a ) );
rcsc::AngleDeg vel_angle = vel.th();
if ( vel_angle.abs() > 80.0 )
{
rcsc::dlog.addText( rcsc::Logger::TEAM,
__FILE__": clearGoal() angle=%.1f. vel_angle=%.1f is dangerouns",
a,
vel_angle.degree() );
continue;
}
double speed = vel.r();
int n_intersects = 0;
if ( ball_ray.intersection( line_c ).valid() ) ++n_intersects;
if ( ball_ray.intersection( line_l ).valid() ) ++n_intersects;
if ( ball_ray.intersection( line_r ).valid() ) ++n_intersects;
if ( n_intersects == 3 )
{
rcsc::dlog.addText( rcsc::Logger::TEAM,
"__ angle=%.1f vel=(%.1f %.1f)"
" 3 intersects with v_lines. angle is dangerous.",
a, vel.x, vel.y );
speed -= 2.0;
}
else if ( n_intersects == 2
&& wm.ball().pos().absY() > 3.0 )
{
rcsc::dlog.addText( rcsc::Logger::TEAM,
"__ executeV12() angle=%.1f vel=(%.1f %.1f)"
" 2 intersects with v_lines. angle is dangerous.",
a, vel.x, vel.y );
speed -= 2.0;
}
if ( speed > max_speed )
{
max_speed = speed;
best_angle = target_rel_angle + wm.self().body();
rcsc::dlog.addText( rcsc::Logger::TEAM,
__FILE__": clearGoal() update. angle=%.1f vel_angle=%.1f speed=%.2f",
a,
相關推薦
C++ "multiple definition of .. first defined here 錯誤的修改
今天將Helios有關程式碼摳到我們的底層時,發現不少地方出現 "multiple definition of .. first defined here 錯誤。這個檔案的.h和.cpp檔案在下面。以及修改方法: ====================
stb_image multiple definition of first defined here 多檔案包含問題
解決辦法:預先定義 STB_IMAGE_IMPLEMENTATION STB_IMAGE_STATIC 兩個巨集。 首先吐槽一下,網上的其他的一些內容都是瞎寫,根本沒有指出問題的根本原因,使用時出現異常情況不能自己解決也說明了C語言基礎不牢固, 該標頭檔案可以分
報錯:multiple definition of 和 first defined here
1、就只有一處定義了全域性變數,但還是報錯,提示重複定義。 2、檢查.h標頭檔案,已經避免重複包含了。 解決方法: 在.c程式中定義全域性變數,在.h檔案中使用extern 做外部宣告,供其他檔案呼叫。 參考連結: https://blog.csdn.net/manti
C++ 解決 multiple definition of & previous definition here編譯錯誤
1、第一種可能是 一個函式多次重定義 應新增以下巨集定義 #ifndef TEST_H #define TEST_H #include //you code #endif 2、原始碼直接寫在標頭檔案.h裡沒有對應的.cpp檔案 需要每個函式前新增 inline
C++ 惱人的multiple definition of X連結錯誤
1. 錯誤原因 首先查了一下C&C++從原始碼編譯到可執行檔案的過程: 1)預處理將偽指令(巨集定義、條件編譯、和引用標頭檔案)和特殊符號進行處理 2)編譯過程通過詞法分析、語法分析等步驟生成彙編程式碼的過程,過程中還會進行優化 3)彙編過程將彙編程式碼翻譯為目標機器指令的過
解決C++編譯出現的重定義問題:multiple definition of ’XXX‘錯誤
1 //file_NO2:hello.cpp 2 #include<iostream> 3 #include"hello.h" 4 using namespace std;
如何解決linux下編譯出現的multiple definition of錯誤
今天,在編譯quagga的過程中出現了multiple definition of的錯誤。該錯誤表示不同檔案對同一變數進行了重複定義。因此,可以從以下幾個方面來排查這個問題: 1. 是否定義了重複變數: 直觀來講,如果在已經引用的global.h中定義了變數v,那麼在本檔案
c語言重複定義 multiple definition of `Recusion'
c語言重複定義。。。。 我在標頭檔案(.h)中定義聲明瞭一個變數 int Recusion = 0;/*0,1*/ 然後在兩個.cpp檔案中使用 a.cpp -------------------------- Recusion = 1; b.cpp
解決C++中multiple definition of問題
1.global.h #ifndef _GLOBAL_H #define _FACEDETECT_H struct People{ string name; int age;
編譯時產生multiple definition of 錯誤的解決方法
總結了解決multiple definition of的方法: 問題原因: (1) 當多個檔案包含同一個標頭檔案時,並且你的.H裡面沒有加上條件編譯 #ifndef TEST_H #define TEST_H #endif 就會獨立的解釋,然後生成每個檔案生成獨立的標
【C++】變數定義在.h標頭檔案導致 multiple definition of 的解決方法和根本原因
說明:出現這個錯誤,請你先檢查重複定義的變數是否是定義在了.h標頭檔案中,如果是,請您耐心的看完這篇文章,他會告訴你錯誤的根本原因。 如果你很著急,不想弄清楚原因,請直接按下面的方法更改: 假設重複定
鏈接錯誤:multiple definition of 'xxx' 問題解決及其原理
水管 及其 head 外部聲明 重復元素 img 一定的 原理 重復 內容借鑒 於CSDN炸雞叔 錯因 截圖: “multiple definition of ‘head‘ ” “multiple definition of
multiple definition of `qMain(int, char**)'
發現 image com init tip 項目文件 efi 生成 天發 QT C++ 我上一分鐘運行地好好的,下一分鐘就無法通過編譯了。查了半天發現在IDE自動生成的項目文件.pro中 main竟然包含了兩遍。我對這表示很無語,我完全是通過IDE來操作,卻產生一些我不易察
除錯經驗——如何檢視Oracle自定義函式 (How to view definition of user defined functions in Oracle)
問題描述: 現有的Query中似乎使用了一個自定義函式String_to_list,為了排查問題,需要檢視這個函式的定義。 方法: --新建的function,並未儲存在All_ojbects表中,而是儲存在user_objects表中 SELECT * FRO
Qt提示 multiple definition of `SystemMenuButton::SystemMenuButton(QWidget*)
為了防止以後編碼出現類似得錯誤,在這裡記錄下-------------------------------------------- 錯誤提示: F:\shined-PC(488AD2092F21)\build-InformationDelivery-Desktop_Qt_5_5_1_Min
解決 multiple definition of 問題
原因:多個檔案包含同一個標頭檔案且標頭檔案.h沒有加上條件編譯。因為每個.h標頭檔案被編譯生成獨立的標示符,編譯器連結時就出現了重複定義的錯誤。 Methon 1:為每個標頭檔案加上條件編譯,避免該檔案多次引用時被多次解釋。 #ifndef TEST_H #
檔案編譯時出現multiple definition of `xxxxxx'的解決辦法
問題: 原來有單個檔案tcpclient.c,執行gcc -o tcpclient tcpclient.c可以順利完成編譯,並能與下載到目標板中的tcpserver成功通訊; 現在把tcpclient.c中的底層通訊部分抽取出來,單獨放到一個檔案中nettrans.c中,並
multiple definition of 變數重複定義
# vi test.c ------------------------------- #include <stdio.h> #include "test.h" extern i; extern void test1(); extern v
全域性變數 multiple definition of 問題解決方法
解決方法:1.給每一個頭檔案加上條件編譯:注:此方法不是解決上述問題的方法,只是解決multiple definition of的一個方法。 當多個檔案包含同一個標頭檔案時,而標頭檔案中沒有加上條件編譯,就會獨立的解釋,然後生成每個檔案生成獨立的標示符。在編譯器連線時
multiple definition of 問題解決方法
問題描述:有一個opt_process.h檔案,兩個.cc檔案都引用了這個.h檔案,在.h檔案中聲明瞭一些全域性變數,報錯 /tmp/ccBCSKoH.o:(.bss+0x0): multiple definition of longopts' /tmp/c