    <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http://purl.org/rss/1.0/modules/content/">
     <channel>
        <title>ACCU  :: Swamp Fever</title>
        <link>https://members.accu.org/index.php/articles/1096</link>
        <description>Professionalism in Programming</description>
        <dc:language>en-us</dc:language> 
        <dc:creator>Administrator</dc:creator> 
        <admin:generatorAgent rdf:resource="http://www.xaraya.org" /> 
        <admin:errorReportsTo rdf:resource="mailto:webeditor@accu.org" />
       <sy:updatePeriod>hourly</sy:updatePeriod>
       <sy:updateFrequency>1</sy:updateFrequency>
       <docs>http://backend.userland.com/rss</docs>




<div class="xar-mod-head"><span class="xar-mod-title">Programming Topics + CVu Journal Vol 13, #1 - Feb 2001</span></div>

<table border="0" cellpadding="1" cellspacing="0">
    <tbody>
    <tr>
        <td valign="top">
            Browse in :
       </td>
       <td valign="top">

                                            <a href="https://members.accu.org/index.php/articles/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c13/">Topics</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c65/">Programming</a>
<br />

                                            <a href="https://members.accu.org/index.php/articles/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c76/">Journals</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c77/">CVu</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c122/">131</a>
<br />

                                            <a href="https://members.accu.org/index.php/articles/c65-122/">Any of these categories</a>

                    -                        <a href="https://members.accu.org/index.php/articles/c65+122/">All of these categories</a>
<br />
</td>
   </tr>
   </tbody>
</table>




<div class="xar-error">
   <p>
 <strong>Note:</strong> when you create a new publication type,
the articles module will automatically use the templates
<em>user-display-[publicationtype].xt</em>
and <em>user-summary-[publicationtype].xt</em>.
If those templates do not exist when you try to preview or display a new article,
you'll get this warning :-)  Please place your own templates in themes/<em>yourtheme</em>/modules/articles . The templates will get the extension .xt there. </p>
</div>
<div class="xar-norm xar-standard-box-padding">
   <h1><strong>Title:</strong>&nbsp;Swamp Fever</h1>
<p><strong>Author:</strong>&nbsp;</p>
<p>
<strong>Date:</strong> 03 February 2001 13:15:43 +00:00 or Sat, 03 February 2001 13:15:43 +00:00</p>
<p><strong>Summary:</strong>&nbsp;</p>
<p><strong>Body:</strong>&nbsp;<div class="article" lang="en">
<div class="titlepage">
<div>
<div>
<h2><a name="d0e1" id="d0e1"></a>Swamp Fever</h2>
</div>
<div class="author">
<h3><span class="firstname">Barry</span>
<span class="surname">Aulton</span></h3>
<tt class="email">&lt;<a href=
"mailto:barry.aulton@bigwig.net">barry.aulton@bigwig.net</a>&gt;</tt></div>
</div>
<hr></div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e20" id="d0e20"></a></h2>
</div>
<p>I thought I would chip in with some suggestions on how to
implement the actions of computer players, not a design, more a
problem statement and some tricks and techniques that may (or may
not) help. Just to set the scene, I will present one possible
structure.</p>
<p>There is here a class <tt class="classname">Agent</tt> that is a
base class for associating game objects with specific AI Agents for
a particular game. Class <tt class="classname">SwampAgent</tt> is
derived from the base class <tt class="classname">Agent</tt> and
adds the specific techniques used for the Swamp game.</p>
<pre class="programlisting">
class Agent {
  protected:
    World *swampworld;
// e.g. representing the board
    Swamp_obj *swamp_object;  
// e.g. snake
  public:
    Agent(World *w=0,Swamp_obj *g=0);
    virtual ~Agent();
    virtual void run_agent();
    void set_swamp_object(Swamp_obj *g)
               { swamp_object=g; }
    void set_world(World *w) {swampworld=w; }
};
class SwampAgent: public Agent {

protected: // private: ?

