Journal Articles

CVu Journal Vol 13, #1 - Feb 2001 + Programming Topics
Browse in : All > Journals > CVu > 131 (16)
All > Topics > Programming (877)
Any of these categories - All of these categories

Note: when you create a new publication type, the articles module will automatically use the templates user-display-[publicationtype].xt and user-summary-[publicationtype].xt. 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/yourtheme/modules/articles . The templates will get the extension .xt there.

Title: Swamp Fever

Author: Administrator

Date: 03 February 2001 13:15:43 +00:00 or Sat, 03 February 2001 13:15:43 +00:00

Summary: 

Body: 

Swamp Fever

Barry Aulton


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.

There is here a class Agent that is a base class for associating game objects with specific AI Agents for a particular game. Class SwampAgent is derived from the base class Agent and adds the specific techniques used for the Swamp game.

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();
};

But how can we model intelligent behaviour conceptually?

Figure 1 (adopted from [Albus]) 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.

Expert System

The knowledge database mainly consists of sets of game dependent if then type rules and information (which I will call Messages).

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.

For example, in Monopoly my motivation to consider buying Mayfair may be a function of money, which is an integer value.

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.

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 & 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);
    ...
};

Behaviour Generation and Planning

Behaviour generation is the planning and control of the agents to achieve behavioural goals such as winning the game.

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:

  maxvalue = 0;
  best_plan_no = BADPLAN;
  for(plan_no=0; plan_no<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 > maxvalue){
      maxvalue = effective_ness_of_result;
      best_plan_no = plan_no;
    }
  }

Value Judgement

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.

We can then use these inference numbers and the agents current action to decide:

  1. a unique "situation" each agent is in.

  2. numbers indicating how well this agent is performing at this point in the game.

From this limited information we estimate the performance of each player and perhaps each Agent. Ad hoc formulae (aka fitness functions) are often used for this, for example:

how_well_player_is_doing =     c1 * number_of_areas_occupied + 
    c2 * number_of_animals_have;
if (number_of_areas_occupied > 30) {
    how_well_player_is_doing += 
  pow(number_of_areas_occupied-30, 2)*c3;
}

Such formulae need testing by hand to minimise bad decisions.

I hope this is of some interest.

References

[Albus] The Engineering of Mind, J S Albus, in Proceedings of the 4th International conference on Simulation of Adaptive Behaviour, MIT press

Notes: 

More fields may be available via dynamicdata ..