home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / OPENSTEP / Games / NeXTGo-3.0-MIS / opening.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-07-06  |  1.5 KB  |  70 lines

  1. #include "comment.header"
  2.  
  3. /* $Id: opening.c,v 1.3 1997/07/06 19:35:03 ergo Exp $ */
  4.  
  5. /*
  6.  * $Log: opening.c,v $
  7.  * Revision 1.3  1997/07/06 19:35:03  ergo
  8.  * actual version
  9.  *
  10.  * Revision 1.2  1997/05/04 18:57:09  ergo
  11.  * added time control for moves
  12.  *
  13.  */
  14.  
  15. extern int rd, MAXX, MAXY;
  16. extern void Random(int*);
  17.  
  18. int opening(int *i, int *j, int *cnd, int type)
  19.      /* get move for opening from game tree */
  20. {
  21.   struct tnode {
  22.     int i, j, ndct, next[8];
  23.   };
  24.   
  25.   static struct tnode tree[] = {
  26.     {-1, -1, 8, { 1, 2, 3, 4, 5, 6, 7, 20}},    /* 0 */
  27.     {2, 3, 2, { 8, 9}},
  28.     {2, 4, 1, {10}},
  29.     {3, 2, 2, {11, 12}},
  30.     {3, 3, 6, {14, 15, 16, 17, 18, 19}},
  31.     {3, 4, 1, {10}},  /* 5 */
  32.     {4, 2, 1, {13}},
  33.     {4, 3, 1, {13}},
  34.     {4, 2, 0},
  35.     {4, 3, 0},
  36.     {3, 2, 0},  /* 10 */
  37.     {2, 4, 0},
  38.     {3, 4, 0},
  39.     {2, 3, 0},
  40.     {2, 5, 1, {10}},
  41.     {2, 6, 1, {10}},  /* 15 */
  42.     {3, 5, 1, {10}},
  43.     {5, 2, 1, {13}},
  44.     {5, 3, 1, {13}},
  45.     {6, 2, 1, {13}},
  46.     {2, 2, 0}  /* 20 */
  47.   };
  48.   int m;
  49.   
  50.   /* get i, j */
  51.   if ((type == 1) || (type == 3))
  52.     *i = (18 - tree[*cnd].i)*MAXX/19;   /* inverted */
  53.   else
  54.     *i = tree[*cnd].i*MAXX/19;
  55.   if ((type == 2) || (type == 3))
  56.     *j = (18 - tree[*cnd].j)*MAXY/19;   /* reflected */
  57.   else
  58.     *j = tree[*cnd].j*MAXY/19;
  59.   if (tree[*cnd].ndct)  /* more move */
  60.     {
  61.       Random(&rd);
  62.       m = rd % tree[*cnd].ndct;  /* select move */
  63.       *cnd = tree[*cnd].next[m];    /* new    current node */
  64.       return 1;
  65.     }
  66.   else
  67.     return 0;
  68. }  /* end opening */
  69.  
  70.