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

📄 formations_8c-source.html

📁 仿真人工智能是指用人工的方法和技术
💻 HTML
📖 第 1 页 / 共 3 页
字号:
00506   <font class="keywordflow">if</font>( ptInfo-&gt;<a class="code" href="classPlayerTypeInfo.html#a15">getBehindBall</a>() == <font class="keyword">true</font> &amp;&amp; x &gt; posBall.<a class="code" href="classVecPosition.html#a26">getX</a>() )00507     x = posBall.<a class="code" href="classVecPosition.html#a26">getX</a>();00508 00509   <font class="comment">// do not move past maximal x or before minimal x</font>00510   <font class="keywordflow">if</font>( x &gt; ptInfo-&gt;<a class="code" href="classPlayerTypeInfo.html#a13">getMaxX</a>() )00511     x = ptInfo-&gt;<a class="code" href="classPlayerTypeInfo.html#a13">getMaxX</a>();00512   <font class="keywordflow">else</font> <font class="keywordflow">if</font>( x &lt; ptInfo-&gt;<a class="code" href="classPlayerTypeInfo.html#a11">getMinX</a>() )00513     x = ptInfo-&gt;<a class="code" href="classPlayerTypeInfo.html#a11">getMinX</a>();00514 00515   <font class="comment">// when x coordinate is in front of allowed x value, change it</font>00516   <font class="keywordflow">if</font>( x &gt; dMaxXInPlayMode )00517     x = dMaxXInPlayMode;00518 00519   <font class="keywordflow">return</font> <a class="code" href="classVecPosition.html">VecPosition</a>( x, y );00520 }00521 <a name="l00534"></a><a class="code" href="classFormations.html#a3">00534</a> <font class="keywordtype">bool</font> <a class="code" href="classFormations.html#a3">Formations::readFormations</a>( <font class="keyword">const</font> <font class="keywordtype">char</font> *strFile )00535 {00536   ifstream in( strFile );00537   <font class="keywordflow">if</font>( !in )00538   {00539     cerr &lt;&lt; <font class="stringliteral">"(readValues::readValues) Could not open file '"</font> &lt;&lt;00540     strFile &lt;&lt; <font class="stringliteral">"'"</font> &lt;&lt; endl;00541     <font class="keywordflow">return</font> <font class="keyword">false</font>;00542   }00543 00544   <font class="keywordtype">char</font> strLine[256], *str;00545   <font class="keywordtype">int</font>            iLineNr          = 0, i;00546   <font class="keywordtype">int</font>            iForm            = 0; <font class="comment">// current formation type that is parsed</font>00547   <font class="keywordtype">int</font>            iLineInFormation = 0; <font class="comment">// current offset of line in formation</font>00548   <font class="keywordtype">bool</font>           bReturn          = <font class="keyword">true</font>;00549   <a class="code" href="classPlayerTypeInfo.html">PlayerTypeInfo</a> *pt_info;00550 00551   <font class="comment">// read all lines</font>00552   <font class="keywordflow">while</font>( bReturn &amp;&amp; in.getline( strLine, <font class="keyword">sizeof</font>(strLine) ) )00553   {00554     str = &amp;strLine[0];00555     iLineNr++;00556     <font class="comment">// comment and empty lines should be skipped</font>00557     <font class="keywordflow">if</font>( !(strLine[0] == <font class="charliteral">'\n'</font> || strLine[0] == <font class="charliteral">'#'</font> || strLine[0]==<font class="charliteral">'\0'</font> ||00558           <a class="code" href="classParse.html#d4">Parse::gotoFirstNonSpace</a>( &amp;str ) == <font class="charliteral">'\0'</font> ) )00559     {00560       <font class="comment">// there are nine different lines in a formation (see comment above)</font>00561       <font class="comment">// all values for each line are parsed in one iteration</font>00562       <font class="comment">// after all 9 lines are parsed, the sequence it is resetted.</font>00563       <font class="keywordflow">switch</font>( iLineInFormation )00564       {00565         <font class="keywordflow">case</font> 0: <font class="comment">// first line is the number of the formation</font>00566           iForm = <a class="code" href="classParse.html#d1">Parse::parseFirstInt</a>( &amp;str );00567           <font class="keywordflow">break</font>;00568         <font class="keywordflow">case</font> 1: <font class="comment">// the x coordinate of the home pos for all the players</font>00569           <font class="keywordflow">for</font>( i = 0 ; i &lt; <a class="code" href="SoccerTypes_8h.html#a0">MAX_TEAMMATES</a> ; i ++ )00570             <a class="code" href="classFormations.html#o0">formations</a>[iForm].<a class="code" href="classFormationTypeInfo.html#a5">setXPosHome</a>(<a class="code" href="classParse.html#d0">Parse::parseFirstDouble</a>(&amp;str), i);00571           <font class="keywordflow">break</font>;00572         <font class="keywordflow">case</font> 2: <font class="comment">// the y coordinate of the home pos for all the players</font>00573           <font class="keywordflow">for</font>( i = 0 ; i &lt; <a class="code" href="SoccerTypes_8h.html#a0">MAX_TEAMMATES</a> ; i ++ )00574             <a class="code" href="classFormations.html#o0">formations</a>[iForm].<a class="code" href="classFormationTypeInfo.html#a6">setYPosHome</a>(<a class="code" href="classParse.html#d0">Parse::parseFirstDouble</a>(&amp;str), i);00575           <font class="keywordflow">break</font>;00576         <font class="keywordflow">case</font> 3: <font class="comment">// the player types for all the players</font>00577           <font class="keywordflow">for</font>( i = 0 ; i &lt; <a class="code" href="SoccerTypes_8h.html#a0">MAX_TEAMMATES</a> ; i ++ )00578             <a class="code" href="classFormations.html#o0">formations</a>[iForm].<a class="code" href="classFormationTypeInfo.html#a8">setPlayerType</a>(00579                 (<a class="code" href="SoccerTypes_8h.html#a248">PlayerT</a>) <a class="code" href="classParse.html#d1">Parse::parseFirstInt</a>(&amp;str), i);00580           <font class="keywordflow">break</font>;00581         <font class="keywordflow">case</font> 4: <font class="comment">// the x attraction for all the player types</font>00582           <font class="keywordflow">for</font>( i = 0 ; i &lt; <a class="code" href="SoccerTypes_8h.html#a2">MAX_PLAYER_TYPES</a> ; i ++ )00583           {00584             pt_info = <a class="code" href="classFormations.html#o0">formations</a>[iForm].<a class="code" href="classFormationTypeInfo.html#a11">getPlayerTypeInfo</a>( i );00585             pt_info-&gt;<a class="code" href="classPlayerTypeInfo.html#a6">setAttrX</a>( <a class="code" href="classParse.html#d0">Parse::parseFirstDouble</a>( &amp;str ) );00586           }00587           <font class="keywordflow">break</font>;00588         <font class="keywordflow">case</font> 5: <font class="comment">// the y attraction for all the player types</font>00589           <font class="keywordflow">for</font>( i = 0 ; i &lt; <a class="code" href="SoccerTypes_8h.html#a2">MAX_PLAYER_TYPES</a> ; i ++ )00590           {00591             pt_info = <a class="code" href="classFormations.html#o0">formations</a>[iForm].<a class="code" href="classFormationTypeInfo.html#a11">getPlayerTypeInfo</a>( i );00592             pt_info-&gt;<a class="code" href="classPlayerTypeInfo.html#a8">setAttrY</a>( <a class="code" href="classParse.html#d0">Parse::parseFirstDouble</a>( &amp;str ) );00593           }00594           <font class="keywordflow">break</font>;00595         <font class="keywordflow">case</font> 6: <font class="comment">// stay behind the ball for all the player types</font>00596           <font class="keywordflow">for</font>( i = 0 ; i &lt; <a class="code" href="SoccerTypes_8h.html#a2">MAX_PLAYER_TYPES</a> ; i ++ )00597           {00598             pt_info = <a class="code" href="classFormations.html#o0">formations</a>[iForm].<a class="code" href="classFormationTypeInfo.html#a11">getPlayerTypeInfo</a>( i );00599             <font class="keywordflow">if</font>( <a class="code" href="classParse.html#d1">Parse::parseFirstInt</a>( &amp;str ) == 1 )00600               pt_info-&gt;<a class="code" href="classPlayerTypeInfo.html#a14">setBehindBall</a>( <font class="keyword">true</font> );00601             <font class="keywordflow">else</font>00602               pt_info-&gt;<a class="code" href="classPlayerTypeInfo.html#a14">setBehindBall</a>( <font class="keyword">false</font> );          ;00603           }00604           <font class="keywordflow">break</font>;00605         <font class="keywordflow">case</font> 7: <font class="comment">// the minimal x coordinate for all the player types</font>00606           <font class="keywordflow">for</font>( i = 0 ; i &lt; <a class="code" href="SoccerTypes_8h.html#a2">MAX_PLAYER_TYPES</a> ; i ++ )00607           {00608             pt_info = <a class="code" href="classFormations.html#o0">formations</a>[iForm].<a class="code" href="classFormationTypeInfo.html#a11">getPlayerTypeInfo</a>( i );00609             pt_info-&gt;<a class="code" href="classPlayerTypeInfo.html#a10">setMinX</a>( <a class="code" href="classParse.html#d0">Parse::parseFirstDouble</a>( &amp;str ));00610           }00611           <font class="keywordflow">break</font>;00612         <font class="keywordflow">case</font> 8:<font class="comment">// the maximal x coordinate for all the player types</font>00613           <font class="keywordflow">for</font>( i = 0 ; i &lt; <a class="code" href="SoccerTypes_8h.html#a2">MAX_PLAYER_TYPES</a> ; i ++ )00614           {00615             pt_info = <a class="code" href="classFormations.html#o0">formations</a>[iForm].<a class="code" href="classFormationTypeInfo.html#a11">getPlayerTypeInfo</a>( i );00616             pt_info-&gt;<a class="code" href="classPlayerTypeInfo.html#a12">setMaxX</a>( <a class="code" href="classParse.html#d0">Parse::parseFirstDouble</a>( &amp;str ));00617           }00618           <font class="keywordflow">break</font>;00619         <font class="keywordflow">default</font>:00620           cerr &lt;&lt; <font class="stringliteral">"(Formations::readFormations) error line "</font> &lt;&lt; iLineNr &lt;&lt;endl;00621           <font class="keywordflow">return</font> <font class="keyword">false</font>;00622       }00623 00624       iLineInFormation++;         <font class="comment">// go one line further</font>00625       <font class="keywordflow">if</font>( iLineInFormation == 9 ) <font class="comment">// each formation consists of nine lines</font>00626         iLineInFormation = 0;00627     }00628   }00629   <font class="keywordflow">return</font> <font class="keyword">true</font>;00630 }00631 <a name="l00635"></a><a class="code" href="classFormations.html#a4">00635</a> <font class="keywordtype">bool</font> <a class="code" href="classFormations.html#a4">Formations::setFormation</a>( <a class="code" href="SoccerTypes_8h.html#a249">FormationT</a> formation )00636 {00637   <a class="code" href="classFormations.html#o1">curFormation</a> = formation;00638   <font class="keywordflow">return</font> <font class="keyword">true</font>;00639 }00640 <a name="l00643"></a><a class="code" href="classFormations.html#a5">00643</a> <a class="code" href="SoccerTypes_8h.html#a249">FormationT</a> <a class="code" href="classFormations.html#a5">Formations::getFormation</a>( )<font class="keyword"> const</font>00644 <font class="keyword"></font>{00645   <font class="keywordflow">return</font> <a class="code" href="classFormations.html#o1">curFormation</a>;00646 }00647 <a name="l00652"></a><a class="code" href="classFormations.html#a6">00652</a> <font class="keywordtype">bool</font> <a class="code" href="classFormations.html#a6">Formations::setPlayerInFormation</a>( <font class="keywordtype">int</font> iNumber )00653 {00654   <a class="code" href="classFormations.html#o2">iPlayerInFormation</a> = iNumber;00655   <font class="keywordflow">return</font> <font class="keyword">true</font>;00656 }00657 <a name="l00660"></a><a class="code" href="classFormations.html#a7">00660</a> <font class="keywordtype">int</font> <a class="code" href="classFormations.html#a7">Formations::getPlayerInFormation</a>( )<font class="keyword"> const</font>00661 <font class="keyword"></font>{00662   <font class="keywordflow">return</font> <a class="code" href="classFormations.html#o2">iPlayerInFormation</a>;00663 }00664 <a name="l00667"></a><a class="code" href="classFormations.html#a8">00667</a> <a class="code" href="SoccerTypes_8h.html#a248">PlayerT</a> <a class="code" href="classFormations.html#a8">Formations::getPlayerType</a>( )<font class="keyword"> const</font>00668 <font class="keyword"></font>{00669   <font class="keywordflow">return</font> <a class="code" href="classFormations.html#o0">formations</a>[ <a class="code" href="classFormations.html#o1">curFormation</a> ].getPlayerType( <a class="code" href="classFormations.html#o2">iPlayerInFormation</a> );00670 }00671 00672 <font class="comment">/*************************** TESTING PURPOSES *********************************/</font>00673 00674 <font class="comment">/*</font>00675 <font class="comment">int main( void )</font>00676 <font class="comment">{</font>00677 <font class="comment">  Formations fs( "formations.conf" );</font>00678 <font class="comment">  fs.show( cout );</font>00679 <font class="comment">}</font>00680 <font class="comment">*/</font></pre></div><hr><address><small>Generated on Thu Mar 7 00:37:42 2002 for UvA Trilearn 2001 by<a href="http://www.doxygen.org/index.html"><img src="doxygen.gif" alt="doxygen" align="middle" border=0 width=110 height=53></a>1.2.12 written by <a href="mailto:dimitri@stack.nl">Dimitri van Heesch</a>, &copy;&nbsp;1997-2001</small></address></body></html>

⌨️ 快捷键说明

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