player_8c-source.html
来自「仿真人工智能是指用人工的方法和技术」· HTML 代码 · 共 545 行 · 第 1/5 页
HTML
545 行
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>Player.C Source File</title><link href="doxygen.css" rel="stylesheet" type="text/css"></head><body bgcolor="#ffffff"><!-- Generated by Doxygen 1.2.12 --><center><a class="qindex" href="index.html">Main Page</a> <a class="qindex" href="hierarchy.html">Class Hierarchy</a> <a class="qindex" href="annotated.html">Compound List</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="functions.html">Compound Members</a> <a class="qindex" href="globals.html">File Members</a> </center><hr><h1>Player.C</h1><a href="Player_8C.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <font class="comment">/*</font>00002 <font class="comment">Copyright (c) 2000,2001, Jelle Kok, University of Amsterdam</font>00003 <font class="comment">All rights reserved.</font>00004 <font class="comment"></font>00005 <font class="comment">Redistribution and use in source and binary forms, with or without </font>00006 <font class="comment">modification, are permitted provided that the following conditions are met:</font>00007 <font class="comment"></font>00008 <font class="comment">1. Redistributions of source code must retain the above copyright notice, this </font>00009 <font class="comment">list of conditions and the following disclaimer. </font>00010 <font class="comment"></font>00011 <font class="comment">2. Redistributions in binary form must reproduce the above copyright notice, </font>00012 <font class="comment">this list of conditions and the following disclaimer in the documentation </font>00013 <font class="comment">and/or other materials provided with the distribution. </font>00014 <font class="comment"></font>00015 <font class="comment">3. Neither the name of the University of Amsterdam nor the names of its </font>00016 <font class="comment">contributors may be used to endorse or promote products derived from this </font>00017 <font class="comment">software without specific prior written permission. </font>00018 <font class="comment"></font>00019 <font class="comment">THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" </font>00020 <font class="comment">AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE </font>00021 <font class="comment">IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE </font>00022 <font class="comment">DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE </font>00023 <font class="comment">FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL </font>00024 <font class="comment">DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR </font>00025 <font class="comment">SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER </font>00026 <font class="comment">CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, </font>00027 <font class="comment">OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE </font>00028 <font class="comment">OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</font>00029 <font class="comment">*/</font>00044 <font class="preprocessor">#include "<a class="code" href="Player_8h.html">Player.h</a>"</font>00045 <font class="preprocessor">#include "<a class="code" href="Parse_8h.html">Parse.h</a>"</font>00046 <font class="preprocessor">#include <sys/poll.h></font> <font class="comment">// needed for 'poll'</font>00047 00048 <a name="l00058"></a><a class="code" href="classPlayer.html#a0">00058</a> <a class="code" href="classPlayer.html#a0">Player::Player</a>( <a class="code" href="classActHandler.html">ActHandler</a>* act, <a class="code" href="classWorldModel.html">WorldModel</a> *wm, <a class="code" href="classServerSettings.html">ServerSettings</a> *ss,00059 <a class="code" href="classPlayerSettings.html">PlayerSettings</a> *ps,00060 <a class="code" href="classFormations.html">Formations</a> *fs, <font class="keywordtype">char</font>* strTeamName, <font class="keywordtype">double</font> dVersion, <font class="keywordtype">int</font> iReconnect )00061 00062 {00063 <font class="keywordtype">char</font> str[<a class="code" href="SoccerTypes_8h.html#a6">MAX_MSG</a>];00064 00065 <a class="code" href="classBasicPlayer.html#n0">ACT</a> = act;00066 <a class="code" href="classBasicPlayer.html#n1">WM</a> = wm;00067 <a class="code" href="classBasicPlayer.html#n2">SS</a> = ss;00068 <a class="code" href="classBasicPlayer.html#n3">PS</a> = ps;00069 <a class="code" href="classPlayer.html#o0">formations</a> = fs;00070 <a class="code" href="classPlayer.html#o1">bContLoop</a> = <font class="keyword">true</font>;00071 <a class="code" href="classBasicPlayer.html#n1">WM</a>-><a class="code" href="classWorldModel.html#a19">setTeamName</a>( strTeamName );00072 <a class="code" href="classPlayer.html#o2">m_lastSay</a> = -1;00073 00074 <font class="comment">// wait longer as role number increases, to make sure players appear at the</font>00075 <font class="comment">// field in the correct order</font>00076 poll( 0, 0, <a class="code" href="classPlayer.html#o0">formations</a>-><a class="code" href="classFormations.html#a7">getPlayerInFormation</a>()*100 );00077 00078 <font class="comment">// create initialisation string</font>00079 <font class="keywordflow">if</font>( iReconnect != -1 )00080 sprintf( str, <font class="stringliteral">"(reconnect %s %d)"</font>, strTeamName, iReconnect );00081 <font class="keywordflow">else</font> <font class="keywordflow">if</font>( <a class="code" href="classPlayer.html#o0">formations</a>-><a class="code" href="classFormations.html#a8">getPlayerType</a>() == <a class="code" href="SoccerTypes_8h.html#a248a193">PT_GOALKEEPER</a> )00082 sprintf( str, <font class="stringliteral">"(init %s (version %f) (goalie))"</font>, strTeamName, dVersion );00083 <font class="keywordflow">else</font>00084 sprintf( str, <font class="stringliteral">"(init %s (version %f))"</font>, strTeamName, dVersion );00085 <a class="code" href="classBasicPlayer.html#n0">ACT</a>-><a class="code" href="classActHandler.html#a6">sendMessage</a>( str );00086 }00087 <a name="l00092"></a><a class="code" href="classPlayer.html#a2">00092</a> <font class="keywordtype">void</font> <a class="code" href="classPlayer.html#a2">Player::mainLoop</a>( )00093 {00094 <font class="keywordflow">while</font>( bContLoop ) <font class="comment">// as long as server alive</font>00095 {00096 Log.logWithTime( 3, <font class="stringliteral">" start update_all"</font> );00097 <font class="comment">// Log.setHeader( WM->getCurrentCycle(), WM->getPlayerNumber() );</font>00098 00099 <font class="keywordflow">if</font>( <a class="code" href="classBasicPlayer.html#n1">WM</a>-><a class="code" href="classWorldModel.html#a97">updateAll</a>( ) == <font class="keyword">true</font> )00100 {00101 <font class="keywordflow">if</font>( <a class="code" href="classPlayer.html#a9">shallISaySomething</a>() == <font class="keyword">true</font> ) <font class="comment">// shall I communicate</font>00102 {00103 <a class="code" href="classPlayer.html#o2">m_lastSay</a> = <a class="code" href="classBasicPlayer.html#n1">WM</a>-><a class="code" href="classWorldModel.html#a5">getCurrentCycle</a>();00104 <a class="code" href="classBasicPlayer.html#n0">ACT</a>-><a class="code" href="classActHandler.html#a7">sendCommandDirect</a>( <a class="code" href="classPlayer.html#a11">sayWorldStatus</a>() );00105 }00106 00107 <font class="keywordflow">switch</font>( <a class="code" href="classPlayer.html#o0">formations</a>-><a class="code" href="classFormations.html#a8">getPlayerType</a>( ) ) <font class="comment">// determine right loop</font>00108 {00109 <font class="keywordflow">case</font> <a class="code" href="SoccerTypes_8h.html#a248a193">PT_GOALKEEPER</a>: <a class="code" href="classPlayer.html#c0">goalieMainLoop</a>( ); <font class="keywordflow">break</font>;00110 <font class="keywordflow">case</font> <a class="code" href="SoccerTypes_8h.html#a248a194">PT_DEFENDER_SWEEPER</a>:00111 <font class="keywordflow">case</font> <a class="code" href="SoccerTypes_8h.html#a248a195">PT_DEFENDER_WING</a>: <a class="code" href="classPlayer.html#c1">defenderMainLoop</a>( ); <font class="keywordflow">break</font>;00112 <font class="keywordflow">case</font> <a class="code" href="SoccerTypes_8h.html#a248a196">PT_MIDFIELDER_CENTER</a>:00113 <font class="keywordflow">case</font> <a class="code" href="SoccerTypes_8h.html#a248a197">PT_MIDFIELDER_WING</a>: <a class="code" href="classPlayer.html#c2">midfielderMainLoop</a>( ); <font class="keywordflow">break</font>;00114 <font class="keywordflow">case</font> <a class="code" href="SoccerTypes_8h.html#a248a199">PT_ATTACKER</a>:00115 <font class="keywordflow">case</font> <a class="code" href="SoccerTypes_8h.html#a248a198">PT_ATTACKER_WING</a>: <a class="code" href="classPlayer.html#c3">attackerMainLoop</a>( ); <font class="keywordflow">break</font>;00116 <font class="keywordflow">case</font> <a class="code" href="SoccerTypes_8h.html#a248a192">PT_ILLEGAL</a>:00117 <font class="keywordflow">default</font>: <font class="keywordflow">break</font>;00118 }00119 00120 Log.logWithTime( 3, <font class="stringliteral">" determined action; waiting for new info"</font> );00121 00122 <font class="comment">// directly after see message, will nog get better info, so send commands</font>00123 <font class="keywordflow">if</font>( <a class="code" href="classBasicPlayer.html#n1">WM</a>-><a class="code" href="classWorldModel.html#a10">getTimeLastSeeMessage</a>() == <a class="code" href="classBasicPlayer.html#n1">WM</a>-><a class="code" href="classWorldModel.html#a4">getCurrentTime</a>() )00124 <a class="code" href="classBasicPlayer.html#n0">ACT</a>-><a class="code" href="classActHandler.html#a4">sendCommands</a>( );00125 00126 }00127 <font class="keywordflow">else</font>00128 Log.logWithTime( 3, <font class="stringliteral">" HOLE no action determined; waiting for new info"</font> );
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?