    Expertsystem *expert_sys;
    Planmanager *plan_manager;
    Magicmethod *Mymagicmethod;
  public:
    Expertsystem *get_expert_system() 
            { return expert_sys; }
    Planmanager  *get_plan_manager() 
            { return plan_manager; }
    Magicmethod  *get_magicmethod() 
            { return Mymagicmethod; }
//Magic execute this to win the game routines
    virtual void run_agent();
    Swampagent(World * w,swamp_obj * g);
    ~Swampagent();
};
</pre>
<p>But how can we model intelligent behaviour conceptually?</p>
<div class="c2"><a name="figure1" id="figure1"></a><img src=
"resources/swamp_fever_fig1.png" align="middle"></div>
<p>Figure 1 (adopted from [<a href="#Albus">Albus</a>]) shows how
the problems of implementing intelligent computer players are
similar to that of implementing any intelligent system. Albus
splits the functional elements of the system, namely behaviour
generation (action control), sensory perception (to decide what is
happening), world modelling (including modelling the Swamp board
itself) and a knowledge database and expert system.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e45" id="d0e45"></a>Expert
System</h2>
</div>
<p>The knowledge database mainly consists of sets of game dependent
<tt class="literal">if then</tt> type rules and information (which
I will call <i class="firstterm">Messages</i>).</p>
<p>For human players, we may only test if the user requests are
valid and can be implemented. For computer players, an ad hoc
motivation layer can be used to select sets of rules in the expert
system for it to test. This crudely simulates human decisions.</p>
<p>For example, in Monopoly my motivation to consider buying
Mayfair may be a function of money, which is an integer value.</p>
<p>Rules with high priority are tested first (sometimes this order
of testing may need to be changed). The post conditions of an
expert system may result in game specific decision procedures being
executed rather than actions, so that the expert system acts as an
initial filtering mechanism.</p>
<pre class="programlisting">
class ExpertSystem {
  private:
    enum {MAX_MESSAGES=100};
    int num_messages;  // no of messages
    Message Messages[MAX_MESSAGES];
    int priorities[MAX_MESSAGES];  
// each message has a priority so that
// the highest priority rule whose
// preconditions are satisfied can be applied
    const char* titles[MAX_MESSAGES];  
// messages have a label attached
    int info;   // for debugging purposes
  public:
    ExpertSystem() { num_messages= info = 0;}
    void set_info(int &amp; inf) { info = inf; }
    int get_info() { return info; }
    ~ExpertSystem();
    void add_message(const char * title,
       rule_function rf, int priority=10);
    int send_message(World *, Game_obj *);
    void execute_message(World *w,Game_obj *g);
    ...
};
</pre></div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e64" id="d0e64"></a>Behaviour
Generation and Planning</h2>
</div>
<p>Behaviour generation is the planning and control of the agents
to achieve behavioural goals such as winning the game.</p>
<p>This involves hypothesising actions for the agents to carry out,
simulating and predicting the results and selecting the plan with
the most favourable results for execution. Even ad hoc formulae
that guess the consequences of actions can be useful in evaluating
alternatives. You may just loop through a list of plans, for
example:</p>
<pre class="programlisting">
  maxvalue = 0;
  best_plan_no = BADPLAN;
  for(plan_no=0; plan_no&lt;number_of_plans; ++plan_no){
    if(!is_executable(Plan[plan_no]))continue;
    effective_ness_of_result = 
         guess_consequences(Plan[plan_no]);
    if (effective_ness_of_result &gt; maxvalue){
      maxvalue = effective_ness_of_result;
      best_plan_no = plan_no;
    }
  }
</pre></div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e73" id="d0e73"></a>Value
Judgement</h2>
</div>
<p>Value Judgement estimates the costs, risks and benefits of
taking certain actions. To do this we convert the detailed game
information into a few magic numbers, with each one inferring
something critical about the game.</p>
<p>We can then use these inference numbers and the agents current
action to decide:</p>
<div class="orderedlist">
<ol type="a">
<li>
<p>a unique &quot;situation&quot; each agent is in.</p>
</li>
<li>
<p>numbers indicating how well this agent is performing at this
point in the game.</p>
</li>
</ol>
</div>
<p>From this limited information we estimate the performance of
each player and perhaps each <tt class="classname">Agent</tt>. Ad
hoc formulae (aka fitness functions) are often used for this, for
example:</p>
<pre class="programlisting">
how_well_player_is_doing =     c1 * number_of_areas_occupied + 
    c2 * number_of_animals_have;
if (number_of_areas_occupied &gt; 30) {
    how_well_player_is_doing += 
  pow(number_of_areas_occupied-30, 2)*c3;
}
</pre>
<p>Such formulae need testing by hand to minimise bad
decisions.</p>
<p>I hope this is of some interest.</p>
<div class="bibliography">
<div class="titlepage">
<h2><a name="d0e98" id="d0e98"></a>References</h2>
</div>
<div class="bibliomixed"><a name="Albus" id="Albus"></a>
<p class="bibliomixed">[Albus] <span class="citetitle"><i class=
"citetitle">The Engineering of Mind</i></span>, J S Albus, in
Proceedings of the 4th International conference on Simulation of
Adaptive Behaviour, MIT press</p>
</div>
</div>
</div>
</p>
<p><strong>Notes:</strong>&nbsp;</p>
<p><em>More fields may be available via dynamicdata ..</em></p>
</div>
</channel>
</rss>
