root/test/manual/etags/cp-src/clheir.hpp

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. compute_next_state
  2. step
  3. z
  4. assign_neighbor

     1 /* ======================================================================= */
     2 /*                                 CLHEIR.H                                */
     3 /* ======================================================================= */
     4 
     5 // CLASS HIERARCHY
     6 // Locations or Agents are both of type generic_object. Generic_objects may
     7 // have states, and are responsible for updating their states appropriately
     8 // when their step() functions are executed.
     9 
    10 extern void init_registry(void);
    11 extern void step_everybody(void);
    12 
    13 class generic_object
    14     {
    15     int where_in_registry;
    16 public:
    17     generic_object();  // enter generic_object into ObjectRegistry
    18     // We never copy generic_objects, so we don't need a copy constructor.
    19     ~generic_object(void);  // delete from ObjectRegistry
    20     // Simulation steps, accommodate different kinds of time
    21     virtual void compute_next_state(void) { }
    22     virtual void step(void) { }
    23     };
    24 
    25 // =======================================================================
    26 
    27 // Locations can be regular (like a field of squares or hexagons) or
    28 // irregular. Regular locations have 2-D or 3-D positions represented
    29 // by integers. Locations are never copied; no need for copy constructors.
    30 
    31 const int max_num_directions = 6; // handles both cubes and hexagons
    32 
    33 class location: public generic_object
    34     {
    35     // Any kind of location needs a physical position, but for a regular
    36     // location, this may be implicit, and for an irregular location, it
    37     // should be custom-defined.
    38 
    39     // Any kind of location needs a private list of neighbors, but for a
    40     // regular location, this may be implicit.
    41 
    42 public:
    43     location() { }
    44     ~location();
    45     };
    46 
    47 class irregular_location: public location
    48     {
    49     double x, y, z;
    50 public:
    51     irregular_location(double xi, double yi, double zi)
    52         { x = xi; y = yi; z = zi; }
    53     ~irregular_location();
    54     };
    55 
    56 class discrete_location: public location
    57     {
    58     int x, y, z;
    59     class location *neighbors[max_num_directions];
    60     void clear_neighbors(void);
    61 public:
    62     discrete_location(int xi, int yi, int zi):
    63         x(xi), y(yi), z(zi)
    64             { clear_neighbors(); }
    65     ~discrete_location(void);
    66     void assign_neighbor(int direction, location *x)
    67         { neighbors[direction] = x; }
    68     };
    69 
    70 // =======================================================================
    71 
    72 // Agents are generic_objects with locations, who can move. Examples in
    73 // Pacman would be the protagonist, the monsters, and the monsters' ghosts.
    74 
    75 class agent: public generic_object
    76     {
    77     location *where;
    78 public:
    79     agent();
    80     ~agent();
    81     void move(int);
    82     };

/* [<][>][^][v][top][bottom][index][help] */