📄 environment.htm
字号:
</table>
</div>
<p class="MsoNormal" align="left">
<span style="font-family: Arial; font-weight: normal">The next method
returns the IHistory for the last test of the individual in this
</span><span style="font-family:Arial">IEnvironment</span><span style="font-family: Arial; font-weight: normal">or <i>null </i>if tests have not yet been run. </span></p>
<div align="center">
<table border="0" width="90%" id="table9">
<tr>
<td>
<p class="MsoNormal" style="text-autospace: none; margin-top: 0; margin-bottom: 0" align="left">
<span style="font-size: 10.0pt; font-family: Courier New">
public</span><span style="font-size:10.0pt;font-family:"Courier New"">
IHistory History {</span></p>
<p class="MsoNormal" style="text-autospace: none; margin-top: 0; margin-bottom: 0" align="left">
<font size="2"><span style="font-family: Courier New">
</span></font>
<span style="font-size: 10.0pt; font-family: Courier New">
get</span><span style="font-size:10.0pt;font-family:"Courier New"">
{</span></p>
<p class="MsoNormal" style="text-autospace: none; margin-top: 0; margin-bottom: 0" align="left">
<font size="2"><span style="font-family: Courier New">
</span></font>
<span style="font-size: 10.0pt; font-family: Courier New">
return</span><span style="font-size:10.0pt;font-family:"Courier New"">
m_AntHistory;</span></p>
<p class="MsoNormal" style="text-autospace: none; margin-top: 0; margin-bottom: 0" align="left">
<font size="2"><span style="font-family: Courier New">
</span></font>
<span style="font-size:10.0pt;font-family:"Courier New"">
}</span></p>
<p class="MsoNormal" style="text-autospace: none; margin-top: 0; margin-bottom: 0" align="left">
<span style="font-size:10.0pt;font-family:"Courier New"">
}</span></p>
<p class="MsoNormal" style="text-autospace: none" align="left">
<span style="font-size: 10.0pt; font-family: Courier New">
private</span><span style="font-size:10.0pt;font-family:"Courier New"">
AntHistory m_AntHistory;</span></td>
</tr>
</table>
</div>
<h4 align="left"><span style="font-family: Arial; font-weight: normal">
Next, any problem-specific methods are defined. The artificial ant, for
example, has a method to limit the number of steps the ant can take.
This is one way to determine if the ant is finished being tested. This ensures that the ant does not wind up in an
infinite loop.</span></h4>
<div align="center">
<table border="0" width="90%" id="table10">
<tr>
<td>
<p class="MsoNormal" style="text-autospace: none; margin-top: 0; margin-bottom: 0" align="left">
<span style="font-size: 10.0pt; font-family: Courier New">
public</span><span style="font-size:10.0pt;font-family:"Courier New"">
int StepLimit {</span></p>
<p class="MsoNormal" style="text-autospace: none; margin-top: 0; margin-bottom: 0" align="left">
<font size="2"><span style="font-family: Courier New">
</span></font>
<span style="font-size: 10.0pt; font-family: Courier New">
get</span><span style="font-size:10.0pt;font-family:"Courier New"">
{</span></p>
<p class="MsoNormal" style="text-autospace: none; margin-top: 0; margin-bottom: 0" align="left">
<font size="2"><span style="font-family: Courier New">
</span></font>
<span style="font-size: 10.0pt; font-family: Courier New">
return</span><span style="font-size:10.0pt;font-family:"Courier New"">
m_StepLimit;</span></p>
<p class="MsoNormal" style="text-autospace: none; margin-top: 0; margin-bottom: 0" align="left">
<font size="2"><span style="font-family: Courier New">
</span></font>
<span style="font-size:10.0pt;font-family:"Courier New"">
}</span></p>
<p class="MsoNormal" style="text-autospace: none; margin-top: 0; margin-bottom: 0" align="left">
<span style="font-size:10.0pt;font-family:"Courier New"">
}</span></p>
<p class="MsoNormal" style="text-autospace: none; margin-top: 0; margin-bottom: 0" align="left"> </p>
<h4 align="left" style="margin-top: 0; margin-bottom: 0">
<span style="font-size: 10.0pt; font-family: Courier New; font-weight: normal">
private int m_StepLimit = 500;</span></h4>
</td>
</tr>
</table>
</div>
<h4 align="left" style="margin-top: 0; margin-bottom: 0"> </h4>
<h4 align="left" style="margin-top: 0; margin-bottom: 0">
<span style="font-family: Arial; font-weight: normal">Another possible
way for the ant to finish testing is to have collected all of the
available in the environment. This is another problem specific
method that tells the engine the ant is done being tested. </span></h4>
<p align="left" style="margin-top: 0; margin-bottom: 0"> </p>
<div align="center">
<table border="0" width="90%" id="table11">
<tr>
<td>
<p class="MsoNormal" style="text-autospace: none; margin-top: 0; margin-bottom: 0" align="left">
<span style="font-size: 10.0pt; font-family: Courier New">
public</span><span style="font-size:10.0pt;font-family:"Courier New"">
bool AllFoodCollected {</span></p>
<p class="MsoNormal" style="text-autospace: none; margin-top: 0; margin-bottom: 0" align="left">
<font size="2"><span style="font-family: Courier New">
</span></font>
<span style="font-size: 10.0pt; font-family: Courier New">
get</span><span style="font-size:10.0pt;font-family:"Courier New"">
{</span></p>
<p class="MsoNormal" style="text-autospace: none; margin-top: 0; margin-bottom: 0" align="left">
<font size="2"><span style="font-family: Courier New">
</span></font>
<span style="font-size: 10.0pt; font-family: Courier New">
return</span><span style="font-size:10.0pt;font-family:"Courier New"">
m_AntHistory.FoodFound == m_FoodCount;</span></p>
<p class="MsoNormal" style="text-autospace: none; margin-top: 0; margin-bottom: 0" align="left">
<font size="2"><span style="font-family: Courier New">
</span></font>
<span style="font-size:10.0pt;font-family:"Courier New"">
}</span></p>
<p class="MsoNormal" style="text-autospace: none; margin-top: 0; margin-bottom: 0" align="left">
<span style="font-size:10.0pt;font-family:"Courier New"">
}</span></td>
</tr>
</table>
</div>
<h4 align="left"><span style="font-family: Arial; font-weight: normal">
Next, problem specific local variables are defined. For example,
m_FoodCount tracks how many pieces of food an ant has collected in an
</span><span style="font-family:Arial; font-weight:400">IEnvironment</span><span style="font-family: Arial; font-weight: normal">. m_Grid specifies
the XML grid for the individual ant m_HisotryGrid is a clone of
the grid which will be shared by the histories of all IIndividuals.</span></h4>
<div align="center">
<table border="0" width="90%" id="table12">
<tr>
<td>
<p class="MsoNormal" style="text-autospace: none; margin-top: 0; margin-bottom: 0" align="left">
<span style="font-size: 10.0pt; font-family: Courier New">
private</span><span style="font-size:10.0pt;font-family:"Courier New"">
int m_FoodCount;</span></p>
<p class="MsoNormal" style="text-autospace: none; margin-top: 0; margin-bottom: 0" align="left">
<span style="font-size: 10.0pt; font-family: Courier New">
private</span><span style="font-size:10.0pt;font-family:"Courier New"">
string m_Name;</span></p>
<p class="MsoNormal" style="text-autospace: none; margin-top: 0; margin-bottom: 0" align="left">
<span style="font-size: 10.0pt; font-family: Courier New">
private</span><span style="font-size:10.0pt;font-family:"Courier New"">
Grid m_Grid;</span></p>
<p class="MsoNormal" style="text-autospace: none; margin-top: 0; margin-bottom: 0" align="left">
<span style="font-size: 10.0pt; font-family: Courier New">
private</span><span style="font-size:10.0pt;font-family:"Courier New"">
Grid m_HistoryGrid;</span></td>
</tr>
</table>
</div>
<h4 align="left"><span style="font-family: Arial; font-weight: normal">
Next, the environment is initialized. The </span>
<span style="font-family: Arial; font-weight: 400">
IEnvironment </span><span style="font-family: Arial; font-weight: normal">
is initialized
with the file specified by the InitializationFile parameter. This
met</span><span style="font-family: Arial; font-weight: 400">hod verifies the
IEnvironment file. Initialize
also sets IEnvironment variables to default values. For example, the
initialize method sets </span><span style="font-family: Arial; font-weight: normal">m_FoodCount to
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -