worldmodelhighlevel_8c-source.html

来自「仿真人工智能是指用人工的方法和技术」· HTML 代码 · 共 765 行 · 第 1/5 页

HTML
765
字号
00830   <font class="comment">// make shooting line using position and desired direction</font>00831   <a class="code" href="classLine.html">Line</a> lineObj     = <a class="code" href="classLine.html#d1">Line::makeLineFromPositionAndAngle</a>( pos, ang );00832 00833   <font class="comment">// get intersection point between the created line and goal line</font>00834   <a class="code" href="classLine.html">Line</a> lineLength  = <a class="code" href="classLine.html#d1">Line::makeLineFromPositionAndAngle</a>(00835                             <a class="code" href="classVecPosition.html">VecPosition</a>( <a class="code" href="SoccerTypes_8h.html#a13">PITCH_LENGTH</a>/2.0 - dDist, 0.0 ), 90 );00836   posShoot         = lineObj.<a class="code" href="classLine.html#a2">getIntersection</a>( lineLength );00837 00838   <font class="comment">// check whether it first crosses the penalty line</font>00839   <a class="code" href="classLine.html">Line</a> linePenalty = <a class="code" href="classLine.html#d1">Line::makeLineFromPositionAndAngle</a>(00840                             <a class="code" href="classVecPosition.html">VecPosition</a>( <a class="code" href="SoccerTypes_8h.html#a18">PENALTY_X</a> - dDist, 0.0 ), 90.0 );00841   <font class="keywordtype">double</font> dPenaltyY = lineObj.<a class="code" href="classLine.html#a2">getIntersection</a>(linePenalty).<a class="code" href="classVecPosition.html#a28">getY</a>();00842 00843   <font class="keywordflow">if</font>( bWithPenalty &amp;&amp; fabs(dPenaltyY) &lt; <a class="code" href="SoccerTypes_8h.html#a17">PENALTY_AREA_WIDTH</a>/2.0 )00844   {00845     <font class="keywordflow">if</font>( fabs(dPenaltyY) &lt; <a class="code" href="SoccerTypes_8h.html#a17">PENALTY_AREA_WIDTH</a>/2.0 - 5.0 ||   <font class="comment">// crosses inside</font>00846         fabs(posShoot.<a class="code" href="classVecPosition.html#a28">getY</a>()) &lt;  <a class="code" href="SoccerTypes_8h.html#a17">PENALTY_AREA_WIDTH</a>/2.0 )   <font class="comment">// or ends inside</font>00847       posShoot = lineObj.<a class="code" href="classLine.html#a2">getIntersection</a>( linePenalty );00848   }00849 00850   <font class="comment">// check where it crosses the side line</font>00851   <a class="code" href="classLine.html">Line</a> lineSide = ( ang &lt; 0 )00852      ? <a class="code" href="classLine.html#d1">Line::makeLineFromPositionAndAngle</a>(00853                            <a class="code" href="classVecPosition.html">VecPosition</a>( 0.0, - <a class="code" href="SoccerTypes_8h.html#a14">PITCH_WIDTH</a>/2.0 + dDist ), 0.0 )00854      : <a class="code" href="classLine.html#d1">Line::makeLineFromPositionAndAngle</a>(00855                            <a class="code" href="classVecPosition.html">VecPosition</a>( 0.0, + <a class="code" href="SoccerTypes_8h.html#a14">PITCH_WIDTH</a>/2.0 - dDist ), 0.0 );00856 00857   <font class="keywordflow">if</font>( fabs(posShoot.<a class="code" href="classVecPosition.html#a28">getY</a>()) &gt; <a class="code" href="SoccerTypes_8h.html#a14">PITCH_WIDTH</a>/2.0 - dDist )00858     posShoot = lineObj.<a class="code" href="classLine.html#a2">getIntersection</a>( lineSide );00859 00860   <font class="keywordflow">return</font> posShoot;00861 }00862 <a name="l00874"></a><a class="code" href="classWorldModel.html#a142">00874</a> <a class="code" href="Geometry_8h.html#a2">AngDeg</a> <a class="code" href="classWorldModel.html#a142">WorldModel::getDirectionOfWidestAngle</a>(<a class="code" href="classVecPosition.html">VecPosition</a> posOrg, <a class="code" href="Geometry_8h.html#a2">AngDeg</a> angMin,00875                                <a class="code" href="Geometry_8h.html#a2">AngDeg</a> angMax, <a class="code" href="Geometry_8h.html#a2">AngDeg</a> *angLargest, <font class="keywordtype">double</font> dDist)00876 {00877   list&lt;double&gt; v;00878   list&lt;double&gt; v2;00879   <font class="keywordtype">double</font>       temp;00880   <font class="keywordtype">int</font>          iIndex;00881   <font class="keywordtype">double</font>       dConf  = <a class="code" href="classWorldModel.html#o1">PS</a>-&gt;<a class="code" href="classPlayerSettings.html#a1">getPlayerConfThr</a>();00882 00883   <font class="comment">// add all angles of all the opponents to the list v</font>00884   <font class="keywordflow">for</font>( <a class="code" href="SoccerTypes_8h.html#a240">ObjectT</a> o = <a class="code" href="classWorldModel.html#a31">iterateObjectStart</a>( iIndex, <a class="code" href="SoccerTypes_8h.html#a241a116">OBJECT_SET_OPPONENTS</a>, dConf );00885        o != <a class="code" href="SoccerTypes_8h.html#a240a113">OBJECT_ILLEGAL</a>;00886        o = <a class="code" href="classWorldModel.html#a32">iterateObjectNext</a> ( iIndex, <a class="code" href="SoccerTypes_8h.html#a241a116">OBJECT_SET_OPPONENTS</a>, dConf ) )00887   {00888     <font class="keywordflow">if</font>( <a class="code" href="classWorldModel.html#a54">getRelativeDistance</a>( o ) &lt; dDist )00889       v.push_back( (<a class="code" href="classWorldModel.html#a51">getGlobalPosition</a>(o)-posOrg).getDirection());00890   }00891   <a class="code" href="classWorldModel.html#a33">iterateObjectDone</a>( iIndex );00892   v.sort();00893 00894   <font class="comment">// Create new list with only opponents from interval [angMin..angMax].</font>00895   <font class="comment">// Note that opponents outside angMin and angMax can have an influence</font>00896   <font class="comment">// on the largest angle between the opponents, so they should be accounted</font>00897   <font class="comment">// for. To this end, a projection is defined in both angMin and angMax.</font>00898   <font class="comment">// The opponent with the smallest global angle difference a to angMin</font>00899   <font class="comment">// (either inside or outside the interval [angMin..angMax]) is determined</font>00900   <font class="comment">// and an extra angle angMin - a is added to the list. The situation for</font>00901   <font class="comment">// angMax is analogous.</font>00902 00903   <font class="keywordtype">double</font> absMin     = 1000;00904   <font class="keywordtype">double</font> absMax     = 1000;00905   <font class="keywordtype">double</font> angProjMin = angMin;00906   <font class="keywordtype">double</font> angProjMax = angMax;00907   <font class="keywordtype">double</font> array[<a class="code" href="SoccerTypes_8h.html#a1">MAX_OPPONENTS</a>+2];00908 00909   <font class="keywordflow">while</font>( v.size() &gt; 0 )00910   {00911     <font class="keywordflow">if</font>( fabs( v.front() - angMin ) &lt; absMin )      <font class="comment">// opp near angMin</font>00912     {00913       absMin     = fabs( v.front() - angMin ) ;    <font class="comment">// make angMin wider</font>00914       angProjMin = angMin - absMin;                <font class="comment">// to take him into account</font>00915     }00916     <font class="keywordflow">if</font>( fabs( v.front() - angMax ) &lt; absMax )      <font class="comment">// opp near angMax</font>00917     {00918       absMax     = fabs( v.front() - angMax ) ;    <font class="comment">// make angMax wider</font>00919       angProjMax = angMax + absMax;                <font class="comment">// to take him into account</font>00920     }00921     <font class="keywordflow">if</font>( v.front() &gt; angMin &amp;&amp; v.front() &lt; angMax ) <font class="comment">// opp in range</font>00922       v2.push_back( v.front() );                   <font class="comment">// add him</font>00923     v.pop_front();00924   }00925 00926   <font class="comment">// make all angles relative to angProjMin which has angle 0 and set them in</font>00927   <font class="comment">// the range 0..360, where the range -180..0 is moved to 180..360. Do this by</font>00928   <font class="comment">// adding 360 and then subtracting 360 if value is larger than 360.</font>00929   v.push_back( 0 );00930   <font class="keywordflow">while</font>( v2.size() &gt; 0 )  <font class="comment">// for all the opponents</font>00931   {00932     temp = <a class="code" href="classVecPosition.html#d1">VecPosition::normalizeAngle</a>(v2.front()-angProjMin)+360.0;00933     <font class="keywordflow">if</font>( temp &gt; 360 )00934       temp -= 360;00935     v.push_back( temp );00936     v2.pop_front();00937   }00938   <font class="comment">// add max projection.</font>00939   temp = <a class="code" href="classVecPosition.html#d1">VecPosition::normalizeAngle</a>(angProjMax-angProjMin)+360.0;00940   <font class="keywordflow">if</font>( temp &gt; 360 )00941     temp -= 360;00942 00943   v.push_back( temp );00944 00945   <font class="comment">// sort the list</font>00946   v.sort();00947 00948   <font class="comment">// put all the values in an array</font>00949   <font class="keywordtype">int</font> i = 0;00950   <font class="keywordflow">while</font>( v.size() &gt; 0 )00951   {00952     array[i++] = v.front();00953     v.pop_front();00954   }00955 00956   <font class="comment">// find the largest angle and determine the associated midpoint direction</font>00957   <font class="keywordtype">double</font> dLargest = -1000;00958   <font class="keywordtype">double</font> d;00959   <font class="keywordtype">double</font> ang      = <a class="code" href="SoccerTypes_8h.html#a20">UnknownAngleValue</a>;00960   <font class="keywordflow">for</font>( <font class="keywordtype">int</font> j = 0; j &lt; i - 1 ; j ++ )00961   {00962     d = <a class="code" href="classVecPosition.html#d1">VecPosition::normalizeAngle</a>(( array[j+1] - array[j] )/2.0);00963     <font class="keywordflow">if</font>( d &gt; dLargest )00964     {00965       ang = angProjMin + array[j] + d;00966       ang = <a class="code" href="classVecPosition.html#d1">VecPosition::normalizeAngle</a>( ang );00967       dLargest = d;00968     }00969   }00970 00971   <font class="keywordflow">if</font>( ang == <a class="code" href="SoccerTypes_8h.html#a20">UnknownAngleValue</a> ) <font class="comment">// no angle found -&gt; get angle in between</font>00972   {00973     ang = <a class="code" href="Geometry_8h.html#a13">getBisectorTwoAngles</a>( angMin, angMax );00974     <font class="keywordflow">if</font>( angLargest != NULL )00975       *angLargest = 360;00976   }00977   <font class="keywordflow">else</font> <font class="keywordflow">if</font>( angLargest != NULL )00978     *angLargest = dLargest;00979 00980   <font class="keywordflow">return</font> ang;00981 }00982 <a name="l00994"></a><a class="code" href="classWorldModel.html#a143">00994</a> <font class="keywordtype">double</font> <a class="code" href="classWorldModel.html#a143">WorldModel::getActualKickPowerRate</a>( )00995 {00996  <font class="comment">// true indicates that relative angle to body should be returned</font>00997  <font class="keywordtype">double</font> dir_diff      = fabs( <a class="code" href="classWorldModel.html#a56">getRelativeAngle</a>( <a class="code" href="SoccerTypes_8h.html#a240a24">OBJECT_BALL</a>, <font class="keyword">true</font> ) );00998  <font class="keywordtype">double</font> dist          = <a class="code" href="classWorldModel.html#a54">getRelativeDistance</a>( <a class="code" href="SoccerTypes_8h.html#a240a24">OBJECT_BALL</a> ) -00999                         <a class="code" href="classWorldModel.html#o0">SS</a>-&gt;<a class="code" href="classServerSettings.html#a6">getPlayerSize</a>( ) - <a class="code" href="classWorldModel.html#o0">SS</a>-&gt;<a class="code" href="classServerSettings.html#a58">getBallSize</a>( );01000  <font class="keywordflow">return</font> <a class="code" href="classWorldModel.html#o0">SS</a>-&gt;<a class="code" href="classServerSettings.html#a82">getKickPowerRate</a>() *01001            ( 1 - 0.25 * dir_diff/180.0 - 0.25 * dist / <a class="code" href="classWorldModel.html#o0">SS</a>-&gt;<a class="code" href="classServerSettings.html#a76">getKickableMargin</a>());01002 }01003 <a name="l01018"></a><a cla

⌨️ 快捷键说明

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