#ifndef _CA_MODEL_H_
#define _CA_MODEL_H_

#ifndef _SCRIPTOBJECTS_H_
#include "console/scriptObjects.h"
#endif

#define BLOCK_GRID_XSIZE 16
#define BLOCK_GRID_YSIZE 24

#define ON   1
#define OFF -1

class CaModel : public ScriptObject
{
   typedef ScriptObject Parent;

public:
   CaModel();
   bool onAdd();
   void onRemove();

   DECLARE_CONOBJECT(CaModel);

   int size_x;
   int size_y;
   int value[BLOCK_GRID_XSIZE][BLOCK_GRID_YSIZE];
   int v[BLOCK_GRID_XSIZE][BLOCK_GRID_YSIZE];
   int get_value( int x, int y );
   void set_value( int i, int j, int N );
   void apply_rule();

protected:
    int state;
    int N, S, E, W, NE, NW, SW, SE;
    void VonNeumann_neighbourhood( int i, int j );
    void Moore_neighbourhood( int i, int j );
    virtual int rule( int i, int j );
};

#endif
