home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1887 / lifesrc.h < prev    next >
C/C++ Source or Header  |  1990-12-28  |  6KB  |  190 lines

  1. /*
  2.  * Life search program include file.
  3.  * Author: David I. Bell.
  4.  */
  5.  
  6. #include <stdio.h>
  7.  
  8.  
  9. /*
  10.  * Maximum dimensions of the search
  11.  */
  12. #define    ROWMAX        21    /* maximum rows for search rectangle */
  13. #define    COLMAX        79    /* maximum columns for search rectangle */
  14. #define    GENMAX        6    /* maximum number of generations */
  15. #define    TRANSMAX    3    /* largest translation value allowed */
  16.  
  17.  
  18. /*
  19.  * Build options
  20.  */
  21. #ifndef DEBUGFLAG
  22. #define    DEBUGFLAG    0    /* nonzero for debugging features */
  23. #endif
  24.  
  25.  
  26. /*
  27.  * Other definitions
  28.  */
  29. #define    ALLOCSIZE    100        /* chunk size for cell allocation */
  30. #define    VIEWMULT    1000        /* viewing frequency multiplier */
  31. #define    DUMPMULT    1000        /* dumping frequency multiplier */
  32. #define    DUMPFILE    "lifesrc.dmp"    /* default dump file name */
  33. #define    DUMPVERSION    1        /* version of dump file */
  34. #define    LINESIZE    132        /* size of input lines */
  35.  
  36. #define    MAXCELLS    ((COLMAX + 2) * (ROWMAX + 2) * GENMAX)
  37. #define    AUXCELLS    (TRANSMAX * (COLMAX + ROWMAX + 4) * 2)
  38.  
  39.  
  40. /*
  41.  * Debugging macros
  42.  */
  43. #if DEBUGFLAG
  44. #define    DPRINTF0(fmt)            if (debug) printf(fmt)
  45. #define    DPRINTF1(fmt,a1)        if (debug) printf(fmt,a1)
  46. #define    DPRINTF2(fmt,a1,a2)        if (debug) printf(fmt,a1,a2)
  47. #define    DPRINTF3(fmt,a1,a2,a3)        if (debug) printf(fmt,a1,a2,a3)
  48. #define    DPRINTF4(fmt,a1,a2,a3,a4)    if (debug) printf(fmt,a1,a2,a3,a4)
  49. #define    DPRINTF5(fmt,a1,a2,a3,a4,a5)    if (debug) printf(fmt,a1,a2,a3,a4,a5)
  50. #else
  51. #define    DPRINTF0(fmt)
  52. #define    DPRINTF1(fmt,a1)
  53. #define    DPRINTF2(fmt,a1,a2)
  54. #define    DPRINTF3(fmt,a1,a2,a3)
  55. #define    DPRINTF4(fmt,a1,a2,a3,a4)
  56. #define    DPRINTF5(fmt,a1,a2,a3,a4,a5)
  57. #endif
  58.  
  59.  
  60. #define    isdigit(ch)    (((ch) >= '0') && ((ch) <= '9'))
  61. #define    isblank(ch)    (((ch) == ' ') || ((ch) == '\t'))
  62.  
  63.  
  64. typedef    unsigned char    BOOL;
  65. typedef    unsigned char    STATE;
  66. typedef    unsigned int    STATUS;
  67.  
  68.  
  69. #define    FALSE        ((BOOL) 0)
  70. #define    TRUE        ((BOOL) 1)
  71.  
  72.  
  73. /*
  74.  * Status returned by routines
  75.  */
  76. #define    OK        ((STATUS) 0)
  77. #define    ERROR        ((STATUS) 1)
  78. #define    CONSISTENT    ((STATUS) 2)
  79. #define    NOTEXIST    ((STATUS) 3)
  80. #define    FOUND        ((STATUS) 4)
  81.  
  82.  
  83. /*
  84.  * States of a cell
  85.  */
  86. #define    OFF    ((STATE) 0x00)        /* cell is known off */
  87. #define    ON    ((STATE) 0x01)        /* cell is known on */
  88. #define    UNK    ((STATE) 0x10)        /* cell is unknown */
  89. #define    NSTATES    3            /* number of states */
  90.  
  91.  
  92. typedef    struct cell CELL;
  93. struct cell {
  94.     STATE    state;        /* current state */
  95.     BOOL    free;        /* TRUE if this cell still has free choice */
  96.     char    gen;        /* generation number of this cell */
  97.     short    row;        /* row of this cell */
  98.     short    col;        /* column of this cell */
  99.     CELL    *search;    /* cell next to be searched for setting */
  100.     CELL    *past;        /* cell in the past at this location */
  101.     CELL    *future;    /* cell in the future at this location */
  102.     CELL    *cul;        /* cell to up and left */
  103.     CELL    *cu;        /* cell to up */
  104.     CELL    *cur;        /* cell to up and right */
  105.     CELL    *cl;        /* cell to left */
  106.     CELL    *cr;        /* cell to right */
  107.     CELL    *cdl;        /* cell to down and left */
  108.     CELL    *cd;        /* cell to down */
  109.     CELL    *cdr;        /* cell to down and right */
  110.     CELL    *csym;        /* cell in symmetric position */
  111. };
  112.  
  113. #define    NULL_CELL    ((CELL *) 0)
  114.  
  115.  
  116. /*
  117.  * Data about the cells.
  118.  */
  119. extern CELL    *celltable[MAXCELLS];    /* table of usual cells */
  120. extern CELL    *auxtable[AUXCELLS];    /* table of auxillary cells */
  121. extern CELL    *settable[MAXCELLS];    /* table of cells whose value is set */
  122. extern CELL    **newset;    /* where to add new cells into setting table */
  123. extern CELL    **nextset;    /* next cell in setting table to examine */
  124. extern CELL    **baseset;    /* base of changeable part of setting table */
  125. extern CELL    *searchlist;    /* current list of cells to search */
  126. extern CELL    *fullsearchlist;    /* complete list of cells to search */
  127. extern CELL    *newcells;    /* cells ready for allocation */
  128. extern CELL    *deadcell;    /* boundary cell value */
  129. extern int    newcellcount;    /* number of cells ready for allocation */
  130. extern int    auxcellcount;    /* number of cells in auxillary table */
  131.  
  132.  
  133. /*
  134.  * Current parameter values for the program.
  135.  */
  136. extern BOOL    debug;        /* enable debugging output (if compiled so) */
  137. extern BOOL    nowait;        /* don't wait for commands after loading */
  138. extern BOOL    setall;        /* set all cells from initial file */
  139. extern BOOL    rowsym;        /* enable row symmetry */
  140. extern BOOL    colsym;        /* enable column symmetry */
  141. extern BOOL    parent;        /* only look for parents */
  142. extern BOOL    allobjects;    /* look for all objects including subperiods */
  143. extern STATUS    curstatus;    /* current status for display */
  144. extern int    curgen;        /* current generation for display */
  145. extern int    rowmax;        /* maximum number of rows */
  146. extern int    colmax;        /* maximum number of columns */
  147. extern int    genmax;        /* maximum number of generations */
  148. extern int    rowtrans;    /* translation of rows */
  149. extern int    coltrans;    /* translation of columns */
  150. extern int    maxcount;    /* maximum number of cells in generation 0 */
  151. extern int    cellcount;    /* number of live cells in generation 0 */
  152. extern long    dumpfreq;    /* how often to perform dumps */
  153. extern long    dumpcount;    /* counter for dumps */
  154. extern long    viewfreq;    /* how often to view results */
  155. extern long    viewcount;    /* counter for viewing */
  156. extern long    foundcount;    /* number of objects found */
  157. extern char    *dumpfile;    /* dump file name */
  158. extern char    *initfile;    /* file containing initial cells */
  159. extern char    *loadfile;    /* file to load state from */
  160. extern char    *outputfile;    /* file to output results to */
  161.  
  162.  
  163. /*
  164.  * Global procedures
  165.  */
  166. extern void    getcommands();
  167. extern void    initcells();
  168. extern void    printgen();
  169. extern void    dumpstate();
  170. extern STATUS    search();
  171. extern STATUS    proceed();
  172. extern CELL    *findcell();
  173. extern BOOL    subperiods();
  174.  
  175. extern int    ttyopen();
  176. extern int    ttycheck();
  177. extern int    ttyread();
  178. extern void    ttyprintf();
  179. extern void    ttystatus();
  180. extern void    ttywrite();
  181. extern void    ttyhome();
  182. extern void    ttyeeop();
  183. extern void    ttyflush();
  184. extern void    ttyclose();
  185.  
  186. extern char    *malloc();
  187. extern long    atol();
  188.  
  189. /* END CODE */
  190.